# An action once a day, every day…

**URL:** <https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254>\
**Category:** General\
**Created:** [27 January 2023 13:15 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254 "2023-01-27T13:15:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 13:15 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/1 "2023-01-27T13:15:07Z")

</div>

Hi  
Newbie with Node Red, I would like to open a roller shutter every morning from 8:00 a.m. when the light is above 200 lux.  
What nodes should be used so that this action only occurs once a day?  
Thanks for your advices,

---

<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:** [27 January 2023 13:16 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/2 "2023-01-27T13:16:37Z")

</div>

You can use the core inject node.

If you need more configuration than that, try the contributed CRON+ node.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [27 January 2023 13:19 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/3 "2023-01-27T13:19:34Z")

</div>

> [@patrickp78](#):
>
> when the light is above 200 lux

How are you measuring lux, and how do you get the lux value into the node-RED flow.  
Does it send the lux value every 'x' minutes, or do you have to request the value?

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 13:22 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/4 "2023-01-27T13:22:28Z")

</div>

I have a sensor.luminosite\_toiture for lux which send value every ± 6 minutes.

---

<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:** [27 January 2023 13:27 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/5 "2023-01-27T13:27:45Z")

</div>

I shouldn't have skipped the 2nd part of your question!

One way to do this is to send the inject 8am prompt to a gate node. You will want to send another inject at some later point in the day to close the gate. Then you would pass your lux measurement through the gate as well. It will only get through if the gate is open.

Presumably, you will also want to track when the lux value falls too low.

In any case, you will probably want to track whether the blinds are open or closed. which you can do by setting a context variable.

BTW, if you don't like contributed nodes (e.g. simple gate), you can do the same thing by storing a context variable that tells your flows whether it is after 8am or not. Then each time you get a lux value, you can test to see if you need to process it.

Oh, and if you are opening/closing based on Lux, you should also take care to leave a gap between the close lux and the open lux otherwise you will eventually hit a situation at the cutover where the blinds are rapidly opening and closing due to small fluctuations in the light level.

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 14:08 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/6 "2023-01-27T14:08:22Z")

</div>

Thanks, but I only want the roller shutter to open:

- if time ≥ 08:00
- if lux ≥ 300 lux  
If lux ≥ 300 at 09:20, the shutter should open at 09:20.  
And that only once a day.

If I put a node inject, the shutter will not open at 08:00 if lux ≤ 300

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 14:23 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/7 "2023-01-27T14:23:40Z")

</div>

This should work.

Record the lux value into a flow/global variable.  
At 09:20 read the variable.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/720c7be1c14f3c2845ef63635fe8a6f55c9e2e47.png)

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 14:35 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/8 "2023-01-27T14:35:05Z")

</div>

Thanks, but…

May be it's difficult for me to explain you what I want.  
I said 09:20 for example, but the sun does not light the house at 300 lux every day at 09:20…

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 14:58 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/9 "2023-01-27T14:58:35Z")

</div>

> but the sun does not light the house at 300 lux every day at 09:20…

Yes understood, which means you need to keep track of it.

You can do this by using a change node - setting a [context variable](https://nodered.org/docs/user-guide/context).

Where does the `sensor.luminosite_toiture` come from ? Is it home assistant ?

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 15:03 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/10 "2023-01-27T15:03:58Z")

</div>

> [@bakman2](#):
>
> Where does the `sensor.luminosite_toiture` come from ? Is it home assistant ?

Yes, it's a sensor on the home roof

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 15:12 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/11 "2023-01-27T15:12:47Z")

</div>

Try importing this flow:

