What am i doing wrong with this automation?

Hi,

I am trying to create an automation but cant get it to make it run automatically… watched several tutorials and tried different methods, I am still struggling to get it run automatically….

Here is the idea….

2 motion sensor
1 light

When both motion sensors stopped detecting motion after 25 seconds of no motion then it turns off the light… (it’s important to note I’m using Aqara P1 sensor with detection interval set to 5 seconds)…

Below is the YAML code and for some reason it fails to trigger automatically… lights on automation for the same setup works flawlessly…

alias: Bathroom Off
description: ""
trigger:
  - type: no_motion
    platform: device
    device_id: 5f4869dab2a49af9f48917a72df27a03
    entity_id: d9cfe254e2ac69a2ba05991f1d5686b3
    domain: binary_sensor
    id: " Bathroom clear"
    for:
      hours: 0
      minutes: 0
      seconds: 25
  - type: no_motion
    platform: device
    device_id: 40c430df00706bbf2b03a6a37e3835cb
    entity_id: 8e463624ef85210e37f221bff48fd4b3
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 25
    id: Shower Clear
condition:
  - condition: and
    conditions:
      - condition: trigger
        id:
          - " Bathroom clear"
      - condition: trigger
        id:
          - Shower Clear
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.bathroom_lights
        - light.sdb_plafonnier_sdb_applique_undefinedtype_singleton
    data: {}
mode: single

Thanks to all the help possible….

Hello
I am no expert but I think you need to have the second check at the Then Do section i.e. if the automation was triggered by Bathroom clear then do xxx otherwise if triggered by Shower Clear then do yyy.

You do that by using “Add building block → Choose”

No it isn’t. Click the three dots, Edit in YAML, copy that code and paste it, formatted with the </> button so it looks something like this:

alias: Pump restart
description: >
  Restarts the aquarium pump after 40 mins off, plus lots of safeguards to make
  sure it's running.
trigger:
  - platform: state
[etc]

No, the strategy here is good:

  • trigger off either motion sensor being off for 25 sec
  • check both motion sensors are clear
  • run the action

I think, and will need the YAML to confirm, that the problem lies with the type of condition test chosen. The “when triggered by” is probably wrong.

hi @Troon ooppsieee, forgot to add the code… now updated it with the YAML code… thanks for all the help

Yeah, what you’ve done there isn’t going to work. The condition block is looking for both triggers to be responsible for the automation running — but because triggers are instantaneous events they won’t both trigger at the same time.

Here’s an example of what happens:

  • bathroom sensor goes clear for 25s
  • condition block checks for both:
    • triggered by bathroom sensor (YES)
    • triggered by shower sensor (NO)
  • flow stops as condition failed.

then, a few seconds later:

  • shower sensor goes clear for 25s
  • condition block checks for both:
    • triggered by bathroom sensor (NO)
    • triggered by shower sensor (YES)
  • flow stops as condition failed.

You don’t need the AND in the condition, as they are AND by default. Change the condition block to use state checks not trigger checks, substituting in your motion sensor entity IDs (will be something like binary_sensor.shower_motion depending how you’ve set it up):

condition:
  - condition: state
    entity_id: binary_sensor.bathroom_motion
    state: 'off'
  - condition: state
    entity_id: binary_sensor.shower_motion
    state: 'off'

Always better to use entity IDs and real states like 'off' rather than obscure device IDs and “translated” states like “Clear” — I’d also change the trigger section to:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.bathroom_motion
      - binary_sensor.shower_motion
    to: 'off'
    for: "00:25:00"

Now the action will run when a sensor is clear for 25s and the other sensor is also clear.

1 Like

Thanks a lot @Troon … it worked…

For anyone in future looking into the same here is the full YAML code for simplicity.
You will have to change the entitiy ID (to your sensor names and adapt the time for your requirements)

alias: Bathroom Off
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.0x54ef441000497060_occupancy
      - binary_sensor.aqara_shower_motionsesor_occupancy
    to: "off"
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition:
  - condition: state
    state: "off"
    entity_id: binary_sensor.0x54ef441000497060_occupancy
  - condition: state
    entity_id: binary_sensor.aqara_shower_motionsesor_occupancy
    state: "off"
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.bathroom_lights
        - light.sdb_plafonnier_sdb_applique_undefinedtype_singleton
    data: {}
mode: single

1 Like

Grouping your bathroom sensors with a Helper will also simplify the process. If one sensor is ON, the group sensor will report the state as ON. The state will not report OFF until all bathroom sensors clear.

I have a large master bath that requires 3 sensors. Grouping the sensors solved a lot of my automation issues.

1 Like

Thank you, seems like a good idea too… what about the cool down times if they are from different brands? I mean I have an Aqara & tradfri that I might group for bedroom but I know ikea tradfri has ridiculous cool down timer of 3 mins…

Could you share your YAML code please, it could be easier as a newbie for me to replicate…

The brand won’t matter, as a group HA only monitors the state of each entity in the group. The state won’t display OFF until the slowest sensor of the group clears.

I use different occupancy timeouts for sensors that are part of a group.

No need for YAML, the setup uses the UI.