Multiple triggering of automation through motion sensor and general light switch

Hello everyone,

I’m facing an issue with my automations in Home Assistant and I’m hoping you can assist me. In my setup, I have two automations: one for manually turning on the lights in the living room and another for automatically turning them on based on a motion sensor. The automation for manual switching on works by setting a pseudo boolean (with no actual light control) every time the light is turned on or off, whether through the Philips Hue App or the Philips Hue switches configured in the Philips Hue app. In the Philips Hue App I set the motion sensor to “Configurate in another app”.

The automation for automatic switch-on based on the motion sensor sets this boolean to false to differentiate between user interaction and motion-triggered interaction. Unfortunately, there are instances when the automation for manual power-on is triggered twice. This occurs sometimes when I enter a dark room, turn on the light, and pause for a moment. As a result, the associated input_boolean gets an incorrect value.

If you require any additional information to help me understand the problem, please let me know, and I will provide the necessary details. Thank you very much in advance!


Here are the YAML configurations for my automations:


Light: Living Room Manual

Please note that every time the light is turned on or off, the boolean is set. In the next automation for the motion sensor, this boolean is turned off to simulate an “automatic” light turn-on.

alias: "Licht: Wohnzimmer manuell"
description: ""
trigger:
  - platform: state
    entity_id:
      - light.wohnzimmer
  - platform: state
    entity_id:
      - input_button.test_button
condition: []
action:
  - if:
      - condition: state
        entity_id: light.wohnzimmer
        state: "on"
    then:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.licht_wohnzimmer_manuell
    else:
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.licht_wohnzimmer_manuell
mode: single
max_exceeded: silent

Light: Living Room Automatic

alias: "Licht: Wohnzimmer automatisch"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.wohnzimmer_motion_motion
    to: "on"
condition:
  - condition: or
    conditions:
      - condition: numeric_state # If is dark trigger the action
        entity_id: sensor.wohnzimmer_motion_illuminance
        below: 65000000 # Such a high integer just for testing
        enabled: true
      - condition: state # I want to trigger the action even when the light is on, later i check on a boolean if the light should turn on or off or if nothing should happen
        state: "on"
        enabled: true
        entity_id: light.wohnzimmer
    enabled: true
action:
  - if:
      - condition: state # If no user interaction with the light
        entity_id: input_boolean.licht_wohnzimmer_manuell
        state: "off"
    then:
      - if:
          - condition: state # If i enter the dark room for the first time
            entity_id: light.wohnzimmer
            state: "off"
        then:
          - service: light.turn_on
            data: {}
            target:
              area_id: wohnzimmer
          - wait_for_trigger: # This is controlled by another automation, see above
              - platform: state
                entity_id:
                  - input_boolean.licht_wohnzimmer_manuell
                from: "off"
                to: "on"
          - service: input_boolean.turn_off # Turn off "user interaction" boolean
            data: {}
            target:
              entity_id: input_boolean.licht_wohnzimmer_manuell
      - wait_for_trigger:
          platform: state
          entity_id: binary_sensor.wohnzimmer_motion_motion
          from: "on"
          to: "off"
        enabled: true
      - delay:
          hours: 0
          minutes: 0
          seconds: 15
          milliseconds: 0
      - condition: state
        entity_id: input_boolean.licht_wohnzimmer_manuell
        state: "off"
      - service: light.turn_off
        data: {}
        target:
          area_id: wohnzimmer
mode: restart
max_exceeded: silent