Help with Home Assistant Automations: Problem with Input Boolean and Motion Sensor

Hello Community,

I have an issue with my automations in Home Assistant and I just can’t seem to figure it out. I’ve tried many things, but one scenario still doesn’t work as intended. Here’s my current situation:


Setup:

  • A motion sensor (binary_sensor.flur_og_bewegungssensor_gruppe ) that should dim the light to 5% when motion is detected.
  • A Shelly switch (shelly.click ) that should turn the light to 100% when pressed.
  • An input boolean (input_boolean.flur_og_licht_manuell ) that is used to block the motion sensor as soon as the switch is pressed.

Requirements:

  1. When the motion sensor detects motion, the light should be set to 5% and turn off after no motion is detected.
  2. When the switch is pressed, the light should turn to 100%, the motion sensor should be blocked (Input Boolean = on), and the light should only turn off when the switch is pressed again.
  3. The light should also be manually controllable via the switch without activating the motion sensor.
  4. If the switch is activated, the motion sensor should not perform any further actions until the switch turns off the light again (Input Boolean = off).

Current Configuration:

Motion Sensor Automation

alias: "Flur OG: Bewegungsmelder Licht auf 5% - überarbeitet"
description: ""
triggers:
  - entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
    to: "on"
    trigger: state
  - entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
    to: "off"
    trigger: state
conditions:
  - condition: state
    entity_id: input_boolean.flur_og_licht_manuell
    state: "off"
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
            state: "on"
        sequence:
          - target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            data:
              brightness_pct: 5
            action: light.turn_on
      - conditions:
          - condition: state
            entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
            state: "off"
        sequence:
          - delay: "00:00:01"
          - target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            action: light.turn_off
            data: {}
    default: []
mode: restart

Switch Automation

alias: "Flur OG: Schalter Licht auf 100% - überarbeitet"
description: ""
triggers:
  - event_type: shelly.click
    event_data:
      click_type: single_push
      device: shellyprodm1pm-34987aa933b8
    trigger: event
conditions: []
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.flur_og_shelly_dimmer_1_light_0
            state: "on"
          - condition: template
            value_template: >
              {{ state_attr('light.flur_og_shelly_dimmer_1_light_0',
              'brightness') < 80 }}
        sequence:
          - target:
              entity_id: input_boolean.flur_og_licht_manuell
            action: input_boolean.turn_on
            data: {}
          - target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            data:
              brightness_pct: 100
            action: light.turn_on
      - conditions:
          - condition: state
            entity_id: light.flur_og_shelly_dimmer_1_light_0
            state: "on"
          - condition: state
            entity_id: input_boolean.flur_og_licht_manuell
            state: "on"
        sequence:
          - target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            action: light.turn_off
            data: {}
          - target:
              entity_id: input_boolean.flur_og_licht_manuell
            action: input_boolean.turn_off
            data: {}
      - conditions:
          - condition: state
            entity_id: light.flur_og_shelly_dimmer_1_light_0
            state: "off"
        sequence:
          - target:
              entity_id: input_boolean.flur_og_licht_manuell
            action: input_boolean.turn_on
            data: {}
          - target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            data:
              brightness_pct: 100
            action: light.turn_on
mode: single

Helper Reset Automation

alias: "Flur OG: Helfer zurücksetzen - überarbeitet"
description: ""
triggers:
  - entity_id: light.flur_og_shelly_dimmer_1_light_0
    to: "off"
    trigger: state
conditions:
  - condition: state
    entity_id: input_boolean.flur_og_licht_manuell
    state: "on"
actions:
  - target:
      entity_id: input_boolean.flur_og_licht_manuell
    action: input_boolean.turn_off
    data: {}
mode: single

Test Scenarios:

  1. Motion sensor detects motion, light turns on to 5%, turns off after one second when no motion is detected: Works correctly.
  2. Motion sensor detects motion (light to 5%), switch is pressed (light to 100%), motion sensor turns off the light, even though the helper should be active: Does not work correctly.
  3. Switch is pressed without motion sensor being involved, light turns on/off, motion sensor does not interfere: Works correctly.
  4. Switch is pressed, light remains at 100%, motion sensor detects motion, light remains untouched: Works correctly.

Problem:

  • In scenario 2, the input boolean (input_boolean.flur_og_licht_manuell ) remains “off”, even though the switch automation activates it.
  • As a result, the motion sensor automation takes over and turns off the light.

Question:

  • Why does the input boolean remain “off”?
  • How can I adjust the automations so that scenario 2 works correctly?

Thank you very much for your help!

Restart HA, run scenario 2 and look at the automation traces. This will tell you where the light is getting turned off and the state of variables.

It is possible that setting the light to 100% when it is 20% causes the light state to go to off.

