New to hass (1 week) got all devices connected, reporting etc. Templates and interface. Time to automate. I want to switch on lights (fibaro zwave) based on motion (evl3 and DSC) which should be fairly easy. Issue is switching light off (at switch) and pir not putting it back on. I think i need 1 automation/script to create some sort of global boolean variable that is set to false when light state changes to off, then a 5sec or so timer that changes it back to true. The pir script/automation then needs to check state of that variable when triggered and if it is false then switch on otherwise do nothing. If this is answered elsewhere then sorry and a link would be lovely. Just want 5 seconds to leave room after switching light off without pir overriding human. Any tips about how this is best done would be appreciated.
There’s probably many ways to solve your problem, perhaps including using a condition:
clause in your automation that can check to see if some entity has been in some state for a period of time. This might get around your need for a separate timer and state variable.
See https://www.home-assistant.io/docs/scripts/conditions/#state-condition, I’m sure there’s a bunch of examples around that use the for:
specification on a state trigger or condition.
Simplest is to add a Condition to your motion detection Automation, where state of the light has to be “off” for 5 seconds before triggering on motion is allowed. This may however leave a 5 second gap also between fully automatic switch-off and switch-on.
For a separate state variable, look at the Configuration -> Helpers variables. I suggest creating an input_select (Dropdown) helper, and create a list of appropriate states that you can update by various actions. E.g. at least one “on” state, and two “off” such as “manual_off” and “auto_off”. Set the motion detection Automation to have a Condition with state of this input_select being “manual_off”, “for” 5 seconds.
Another alternative is to create a separate Automation that triggers on the light switching off (preferably you have some way to make this trigger on manual wall-switch action only). Have this automation temporarily disable the motion-activated automation via the “call service” action “automation.turn_off”. You can then add a delay, followed by a call to automation.turn_on. Risk here is that if your HA were to restart while the motion sensor automation is off, it may stay off after restart. There are ways to make sure it’s (re-)enabled after start-up if necessary. Instead of the delay+turn_on action, you can even create a third Automation that only triggers on the motion sensor Automation being disabled, and could re-activate it if it has been off for 5 seconds. This would add robustness to make sure the motion sensor Automation stays enabled.
Thanks for the advice guys. I came across node red and sorted this with a bit of tinkering. @logan893 I put most of your suggestions together using node-red nodes along with functions using a flow-wide variable.