I would like to trigger a light using both HA and binary sensor (PIR). The objective is to allow PIR sensor to turn on and off the light automatically, but allow HA to override the sensor trigger. E.g. If I turn on the light from HA, binary sensor will be disabled until I turn the light off from HA.
I came up something like this:
globals: - id: right_side_triggered type: bool initial_value: 'false' binary_sensor: - platform: gpio pin: 12 name: "Right Side PIR Sensor" device_class: motion id: right_side_pir on_press: then: - if: condition: and: - light.is_off: my_light - lambda: |- return !id(right_side_triggered); then: - globals.set: id: right_side_triggered value: 'true' - light.turn_on: my_light - while: condition: binary_sensor.is_on: right_side_pir then: - delay: 5s - light.turn_off: my_light - globals.set: id: right_side_triggered value: 'false'
The challenge I’m facing right now is I won’t be able to tell who turned on the light when the light is already on. For example, PIR sensor triggered and light turned on. Then I go to the HA and turn on the light and the light will be turn off by the sensor.
Is there a way to set a flag/var when light is turned on by HA? Thanks.