Suggested changes, that won’t fix the issue.

  1. Motion Sensor Automation. Add ID to triggers and choose based on trigger id rather than rechecking state.
  2. If you put sensor values in variables then it’s easy the view this values in the automation traces.

This does not resolve yuour issue but also there is a hole in your logic. When the person presses the switch to turn the light off while they are in the room, and then walk out of the room, the motion of walking out of the room will turn the light on again.

I have gotten around this in my scenario by capturing the exact time the light is turned off - MANUALLY ONLY (not by dashboard or an automation), and every time motion is sensed, a condition of turning the light on is it will only turn the light on if it was not manually turned off within the last 5 minutes (I should probably change that to 1 or 2 minutes).

(Tip: for the time comparison logic instead of jumping through hoops to convert the datetime values to floats to make the math work, you can use the timedelta() function supplied by HA.)

I can live with the light being turned on again due to mottion detection. This lasts for only 90 seconds and then it is off again. Motion detection always means off after 90 seconds. This behaviour shouldonly be broken with the switch.

I am trying this approach, but so far unsuccessfull. I am starting to feel there is a problem with helpers being overwritten.

OK I found a solution that works exactly as expected. Including various scenarios where the motion detector detects a motion at any place in the process (at least as far as I could think of).

alias: "Flur OG: Bewegungsmelder Licht auf 5% - ohne Helfer"
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
    to: "on"
  - platform: state
    entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
    to: "off"
condition:
  - condition: template
    value_template: "{{ state_attr('light.flur_og_shelly_dimmer_1_light_0', 'brightness') != 255 }}"
action:
  - service: system_log.write
    data:
      message: "Bewegungsmelder ausgelöst. Helligkeit: {{ state_attr('light.flur_og_shelly_dimmer_1_light_0', 'brightness') }}"
      level: info
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
            state: "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            data:
              brightness_pct: 5
      - conditions:
          - condition: state
            entity_id: binary_sensor.flur_og_bewegungssensor_gruppe
            state: "off"
        sequence:
          - delay: "00:00:01"
          - service: light.turn_off
            target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
mode: restart
alias: "Flur OG: Schalter Licht auf 100% - mit Ausschaltfunktion"
description: ""
trigger:
  - platform: event
    event_type: shelly.click
    event_data:
      click_type: single_push
      device: shellyprodm1pm-34987aa933b8
condition: []
action:
  - service: system_log.write
    data:
      message: >
        Schalter ausgelöst. Lichtzustand: {{ states('light.flur_og_shelly_dimmer_1_light_0') }},
        Helligkeit: {{ state_attr('light.flur_og_shelly_dimmer_1_light_0', 'brightness') }}
      level: info
  - choose:
      # Licht ausschalten, wenn es auf 100% ist
      - conditions:
          - condition: template
            value_template: >
              {{ states('light.flur_og_shelly_dimmer_1_light_0') == 'on' and
                 state_attr('light.flur_og_shelly_dimmer_1_light_0', 'brightness') == 255 }}
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
          - service: system_log.write
            data:
              message: "Licht ausgeschaltet."
              level: info
      # Licht auf 100% einschalten, wenn es aus ist oder gedimmt ist
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: light.flur_og_shelly_dimmer_1_light_0
                state: "off"
              - condition: template
                value_template: >
                  {{ state_attr('light.flur_og_shelly_dimmer_1_light_0', 'brightness') < 255 }}
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.flur_og_shelly_dimmer_1_light_0
            data:
              brightness_pct: 100
          - service: system_log.write
            data:
              message: "Licht auf 100% eingeschaltet."
              level: info
mode: single

I am now aiming directly at the brightnes level and keep the helper entirely out of the loop.

1 Like

Hello Pete, I’m new here. I came to this forum because I saw one of your responses in an online search. I looked for a private message on your member page, but saw none. So I just bought a HA Green, and it refuses connection from first plugin. I’ve been trying to trouble shoot it in my router, windows security settings and firewall. But have run into dead ends each time. I saw your post about pinging homeassistant.local, and so I did. The strange thing, is it gave an IPv6 IP address, not an IPv4. Or maybe it’s because my Desktop computer is connected via ethernet, because my phone on wifi, pinged the IPv4 IP address of 192.168.1.123. So I’m not sure what is going on, or how to fix it, but hoped you’d be able to steer me in the right direction, as I think you’re one of the more knowledgeable persons here. Sorry for blurting into another thread, but wasn’t sure how else to ask you. I’m open to a more proper way if needed. Thanks for any help or advice you might be able to offer.

Best bet is to post your question under a new topic. That way others with knowledge of HA green can help out.

1 Like

Yes, I started thinking about that, and did make another post, right after posting here. I wasn’t sure if you’d see it on a new post. But here’s the link,
" Brand new Green refuses initial connection
Thanks.