Hello,
New to Node Red here and am looking for some “best practice” advice. I’ve built a flow to turn on the porch light with motion and then turn off after a 5min delay. The flow also ignores motion if the light is already (switched on manually). Now I’d like to reset the timer if additional motion occurs before the timer expires. I figure there are multiple ways to do this, but what I had in mind was a sort of software switch, or temporary “entity”, who’s state could be switched on when the light is turned on via motion, and then switched off when the light is turned off via the expired timer. Then I could simply run a second path from the motion sensor out through a “current state” node (to check if the light is on via motion or not) before running it out to the timer input to feed resets.
That said, I don’t know what node to use to create this temporary “entity”, or if that is even possible. I’ve heard of creating an “input boolean” in HA, but wasn’t sure if there was a simple node that would do what I’m after.
Thanks!
You don’t need that. Use the state of your motion to reset the timer.
Thanks for the reply @flamingm0e! So the difficulty with that scenario is that I want motion to be ignored if the light is switched on manually. If I were to run the motion sensor straight into the timer, then it would start the timer to turn the light off if motion is detected, regardless of whether the light was originally turned on via motion or not.
So I ended up implementing the input_boolean to accomplish what I was after. It was fairly easy to do, but I still wonder if there isn’t a simple node or two that will accomplish the same thing. I was thinking maybe the counter node or something, but I’m not familiar enough with things yet to figure it out. Anyway, here is where I’m at in the meantime with the input_boolean:
Just create a flow variable
Thanks @flamingm0e! “flow variable” are the words I needed! A google search of that led me to this http://www.steves-internet-guide.com/node-red-variables/ and here is what I ended up with.
the contents of the On by Motion function node looks like this:
var motion_on=flow.get('motion_on') || 'on';
motion_on='on';
msg.payload=motion_on
flow.set('motion_on',motion_on);
return msg;
and the Off by Motion node looks like this:
var motion_on=flow.get('motion_on') || 'off';
motion_on='off';
msg.payload=motion_on
flow.set('motion_on',motion_on);
return msg;
and the switch node looks like this:
property "flow.motion_on"
== on
Still learning here, so perhaps the code could have been cleaner, but it works at least.
Thx!