How to use the Time Range Switch

Hi,
I am pretty new to node-red. I am trying to use the time range switc. The documentation says:
Ican send a message like

msg.__config = {
startTime: '12:35',
endTime: 'dusk',
startOffset: 0,
endOffset: 0,
lat: 51.33411,
lon: -0.83716
}

But what exactly do I send in the payload. is it just the json body
{
startTime: '12:35',
endTime: 'dusk',
startOffset: 0,
endOffset: 0,
lat: 51.33411,
lon: -0.83716
}
with JSON selected as the message type
or do I need to send the entire
msg.__config = {
startTime: '12:35',
endTime: 'dusk',
startOffset: 0,
endOffset: 0,
lat: 51.33411,
lon: -0.83716
}
as a string?
Also, if I do not send this message, will the node still automatically work once I have configured its properties or does it require some sort of regular trigger?

Hi Vlad, welcome to the forum.

It is best, when asking about a specific node, to include the actual name of the package. I assume you mean node-red-contrib-time-range-switch?

I've not used that node but it wants the config data in msg.__config? So I would think that whatever is in the payload (and hopefully any other property) will be sent on to the rest of your flow, the node itself doesn't need anything else.


If you send a message to the input with only the __config object included, the node will consume the message and emit no output.
If you send a message to the input with the __config object included and/or a payload/topic, the node will firstly process the __config object, remove it from the message and allow the remainder of the message to be emitted as per the configured rules.

Thank you for your reply. Yes, it is the node-red-contrib-time-range-switch. I am still unclear about how it should be used. What exactly is that node expecting? I json object like
{
startTime: '12:35',
endTime: 'dusk',
startOffset: 0,
endOffset: 0,
lat: 51.33411,
lon: -0.83716
}
or
a strange that references a json object
msg.__config = {
startTime: '12:35',
endTime: 'dusk',
startOffset: 0,
endOffset: 0,
lat: 51.33411,
lon: -0.83716
}

I am unsure what msg.__config is referencing is .__config a shorthand for some property of nodes or messages
image
My inject node has this configuration. Is that correct?

No.

You can use an inject node like this:

[{"id":"913e756e8a5e6e6f","type":"inject","z":"cf3317c32e6245e6","name":"","props":[{"p":"__config","v":"{\"startTime\":\"12:35\",\"endTime\":\"dusk\",\"startOffset\":0,\"endOffset\":0,\"lat\":51.33411,\"lon\":-0.83716}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":680,"y":260,"wires":[["522cc6cbf66cdc5f"]]}]

Or a function node like this:
Untitled 2

[{"id":"827e7e1414bd8351","type":"inject","z":"cf3317c32e6245e6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":240,"wires":[["73b65f1ba078ad2a"]]},{"id":"73b65f1ba078ad2a","type":"function","z":"cf3317c32e6245e6","name":"","func":"msg.__config = {\n    startTime: '12:35',\n    endTime: 'dusk',\n    startOffset: 0,\n    endOffset: 0,\n    lat: 51.33411,\n    lon: -0.83716\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":240,"wires":[["522cc6cbf66cdc5f"]]}]

To use those examples, copy the JSON code and Import it into Node-Red. Hamburger menu | Import.

Once you have set the time range as above, the settings are retained unless you press the deploy button. From the node's help:
It is very important to note that properties set programmatically in this manner are transient. They will not persist over a NodeRED restart or redeploy!

Have a read of the node red docs on working with messages, that should help to clear things up. Working with messages : Node-RED

Also watch this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot in about 1 hour. A small investment for a lot of gain.

Thanks Colin, I did read that a number of times, but it did not make the use of the time-range node any clearer. What confused me was the use of __config, why does the node not but the object directly in the message, like most other nodes. I assumed __config was some sort of shorthand for message body or payload?

Thanks that clears it up. I did not know message could have a .__config property. I assumed __config was shorthand for payload or body and could find no other references to mg.__config. Why not just put the actual object directly in the msg.payload? It is more in keeping with most other nodes.
So I guess I can define any message property then like message.myconfig?

I've always assumed that naming things __summatOrOther was designed to facilitate typing errors.

A message can have many elements - msg.payload, msg.temperature, msg.pressure.
Each element can have it's own structure - msg.payload.temperature, msg.payload.pressure etc.
I find the best way to get a handle on them is via the "Copy path" button in the output from a debug node.

A leading underscore is a common signal that the attribute is supposed to be private. In the case of a node-red msg, it generally (by convention, no strict rules here!) indicates that the property is destined for the node and not for the general flow.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.