Repeating sequence

Hi,

I’m struggling to work out how to get a sequence to trigger again after x minutes.

Senario:

When it is dark and I take the dog out before bed, between 21:00 & 23:00, as I open the back door, I want the back door light to come on only.
When I come in after ~5 minutes, I want the light to go out.

If it is dark and I need to go into the garden after 23:00, I want all garden lights to come on.
When I come in after ~5 minutes, I want the lights to go out.

  1. Door opens (and closes)
  2. If the time is between 21:30 & 23:00
  3. Sun is below the horizon (dark)
  4. Turn on the garden light A
  5. Wait for 1 minute
  6. Door opens after 1 minute but less than 30 minutes
  7. Turn off light A.
  8. Time is not between 21:30 & 23:00
  9. It is dark
  10. Door is opened
  11. Turn on all garden lights.
  12. Wait for 1 minute
  13. Door opens after 1 minute but less than 30 minutes
  14. Turn off all garden lights.

This is what I have so far:


(I have a temporary UI button for testing the binary door monitor)

The main difficulty is working out which type of event node I need to detect the door has been opened again. I looked at a pole node, but it appears it only runs every x seconds and if the door isn’t opened at exactly that moment it won’t fire as the binary sensor only changes state as the door makes or breaks contact.

I feel what would help is a state change node that allows input. I could then hook up delay to Door opened, but I guess there’s a reason why some nodes don’t allow input and I need to go down a different path.

Another idea is perhaps some sort of variable that logs the first occurrence of the door opening and then starts a pole at 1-second intervals to detect the second occurrence of the door opening. But, I notice the Pole state node doesn’t accept inputs either, so I don’t know how the Delay can hook into it.

A bit of a waffle, but I guess there’s some logic to Node-Red that I haven’t clocked on to yet, so any pointers would be gratefully received.

T. I. A.

Your logic confuses me. Time between 21:30 and 23:00 is dark, so why test for dark? (Unless you are in the Arctic circle).

So, you open the door and the light comes on.
You open the door again and the light goes off?

What if you want to go outside at 23:01?

What’s wrong with:
if door opens, and it’s dark, turn on the light for 30 minutes.

I am in Denmark and it is definitely not the arctic circle.
Here the sunsets at around 22:00 on June 21. and rise at around 04:30.
Civil twilight is around 23:00 and 3:30 and nautical twilight is just the rest of the night.

1 Like

Hi @stevemann
Thanks for your reply.

I believe the further one gets from the equator the greater the variation in daylight hours. On the equator, it’s approximately 12 hours of daylight and 12 hours of dark throughout the year, whereas, at either pole, there are almost 6 months of daylight/twilight.

In the UK, which is a surprisingly long way North (Scotland is further North than Moscow), on the summer solstice (21st June), the sun is starting to rise at around 03:00 and there is still light in the air at 23:00, although the sun has technically set, whereas on the winter solstice (22nd December), it’s gone 07:00 before there’s much light and it’s dark by 16:00. The winter solstice is 8 hours, 49 minutes shorter than the summer solstice.

Anyway, back to the problem.

I open the door between 21:30 and 23:00 1 light comes on, then, if the door is not opened for 1 minute, when the door is next opened, turn off the light.

If I open the door at 23:01, then all garden lights come on, then, if the door is not opened again for 1 minute, when the door is next opened, turn off all garden lights.

I guess if the door is opened and I don’t go out, I will have to tell Google Assistant to turn off the lights.

Nothing per se, except I want it cleaver than that. I believe it should be achievable with Node-RED and if nothing else, it would be a good example to learn from - if I can work it out. My main issue is that I don’t understand why so many of the nodes don’t accept input such as poll, which means I can’t work out how to link the first door opening action to the second door opening action.

Thanks again.

Remember the nodes are just using the state machine provided by HA with all it limitations too.
You should probably use a function node to save the time for a door opening with the flow.set or global.set command and the retrieve it again at the next door opening with flow.get or global.get to do a compare.

1 Like

I just use a motion sensor. If there’s motion the light comes on for ten minutes. If there’s any motion during that ten minutes, the timer is reset.