I am currently writing the first automations in HA. Now I ask myself what happens if I have to replace a device because it is broken or there is a better one. How can I design my programs in such a way that this is not a problem? Should I write all sensors in the config.yaml myself?
It’s a big problem that you can avoid by not using device triggers, conditions or actions. There are always other triggers conditions and actions you can use instead.
e.g. instead of a device turn on trigger use a state trigger.
If you only ever use entity_ids in your triggers, conditions and actions then when you have to replace the device you can change the new entity id to match the old one in one place and all your automations keep working.
If you use device ids you have to change all of them. Everywhere they are used.
Also device actions, triggers and conditions do not support more advanced features like templating.
Automations that depend on device ids will also seem to “disappear” if the devices they depend upon become unavailable. This has been fixed. They will now be marked unavailable.
This is very helpful advice, thank you!
Is there by any chance a repo of best practices such as this?
For example, I’d love to understand the practical difference between using Trigger+Duration vs Trigger+Delay Action.
- If I set Change Mode to Restart, do they behave equivalently?
- Other than being able to set Duration separately for each trigger, as opposed to Delay for the whole automation, are there any differences between the semantics of the two?
Thanks!