Stopped because a condition failed

Hello.
Please help me understand the conditions.
I have 2 motion sensors in the room and I need turn of the light in room when they both go into the “no motion detected” state and stay in that state for 1 minute.
My automation is not working and i don’t understand why.
I used condition AND, but it’s not working.
Please help me.

alias: Тест Light
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.light
    from: "off"
    to: "on"
    enabled: true
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.motion1_occupancy
        state: "off"
        for:
          hours: 0
          minutes: 1
          seconds: 0
      - condition: state
        entity_id: binary_sensor.motion2_occupancy
        state: "off"
        for:
          hours: 0
          minutes: 1
          seconds: 0
action:
  - type: turn_off
    device_id: 7c0616bee889a383b58000cd05df5d1d
    entity_id: 1a46b93e1ef5b9e1df5cb7b50e7a1040
    domain: switch
mode: restart

You are misunderstanding how this works.

When triggered, the conditions are looked at to see if they pass or fail.

I am assuming your light turns on from motion (I may be wrong), this triggers, and one (or both) of the motion sensors are on. That is why it ends.

So in human words this translates as:
When the light turns on (=trigger) AND motion1 as well as motion2 are off for 1 minute (condition) , turn off the light (action).

the idea is to make automation work when the light is turned on manually.
I know that I don’t know anything)
How it must works?
How can I get automation to work with my script?
I need the light to turn off if there is no response on either motion sensor within 1 minute.
But if there is movement on at least one of the sensors during this period of time, then the light does not need to be turned off.

How to fix it?

Yeah I was thinking about it, but the condition that motion1 AND motion2 must be off for a minute makes it tricky to create a trigger for it…

Perhaps there is some other way to check the status of two sensors within a minute?
I tried removing the condition completely and adding a wait for 2 triggers in the actions, but it didn’t work(

Maybe if I move the check condition to the “action” or am I again misunderstanding the principle of operation?
sorry for bothering

alias: Теsт Light
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.light
    from: "off"
    to: "on"
    enabled: true
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.motion1_occupancy
        state: "off"
        for:
          hours: 0
          minutes: 1
          seconds: 0
      - condition: state
        entity_id: binary_sensor.motion2_occupancy
        state: "off"
        for:
          hours: 0
          minutes: 1
          seconds: 0
action:
  - type: turn_off
    device_id: 7c0616bee889a383b58000cd05df5d1d
    entity_id: 1a46b93e1ef5b9e1df5cb7b50e7a1040
    domain: switch
mode: restart

Use a trigger that has both motion sensors in it being off for 1:00. Give them separate IDs.

Put a condition of that light state being on.

In the Action, use a choose on trigger ID.

First choose will be the first ID. Put an IF in there querying the second motion sensor to be off. If true, shut off the light.

Second choose will be the second ID. Put an IF in there querying the first motion sensor to be off. If true, shut off the light.

You can also use the sensors to determine presence in the room. I have not done this, but you can surely find it with a google search of home assistant presence detection.

Then, use that presence to turn the light on or off.

The motion sensor is the trigger…the light the action…anything else is a wrong way of thinking…
In this case there is no need for a condition, as that normally refers to something else not related to the trigger (and here the 1 minute does belong to the trigger :thinking:)

@jeffcrum That is an option (especially when you want to do it UI only), but it does make it unnecessary complex…

The issue is that there are 2 motion sensors that both need to be off for at least 1 minute.
Why not combine them in a YAML template trigger?
Something like this:

automation:
  trigger:
    - platform: template
      value_template: "{{is_state('binary_sensor.motion1_occupancy','off') and is_state(‘binary_sensor.motion2_occupancy’,’off’)}}"
      for: “00:01:00”

PS: Just a tip, try to avoid calling device directly, instead use

service: switch.turn_off
data: {}
target:
  entity_id: switch.light

This makes it easier when you need to replace the switch for some reason; as long as it uses the same name, it will not brake the automation. Using device_id will (as any replaced device will get a new ID :wink: )

It’s work! Thank you very much!

I think this is too redundant. I’m afraid of getting confused in the identifiers later)
But the idea is good, we need to study it in order to use it in other automations.
Thank you!

No sweat. They are all ideas. Some better than others. Go with what you like best.

@aceindy certainly had a simpler one there!

I am actually looking at my automations to see if I have a place to use it.

I have used this and kind of love it. But, I went away from the occupancy sensors and just use the motion sensors.

I found the sensor’s occupancy was holding ‘on’ much longer than I wanted. But, it is for the laundry room as opposed to like a TV room where motion might not happen, but occupancy should be tracked.

In the end, the wife is happy. So, I am ecstatic!!!

Ah…yes, the biggest challenge for HA owners…getting wife approval :smiley:

2 Likes