# How to use the Time Range Switch

**URL:** <https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915>\
**Category:** General\
**Created:** [12 September 2021 08:53 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915 "2021-09-12T08:53:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vlad](https://avatars.discourse-cdn.com/v4/letter/v/3bc359/32.png) [@Vlad](https://discourse.nodered.org/u/Vlad)\
**Post date:** [12 September 2021 08:53 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/1 "2021-09-12T08:53:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 September 2021 10:18 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/2 "2021-09-12T10:18:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vlad](https://avatars.discourse-cdn.com/v4/letter/v/3bc359/32.png) [@Vlad](https://discourse.nodered.org/u/Vlad)\
**Post date:** [12 September 2021 11:35 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/3 "2021-09-12T11:35:14Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce26c41facff38e12b49273718c31f92fb963fac.png)  
My inject node has this configuration. Is that correct?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [12 September 2021 12:15 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/4 "2021-09-12T12:15:28Z")

</div>

> [@Vlad](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce26c41facff38e12b49273718c31f92fb963fac.png)  
> My inject node has this configuration. Is that correct?

No.

You can use an inject node like this:

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd640882cb19c3670abec2df3636cc517efd0ee6.jpeg)

```auto
[{"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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/3797aab1781a26eccf5d1db1171836610e3a2bfc.jpeg)

```auto
[{"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!_

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 September 2021 12:28 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/5 "2021-09-12T12:28:09Z")

</div>

Have a read of the node red docs on working with messages, that should help to clear things up. [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)

Also watch this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). 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.

---

<div class="post-metadata">

**Author:** ![Vlad](https://avatars.discourse-cdn.com/v4/letter/v/3bc359/32.png) [@Vlad](https://discourse.nodered.org/u/Vlad)\
**Post date:** [21 September 2021 07:04 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/6 "2021-09-21T07:04:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Vlad](https://avatars.discourse-cdn.com/v4/letter/v/3bc359/32.png) [@Vlad](https://discourse.nodered.org/u/Vlad)\
**Post date:** [21 September 2021 07:09 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/7 "2021-09-21T07:09:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [21 September 2021 14:20 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/8 "2021-09-21T14:20:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 September 2021 20:02 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/9 "2021-09-21T20:02:17Z")

</div>

> [@jbudd](#):
>
> I've always assumed that naming things \_\_summatOrOther was designed to facilitate typing errors.

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 November 2021 20:03 UTC](https://discourse.nodered.org/t/how-to-use-the-time-range-switch/50915/10 "2021-11-20T20:03:03Z")

</div>

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