```auto
[{"id":"c976c33f4cc95606","type":"group","z":"4e2fa50c1ec07f23","name":"lux sensor light value","style":{"label":true},"nodes":["febdd4615d21e4c1","52aee46d107eecb6","c5b42f064b7a5c83","293c094dab5da71b"],"x":94,"y":639,"w":432,"h":162},{"id":"febdd4615d21e4c1","type":"inject","z":"4e2fa50c1ec07f23","g":"c976c33f4cc95606","name":"lux sensor = 400","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"400","payloadType":"num","x":220,"y":680,"wires":[["293c094dab5da71b"]]},{"id":"52aee46d107eecb6","type":"inject","z":"4e2fa50c1ec07f23","g":"c976c33f4cc95606","name":"lux sensor = 300","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"300","payloadType":"num","x":220,"y":720,"wires":[["293c094dab5da71b"]]},{"id":"c5b42f064b7a5c83","type":"inject","z":"4e2fa50c1ec07f23","g":"c976c33f4cc95606","name":"lux sensor = 200","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"num","x":220,"y":760,"wires":[["293c094dab5da71b"]]},{"id":"293c094dab5da71b","type":"change","z":"4e2fa50c1ec07f23","g":"c976c33f4cc95606","name":"","rules":[{"t":"set","p":"lux","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":720,"wires":[[]]},{"id":"4ed09fa5bc401301","type":"group","z":"4e2fa50c1ec07f23","name":"Above or below 300 ?","style":{"label":true},"nodes":["3998cfef19570052","f04f633d47d26ee4","2ec3836cb22dfe96","e72f6e04e3354a92"],"x":94,"y":839,"w":532,"h":142},{"id":"3998cfef19570052","type":"switch","z":"4e2fa50c1ec07f23","g":"4ed09fa5bc401301","name":"","property":"lux","propertyType":"flow","rules":[{"t":"gt","v":"300","vt":"num"},{"t":"lte","v":"300","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":900,"wires":[["f04f633d47d26ee4"],["e72f6e04e3354a92"]]},{"id":"f04f633d47d26ee4","type":"debug","z":"4e2fa50c1ec07f23","g":"4ed09fa5bc401301","name":">300","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":880,"wires":[]},{"id":"2ec3836cb22dfe96","type":"inject","z":"4e2fa50c1ec07f23","g":"4ed09fa5bc401301","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"lux","payloadType":"flow","x":190,"y":900,"wires":[["3998cfef19570052"]]},{"id":"e72f6e04e3354a92","type":"debug","z":"4e2fa50c1ec07f23","g":"4ed09fa5bc401301","name":"<300","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":940,"wires":[]}]

```

Press 1 of the 3 inject nodes in the lux sensor group (this would be your home assistant node)

Then press inject node in the other group and watch to which output the message goes.

This is how you can read the lux value, because it was stored in the `flow.lux` variable, which can be read at any time (as long as it has been set).

In your case you can schedule it at 09:20, read the variable and only let it pass if it is \>300.

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 15:32 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/12 "2023-01-27T15:32:47Z")

</div>

Thank you for this flow but I did not know Node Red 10 days ago.  
Therefore, I do not know enough nodes to understand their configuration and operation.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [27 January 2023 16:56 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/13 "2023-01-27T16:56:54Z")

</div>

Just as an aside...  
I use the node called BigTimer to turn the external lights on my home ON at dusk and off at 22:00hrs.  
This flow also sends a message to my phone informing me lights turned On or Off.

 ![on_off](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5fcd5a737666ffbbbaa9f9dd043f538a9d130e54.png)

If you enter your Lat/Lng BigTimer can work out when 'dusk' is (as it changes each day).  
If think cronplus+ also offers this facility.

 ![dusk](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e04fc1e3cfeb5a603ac969e0d0f49371e466f5a0.png)

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 17:07 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/14 "2023-01-27T17:07:10Z")

</div>

Thanks for the help but in my problem the brightness of 300 lux can come on at any time in the morning (obviously after dawn), then go up, then go back down below 300 lux.  
This is why the trigger should only be done once in the morning.  
Thank you for your help…

---

<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:** [27 January 2023 17:17 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/15 "2023-01-27T17:17:03Z")

</div>

> [@patrickp78](#):
>
> Thanks for the help but in my problem the brightness of 300 lux can come on at any time in the morning (obviously after dawn), then go up, then go back down below 300 lux.

Is this correct?

1. The blinds stay closed until 08:00
2. After 08:00, they open when the light level is more than 300 lux

What happens if the light level goes back below 300 lux?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 January 2023 17:17 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/16 "2023-01-27T17:17:28Z")

</div>

