I have an automation that needs to turn off a light in one room if occupancy is detected on either of two occupancy sensors. No matter what I try I keep getting an error. Here is how I thought my trigger should be done:
- trigger:
not
- Trigger:
Home Assistant is case sensitive and automations are a list not a dictionary. (Use a -
in front of trigger).
Also have a read of this: Why and how to avoid device_ids in automations and scripts
Good to know, but changing the case didn’t fix what I have. Will look at your link as well. Thank you.
That’s a malformed automation.
Your screenshot shows the When field of an automation being created in the Automation Editor in YAML mode. For some inexplicable reason, the first line contains this:
automation:
That doesn’t belong there.
I suggest you delete the automation and start over with the Automation Editor exclusively in Visual mode. Avoid using it in YAML mode until you are familiar with the correct YAML structure of an automation.
Some background, initially I created two separate triggers in the visual editor. That didn’t work. So I switched to YAML, and copied the YAML code from one in to the other. Essentially what is in my screen shot minus the “Automation:” bit. Later I read the multiple trigger section of the docs and it showed the Automation: tag, so I added it. Either way I can’t get it to save. I just need a light to turn off if motion is detected in either of two rooms. I’m only a day in to this so forgive my ignorance.
Create the automation again (with two separate triggers).
Then post the entire automation in YAML format so we can examine it.
Here you go:
alias: Guest Bathroom Light OFF
description: ""
trigger:
- type: occupied
platform: device
device_id: 7fc1cd25eb353eae87f0ff5345dfd90f
entity_id: 1ee81c8f36adc342098864713c561f85
domain: binary_sensor
- type: occupied
platform: device
device_id: c975a741eb6026b55e4833662a395629
entity_id: ab3e88c2a52a43c3ee3736d0c26d8421
domain: binary_sensor
condition:
- condition: device
type: is_on
device_id: b1f8d1924eb499a1484ab5d99bec4dbd
entity_id: 941a3e3e6a89b945e7eb79a66cfddc6b
domain: light
action:
- type: turn_off
device_id: b1f8d1924eb499a1484ab5d99bec4dbd
entity_id: 941a3e3e6a89b945e7eb79a66cfddc6b
domain: light
mode: single
That automation is designed to monitor two binary_sensors. If either one reports ‘occupied’, and the light is currently on, the light will be turned off.
If it doesn’t behave like that, examine its trace (which is produced whenever either of the two triggers is triggered).
If there’s no trace then the automation was never triggered.
OK thanks. Glad to know that it should work. I’ll do a bit more digging then.
Did you make any progress with it?
Actually, I did. It was pointed out to me that best practice was to point automations at entities whenever possible. So, I went through all of my automations and cleaned them up. This solved most of my issues. Coming from Homeseer, it’s taken a while to adapt to the new vernacular. But it’s slowly coming in to focus.
Are you saying you replaced the Device Triggers with another kind of trigger (like a State Trigger)?
Because that’s not normally considered to be the cure for an ailing Device Trigger. Effectively you re-wrote the automation which, on occasion, can be a cure in itself (i.e. clearing out the cobwebs).
Correct on both counts. The first time I created my automations were more guessing than knowing. By the time I got around to re-writing them, I had a better understanding of how things work. Some of my confusion came from the fact that YAML cold is often provided with the assumption that the reader will know where it goes. The issue with that is that there are often multiple places where you can edit YAML. For instance, in dashboards, you can edit the YAML for a card, or for the entire dashboard. That sort of thing. Lastly, I think that I’ve been running into collisions with my automations. Since changing a few of them from “Single Mode” to “Queued Mode”, things have been a lot more reliable. I’m still learning about the ramifications of this change.