Hi,
I noticed that after a recent update of HA, my template stopped working.
I know that the syntacs has changed, but I can’t get it working again.
Anyone that can help me with this?
(I added a # to prevent configurtion.yaml from stopping)
The bit I’d add that caught me out recently (Value template can no longer reference attributes) is how certain templates/definitions break without default values. The impact of the break depending on the rest of the setup.
The examples above includes defaults for float that your original yaml doesn’t. My guess is the inverter sensor you’re using isn’t initialised yet in startup, that fails with float and leaves this sensor as null breaking something else.
I would recommend a trawl through your config to put defaults in across the board.
Hi Taras,
Thank you.
To be honest, I am struggling with Yaml, and I am afraid I could have used the legacy system and modern system together.
I am now trying to clean up the configurtion.yaml, as an example, I have created a new mqtt.yaml file to make things neater.
Should I create a separate template.yaml file to make it easier to maintain?
Could you check my configuration.yaml file for inconsistencies, maybe?
There are no passwords in that file, I keep them in secrets.yaml.
It would really help to let my configuration.yaml checked by someone with a bit more experience.
Rob
So if I understand correctly, then creating a template.yaml would mean that I should use the modern mode.
But if I have created a sensors.yaml (like I have) that is Legacy mode?
I would assume that everything should go in modern mode, so I would need to convert my sensors.yaml file?
In my sensors.yaml file, I have a few of these (example):
You can continue to have a combination of modern and legacy Template Sensors. Just keep them in separate files. You’re not obliged to convert your existing legacy Template Sensors into modern Template Sensors. The legacy format wasn’t officially deprecated, it simply won’t get any more enhancements. If you want to convert them to modern format, feel free to do so at your own pace (i.e. you don’t have to convert them all at once).
In my case, I continue to use the many legacy Template Sensors I have; when I need a new one I create it in modern format.
Hi Taras,
Thank you for your answer, really appreciated !
I create a template.yaml, but now get an error in the log about the template.
Error:
Template variable warning: 'dict object' has no attribute 'linkquality' when rendering '{{ value_json.linkquality }}'
15:56:52 – (WARNING) helpers/template.py - message first occurred at 13:46:20 and shows up 33 times
Invalid config for [template]: [value_template] is an invalid option for [template]. Check: template->sensor->0->value_template. (See /config/templates.yaml, line 0).
15:56:40 – (ERROR) config.py - message first occurred at 15:56:22 and shows up 3 times
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{states.sensor.watermeter.attributes["waterflow"] }}")' for attribute '_attr_native_value' in entity 'sensor.watermeter_flow'
13:45:48 – (ERROR) helpers/template_entity.py - message first occurred at 13:45:48 and shows up 2 times
Error while processing template: Template("{{states.sensor.watermeter.attributes["waterflow"] }}")
13:45:48 – (ERROR) helpers/template.py - message first occurred at 13:45:48 and shows up 2 times
‘dict object’ has no attribute ‘linkquality’ when rendering ‘{{ value_json.linkquality }}’
The received value didn’t contain a linkquality key. You’ll have to investigate that.
[value_template] is an invalid option for [template].
That’s due to my mistake. My example of a modern format Template Sensor (posted above) suggested you can use value_template and that’s wrong. Modern format uses state (and I have corrected the example). Replace value_template with state in all of your modern format Template Sensors.
‘None’ has no attribute ‘attributes’') while processing template ‘Template(“{{states.sensor.watermeter.attributes[“waterflow”] }}”)’ for attribute ‘_attr_native_value’ in entity ‘sensor.watermeter_flow’
Error while processing template: Template(“{{states.sensor.watermeter.attributes[“waterflow”] }}”)
You may have entered the wrong entity_id because Home Assistant couldn’t find it. Is it sensor.watermeter or sensor.watermeter_flow or something else?
Thanks, I was able to fix this, and now the orange dot that notified me of template errors is gone.
I will look into the other errors later.
What do you suggest? Remove all the entries containing a template out of the sensors.yaml?
I can leave the other entries in there? Like these…: