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…
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.
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.
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
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.
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.