Automation state of motion sensor

Hi everybody,
just changed from openhab zu homeassistant and i think that was a good decision. Now it trie to
do all my automations new in HA and need some help with one:

i have stairs with a light and two motion sensors (one on the upper end and one on the lower end). the sensor is a homematic and after 15sec it turns off again (minimum time).

when i step in the motion sensor 1 it turns to “ON” and then turns on the light. after about 5 seconds i walk to the other end of the stairs and the motion sensor 2 turns to “ON”. after another 10 seconds the motion sensor 1 turns to “OFF” but the senor 2 still has 5 seconds to go till it turns to OFF. If i walk back to the stairs within those 5 seconds the automation cant be triggered, because the motion sensor 2 is still ON.
So i would like to turn OFF the motion sensor 2 when sensor 1 turns OFF. I found no way to do this.
another problem is, that even when a found a way to turn OFF the motion sensor, it would trigger any automation related.
Is there a way to change a state without start related automations ?

thanks for any help !!

martin

The following automation:

  • Turns on the light if either motion detector is turned on (detects motion).
  • Turns off the light when both motion detectors are turned off (detects no motion).
alias: example 
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion1
      - binary_sensor.motion2
    from:
      - 'on'
      - 'off'
    to:
      - 'off'
      - 'on'
condition: []
action:
  - variables:
      is_motion: >
        {{ ['binary_sensor.motion1', 'binary_sensor.motion2']
          | map('states') | select('eq', 'on')
          | list | count > 0 }}
  - service: "light.turn_{{ 'on' if is_motion else 'off' }}"
    target:
      entity_id: light.stairs
mode: single

There’s no need to do that. The automation example I posted demonstrates how to handle the two motion detectors.

Thanks a lot for the very fast answer !!!

1 Like

Sorry, i hope you could help me with one more question:
i would like to involve a “numeric state” within the action part, that if
the action is “on” it only starts, when the illumination is below 40.

if i do this “outside” the action it could happen, that it doesnt turn off again.
“inside” i would need the condition for illumination only if “on” is done.

hope you can help me one more time.
thanks

alias: example 
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion1
      - binary_sensor.motion2
    from:
      - 'on'
      - 'off'
    to:
      - 'off'
      - 'on'
condition:
  - condition: template
    value_template: >
      {{ states('sensor.illumination') | int(0) < 40 if trigger.to_state.state == 'on'
         else trigger.to_state.state == 'off' }}
action:
  - variables:
      is_motion: >
        {{ ['binary_sensor.motion1', 'binary_sensor.motion2']
          | map('states') | select('eq', 'on')
          | list | count > 0 }}
  - service: "light.turn_{{ 'on' if is_motion else 'off' }}"
    target:
      entity_id: light.stairs
mode: single

EDIT

Correction. Added missing underscore to value_template

Thank you so much for your help, unfortunatley it doesnt work yet .

The info shows “Message malformed: extra keys not allowed @ data[‘condition’][0][‘value template’]”

alias: Stiegenhaus Keller Licht
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.stgh_kg_oben_bewegungsmelder_motion
      - binary_sensor.stgh_kg_unten_bewegungsmelder_motion
    from:
      - "on"
      - "off"
    to:
      - "off"
      - "on"
condition:
  - condition: template
    value template: >
      {{ states('sensor.stgh_kg_oben_bewegungsmelder_illumination') | int(0) < 40 if trigger.to_state.state == 'on'
      else trigger.to_state.state == 'off' }}
action:
  - variables:
      is_motion: >
        {{ ['binary_sensor.stgh_kg_oben_bewegungsmelder_motion',
        'binary_sensor.stgh_kg_unten_bewegungsmelder_motion']
          | map('states') | select('eq', 'on')
          | list | count > 0 }}
  - service: light.turn_{{ 'on' if is_motion else 'off' }}
    target:
      entity_id: light.stiege_licht_kg
mode: single

Change value template to value_template

I have already corrected it in the example posted above.

Thank you so much !!!
Works fine and I learned so much !