> [@patrickp78](#):
>
> Therefore, I do not know enough nodes to understand their configuration and operation.

I would highly recommend to go through all the short videos on [this node-red playlist](https://www.youtube.com/watch?v=ksGeUD26Mw0&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6) on youtube (made by the developers of node-red). It will take you ±30 minutes and you will understand a whole lot more about node-red and how it works.

Because the flow suggestion I made are basic node-red flows which you may need to use more often in the future.

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 17:31 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/17 "2023-01-27T17:31:19Z")

</div>

> [@jbudd](#):
>
> What happens if the light level goes back below 300 lux?

Nothing at all, the blind must remain open because the luminosity will necessarily increase to more than 1000 lux during the day.

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 17:34 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/18 "2023-01-27T17:34:09Z")

</div>

> [@bakman2](#):
>
> I would highly recommend to go through all the short videos on [this node-red playlist](https://www.youtube.com/watch?v=ksGeUD26Mw0&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6) on youtube (made by the developers of node-red)

Many thanks for this link!  
I already saw some tutos but I need to learn more…

---

<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:** [27 January 2023 18:19 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/19 "2023-01-27T18:19:27Z")

</div>

Let's assume that this is correct.

1. The blinds stay closed until 08:00
2. After 08:00, they open when the light level is more than 300 lux

You need to get the light level into Node-red.  
Use a change node to save the latest value as flow.lux.  
The flow that @bakman2 posted includes this change node.

Use this flow to test if the blinds should be opened

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70fb5ef752bab0892c9d858cd25422cacd16a369.jpeg)

```auto
[{"id":"368519f918adf2ea","type":"group","z":"18302aaec057c898","style":{"stroke":"#0722fc","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#0722fc"},"nodes":["951bf3613f46157d","6074ac50043248f7","75fcf7bbeb6742f3","8c4c72f086832acc","cbcd40a2950a275a","af4b227d43d35891","22c6e6e15e59087a"],"x":54,"y":479,"w":912,"h":162},{"id":"951bf3613f46157d","type":"inject","z":"18302aaec057c898","g":"368519f918adf2ea","name":"From 08:00 to 16:00","props":[{"p":"payload"}],"repeat":"","crontab":"*/1 8-15 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"go","payloadType":"str","x":200,"y":560,"wires":[["6074ac50043248f7"]]},{"id":"6074ac50043248f7","type":"switch","z":"18302aaec057c898","g":"368519f918adf2ea","name":"lux > 300 ?","property":"lux","propertyType":"flow","rules":[{"t":"gte","v":"300","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":560,"wires":[["8c4c72f086832acc"]]},{"id":"75fcf7bbeb6742f3","type":"link out","z":"18302aaec057c898","g":"368519f918adf2ea","name":"Your own code to open the blind","mode":"link","links":[],"x":810,"y":560,"wires":[],"l":true},{"id":"8c4c72f086832acc","type":"rbe","z":"18302aaec057c898","g":"368519f918adf2ea","name":"Only once","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":580,"y":560,"wires":[["75fcf7bbeb6742f3","22c6e6e15e59087a"]]},{"id":"cbcd40a2950a275a","type":"inject","z":"18302aaec057c898","g":"368519f918adf2ea","name":"Reset filter at 07:59","props":[{"p":"reset","v":"","vt":"str"}],"repeat":"","crontab":"59 07 * * *","once":false,"onceDelay":0.1,"topic":"","x":380,"y":520,"wires":[["8c4c72f086832acc"]]},{"id":"af4b227d43d35891","type":"inject","z":"18302aaec057c898","g":"368519f918adf2ea","name":"Test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"go","payloadType":"str","x":250,"y":600,"wires":[["6074ac50043248f7"]]},{"id":"22c6e6e15e59087a","type":"debug","z":"18302aaec057c898","g":"368519f918adf2ea","name":"debug 246","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":520,"wires":[]}]

```

Please give it a try and let us know if you experience any problems.

---

<div class="post-metadata">

**Author:** ![patrickp78](https://avatars.discourse-cdn.com/v4/letter/p/ea5d25/32.png) [@patrickp78](https://discourse.nodered.org/u/patrickp78)\
**Post date:** [27 January 2023 18:52 UTC](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254/20 "2023-01-27T18:52:01Z")

</div>

Thanks a lot. I'll try it to morrow evening now. Not before, sorry.  
I'll tell you back if it's ok.  
Have a nice evening (for France only) 🤣  
Patrick

[Next page](https://discourse.nodered.org/t/an-action-once-a-day-every-day/74254.md?page=2)
