I want to control a light with a pir sensor.
If motion is detected, turn on light (with several conditions)
If pir sensor goes off (no motion during 1:30), turn off light - but only, if turned on by automation.
this is my code for first automation:
alias: Licht Gallerie bei Bewegung
description: Licht in Gallerie einschalten wenn Cover Strasse geschlossen ist
trigger:
- platform: state
entity_id: binary_sensor.deconz_pir_gallerie_rechts
to: 'on'
condition:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.deconz_pir_gallerie_rechts_lux
below: '10'
- condition: state
entity_id: switch.shelly_1pm_entree_gallerie
state: 'off'
- condition: time
before: '23:00'
after: 06:00
- condition: state
entity_id: cover.entree
state: closed
action:
- service: switch.turn_on
data: {}
entity_id: switch.shelly_1pm_entree_gallerie
mode: single
this is my actual second automation to turn off the light, which always turn off the light
alias: Licht Gallerie ausschalten
description: ''
trigger:
- platform: state
entity_id: binary_sensor.deconz_pir_gallerie_rechts
to: 'off'
condition: []
action:
- service: switch.turn_off
data: {}
entity_id: switch.shelly_1pm_entree_gallerie
mode: single
what is the best way to get the goal?
I tought, I use a helper who is put to on by first automation and use this as condition in second automation (and put it back to off).
Is there a better solution?