- alias: Light on motion
trigger:
- platform: state
entity_id: binary_sensor.pir_motion
to: 'on'
conditions:
# Only do this if the light was off to begin with. If the light was on,
# don't auto turn it off in 60 seconds.
condition: state
entity_id: light.light_id
state: 'off'
action:
- service: light.turn_on
entity_id: light.light_id
- delay: "00:01:00"
- service: light.turn_off
entity_id: light.light_id
So the auto shutoff will only happen if the PIR is what turned it on. If there is a way to turn on the light before PIR trigger, this would be sufficient. It’s a little harder if the motion triggered the light and you want to override. When the light is on, the switch is going to turn it off no matter what you do. You could just quickly turn it off/on to override this. Without a custom switch and custom actions (hold), there’s not much you’ll be able to do.
I also like to make my on/off actions as scripts so that I can cancel the scripts.
Sadly you can’t run the same script multiple times, so I can’t just make a generic light_timer and pass in an entity id. You can only run a script one at a time. Now I just use the script like so.
- alias: Light on motion
trigger:
- platform: state
entity_id: binary_sensor.pir_motion
to: 'on'
conditions:
# Only do this if the light was off to begin with. If the light was on,
# don't auto turn it off in 60 seconds.
condition: state
entity_id: light.light_id
state: 'off'
action:
- service: script.bathroom_light_timer
data:
minutes: "2"
If I want to cancel the auto shutoff part of the automation, I simply have to kill the script.
Thanks for your answer and all your advices.
Actually I was looking to do it with groups to be gateway independent, but it’s not possible with the Fibaro TriSensor PIR (it’s not able to send group alert depending on lux value).
So I’ll follow your advices and do it with automation.
Long time before my first post… wasn’t a priority last months…
But I’ve a working solution:
Automation “A” to light on when a motion is detected and lux is low
Automation “B” to light off when motion is clear
Automation “C” to disable automation “A” and “B” when the wall plug is switched ON
Automation “D” to enable automation “A” and “B” when the wall plug is switched OFF
For “A” and “B” the trigger is on state change on the motion binary sensor.
For “C” and “D” the trigger is on zwave_js notification : the FGS-213 send a notification on S1 button switched.
The only thing is that the FGS send the same notification is the switch is turn on or off. So the tricks is to trigger on the event, and add a condition on the light state. Switched + light ON = switched form off to on > disable automations A and B. And the contrary if light if OFF.