at startup this gives me 'sensor' is undefined errors at startup
[homeassistant.components.template.sensor] Could not render template Download Transmission Rate: UndefinedError: 'sensor' is undefined
[homeassistant.components.template.sensor] Could not render template Upload Transmission Rate: UndefinedError: 'sensor' is undefined
resulting in a state of unavailabe.
What can I do to fix that?
Another, secondary, question:
[homeassistant.components.template.sensor] Template sensor transmission_rate_up has no entity ids configured to track nor were we able to extract the entities to track from the value template(s)>
ok, I will add entitiy_id to the configuration, but shouldn’t the system be able to infer it from the very simple value_template?
Can you explain to me, why state_attr('sensor.fritzbox', 'transmission_rate_down') is better than states.sensor.fritzbox.attributes.transmission_rate_down? @Mutt mentioned, that it avoids errors on startup? What does that mean?
If the sensor hasn’t been initialized and/or doesn’t have any data then there will be an error written into the log when the system tries to access the informnation.
If you use the states() method then the results are None. Otherwise the results are unknown and the system couldn’t properly render the template which results in the error.
As finity explained, but the statements : -
is_state(), states() and state_attr() - (finity, can’t think of any others off the top of my head, what have I missed?)
Are specifically designed to cope with these sort of situations. And so should be used wherever possible.
Though I have to admit that I do use “states.” in the template editor when I’m exploring some entities, but usually wrap the results in the above formats