Hi
I have been working on using a timer in a light automation. It is all working fine after reading the documentation combined with some examples from this forum
I have a generic question to the use of the data key on YAML
I have these two working examples of starting a timer in an action in an automation
The duration clearly must be under a data or data_template
My question is a generic question about YAML in Home Assistant and not related to timer. It does work for me. I just want to understand better so I and others reading this can become more effective writing correct configs the first time
Why do the first two examples both work? When do I need to put the entity_id under data and when do I not? And when do I need the data key? Is there a good document I have overlooked that explains this?
Of my two examples - is one considered preferred? I’d like to submit a document update PR to add the duration override example to the timer documentation.
I personally ended up with both under data based on taste. But it is not clear from the answers if one is more correct than the other. The official documentation that Ahmad point to suggests the entity_id to be outside the data. And then Ahmad suggests it is nice inside.
mf_social suggests the outside form is a shortcut. But yes the documentation suggests it as normal even with data
So far i’d say they are both equal. Any other answers?
At the moment I lean on making my PR for adding the duration example to timer documentation as the example from the service calls doc.
I would love to understand why both work but I guess that means understanding how HA parses the configs and that is probably not easy to explain in words
Being able to ‘level up’ the entity_id is for convenience and neatness as in the majority of cases when you run a service the only data you are sending is the entity_id.
However, very often the only data required is the entity_id so, being near and dear to the service’s heart, it gets a pass on formality and this is acceptable: