Hey, i have quite a few automations that looks like the one below, time based on and off, quite simple right?
My Problem is sometimes the automations do not work, i need do delete and recreate them from the same yaml and then it works.
I checked the yaml for these automations and it seems odd to me, it uses a number for device_id and entity_id, i thought this was the old logic / old syntax and we should use something like: entity: switch.ss9_aquariumlicht
Can i use this newer syntax in automations and how?
I heard devices are quite error prone, will this new syntax help there?
Automation code:
alias: Turn off Aquarium 09 Luft
description: ""
trigger:
- platform: time
at: "08:00:00"
condition: []
action:
- type: turn_off
device_id: 64b49a666ee54b4ff38cff71a39358b4
entity_id: 2c863d5011fda2bb85f16cd4016bb716
domain: switch
mode: single
actually using device idâs is the NEW way of doing things.
the device structure in automations isnât any more or less error prone than using entities/services (as far as I know unless something new has popped up).
the issue with using devices is that if/when you replace a device (device breaks, you update a device, etc) you have to go thru and manually change all of the scripts and automations to use the new device info. And it has to be done via the UI since you canât use devices via yaml. So it will get tedious if you use that device in many automations.
yes (even tho itâs technically the old way) but Iâm not sure why you are finding your automations breaking in the first place. So itâs hard to know if it will help.
if you want to test it then (Iâm assuming you use the UI to write automations since you use devices) using the example above you just need to select âcall serviceâ from the âactionâ drop down. Then select the âswitch.turn_offâ service. Then select the correct entity (switch.ss9_aquariumlicht).
for triggers or conditions use (for example) âstateâ, ânumeric_stateâ, etc to use entities instead of devices.
This will also male it easier to maintain your automation in case you need to replace it.
Just remove the device, put in a new device and give it the same name again.
Devices can be renamed, device_idâs and entity_idâs are uniquely generated and cannot be re-used everâŚ.
(which is basically the same as what @finity said; @Stiltjack also has a good pointđ)
I didnât think about that (since I never use devices )
just one more reason to not use them.
But a question it brings up tho is if an unavailable entity will also disable an automation that uses it? If so then itâs a wash for either method just based on that.
itâs true that they are uniquely generated but I can re-use the old entity_id on a new device as long as I remove the old entity_id (by removing the old device) first. I just need to go to the device configuration and select the entity and change it to match the old one there.
thatâs the reason itâs better to use entity_idâs instead of devices since entity_idâs can be reused where device_idâs canât.
I donât think itâs the same. An automation that depends on a device id will be disabled if the device is unavailable. If an entity is unavailable the automation will still be enabled, and the outcome will depend on the function of the entity in it. It may never run, for example, if the state of the entity is the trigger. If the state of the entity is part of a condition, it may stop or take the wrong path. Unavailable (and unknown) are valid states.
Edit: But actually, the OP was asking about automations that stop working - so this is probably a red herring. My fault, sorry.
yeah, so much changes so fast itâs hard to keep up with how things break or not. Even for us seasoned users. I canât imagine trying to be a new user who doesnât have their sea legs with HA and trying to deal with the constant barrage of (sometimes undocumented) breaking changes.
it just seems that no matter how much things are changed to try to âmake it easyâ for new users it still just makes things more confusing to the point that even seasoned users have a hard time figuring things out sometimes.
Thanks a lot, thats exactly what i needed, the named entity_id is the best way to do things because stuff can be renamed.
For the people saying if a device goes offline the automation will be disabled, my devices were not offline and the automation was still enabled but it did not work (i had this multiple times and only with devices). When i delete and recreate the exact same automation it did work again.