Hall light automation with Node Red

Just started with Node red. I have been looking around for the best way to control my hall light. What I would like is the light comes on when I open the front door “sensor from dsc alarm” only after dusk. Then turn off the light after 5 minutes. But if the light is turned on manually by the switch I would like it to stay on for longer. Say 10 minutes.

How is the manaul switch being connected to HA

The manual switch is zwave to a controller on Home assistant.

Ok I am one that needs to return to the community as everyone has helped me. I do a lot with function blocks as I like programming but Javascript isnt my native lanuage.
My advice is do it in logical steps.
-Input
-Timers
Output
So have you got your input nodes on a flow. Most likely I would have each button at a value to a variable. Then using an Inject node fire it into a function block that checks that variable If its above 0 then send on as a return message to the light node. If at zero send off. The same node subtracts 1 from the variabl if its above 0.

Just off to work so will be delayed in replying

Right now I have a flow working for when I open door. It keeps the light on for 5 Mins and then turns it off. Just not sure how go about having a different timer for when the light is pressed manually.

Can you not use node red to read the last time the zwave device was triggered / changed state? after that 5 minutes you have, if it was more the 5 minutes past now then continue to off other wise wait another 5 minutes before off.

Tho how to implement it, off hand I wouldn’t know.

Here is something I just hacked up sitting here whilst waiting for a job to finish. Uses 2 times in functions. Does that help you? Adjust to suit but I kind if do a lot like this

[{“id”:“a75f1936.1ab7c8”,“type”:“function”,“z”:“c904959d.fe19d8”,“name”:“read timer”,“func”:“var tm = global.get(‘timer’)||0;\nif (tm > 0)\n{msg.payload = “on”\n global.set(‘timer’,tm - 1);\n}\nelse\nmsg.payload = “off”;\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:327.0000114440918,“y”:250.00001049041748,“wires”:[[“8069ff83.f9919”]]}]

Just tried to copy the code to my clip board and import. Red node wont do it. The import button is not accessible Hmmmmm.

image

I think you might just leave them as two different paths

The first one you have already that works when you open the door and then shuts off after 5 minutes

Make a second that looks for the light state change - Light changed to on --> 10 Min timer --> light.off

The door opening would also trigger this timer but the light would already be off when this timer finished so you could just leave it or have the 5 min timer disable the 10 min timer when it runs. Then when you trigger the light manually it has it’s own 10 minute timer.

another option is if that door is always closed you could have it check that door to be open when the state of the light goes to on and if it is open halt there…if closed move on to the timer.

just a couple quick thoughts…I am new to node red and learning still myself.

So I have made a small flow in the mean time while I’m still learning about the function node. But I have problems with it. What happens is the door state coming from the trigger-state called Front Door Opened is sending false outputs saying it has opened. If i put a debug or notify my iphone on the output I see multiple triggers of it turning “on” and “off” all night. I know this is not possible because my DSC alarm would be triggered and the sirens would be going off.

If i look at the state in Home Assistant it does not change at all unless the door is actually opened.

is this a communication glitch between Home Assistant and Red Node?

I have a node red flow that has a front door state triggering for no reason too. State isn’t changing in HA. Not sure what the issue is.

Normally node-red matches your entities using the substring mode, so if you have a sensor with a name starting out the same way it will match that sensor as well.
try changing the matching parameter to exact instead.
This has fooled me a couple of times before i found out.

Why not have two separate flows, one where the door sensor triggers the light and then the timer for 5 minutes, and another that if switch turns on then set a timer for 10 minutes and then of?
or have i misunderstood anything?

in my case I’ve already set it to “exact” and it is the exact name of the front door sensor. mysteriously triggers in node-red without a state change in HA.

Ya I just tried setting to “exact”. I’m still getting the false triggers too.

One thing that will stop the triggers is setting the halt state to “off” but that also stops me from seeing if the door is closed.

The event state and trigger-state nodes also trigger when any part of an entity is updated. So if you have a sensor that sends updated information to Home Assistant, Home Assistant will send out a new state_changed event with the new info. You can try using a rbe node after the change nodes.

1 Like

Thanks Kermit. I knew there had to be an easy way.

+1, rbe node also worked for me.