I’ve been trying to get a template to work with no joy. all i have done is played with one template, it works perfect in the template editor but as soon as i add it to a template sensor it generates an error for some reason… anyway… each time I have made a change i have restarted home assistant just to make sure and this time all my templates stopped working… ive left it for a few hours incase it was just a loading issue but nope still not working…
here is my log
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:356
First occurred: 5:47:53 PM (4 occurrences)
Last logged: 5:47:53 PM
TemplateError('ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ (states('sensor.ender_5_pro_time_remaining') | int /60) | round(1) }}' but no default was specified') while processing template 'Template("{{ (states('sensor.ender_5_pro_time_remaining') | int /60) | round(1) }}")' for attribute '_attr_native_value' in entity 'sensor.ender_5pro_minutes_remaining'
TemplateError('ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ (states('sensor.sky_adsl_router_kib_s_received_4') | int / 1024) | round(1) }}' but no default was specified') while processing template 'Template("{{ (states('sensor.sky_adsl_router_kib_s_received_4') | int / 1024) | round(1) }}")' for attribute '_attr_native_value' in entity 'sensor.mbytes_received'
TemplateError('ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ (states('sensor.sky_adsl_router_kib_s_sent_4') | int / 1024) | round(1) }}' but no default was specified') while processing template 'Template("{{ (states('sensor.sky_adsl_router_kib_s_sent_4') | int / 1024) | round(1) }}")' for attribute '_attr_native_value' in entity 'sensor.mbytes_sent'
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ ((float(states.sensor.kitchen_temperature.state) + float(states.sensor.lounge_temperature.state) + float(states.sensor.office_temperature.state)) / 3) | round(1) }}' but no default was specified') while processing template 'Template("{{ ((float(states.sensor.kitchen_temperature.state) + float(states.sensor.lounge_temperature.state) + float(states.sensor.office_temperature.state)) / 3) | round(1) }}")' for attribute '_attr_native_value' in entity 'sensor.average_house_temperature'
I am not going to pretend i know what I am doing with any of this and I got a lot of help with creating the templates but i only touched one… no settings… no other files… just one template… how could this have happend?
thinking on it as i type this i did just install the latest update for home assistant could that be it?
Could you please post the template formatted properly. I cut and pasted from the error messages.
I think you sensors may not be available and you have a string which cannot be converted to a number. I set the defaults int(0); defaults to 0 if unavailable.
The first three sensors all reported a value of unknown whereas the fourth one reported unavailable. You should investigate why that happened because it’s abnormal.
The int filter cannot convert unknown or unavailable to an integer value (and that’s why you received 4 error messages). However, int(0) means the int filter is assigned a default value of 0 so when it’s unable to convert a value it will report 0. That’ll avoid an error message but it will also cause your calculation to report 0 (which may not be ideal because it introduces a spurious value into the sensor’s history). Long story short, determine why the sensors misbehaved and either correct or mitigate the cause of it.
I would try to comment out the last template sensor you made a change on and reload templates to see if that clears up the errors. If it does then fix that template sensor.
if it doesn’t then you have changed something else (by accident or otherwise) and it will be harder to find…at least for us since we don’t see your config.
I’ve changed the int to int(0) and there are no errors but i’m at a total loss as to why there are errors in the first place. this is one of the correctly formatted template sensors.
In your first post you said you restarted Home Assistant. It’s possible that on startup, when the Template Sensors are being initialized, the "sky adsl router " sensors they reference aren’t ready yet (meaning they haven’t acquired proper values yet and so their current value is unknown).
That was what i thought with the sensors but after eaving them for over 4 hours and they still showed unknown i guessed something else must be going on.
if all else fails and I have royally messed things up i can resort to a clean install, yes it’ll be a pain but hopefully it’ll sort it. my backups are partial and not old enough to help me.
for some reason i now have 5 versions of all my sensors in home assistant and only the fith one is returning a valid result. I changed the template sensor to check the correct sensor and its all working. now i need to find out why i have so many sesnors and how to remove the old ones leaving just the working ones.
I don’t see how that constitutes a durable solution: when you have multiple copies of a sensor, pick the last one that works.
It’s likely to work only until the next duplicate sensor is created (it’s already done this five times).The true solution is to determine why the underlying integration is repeatedly duplicating the sensor.
Is it an official integration or a custom component?
in my head it constitutes a durable solution as the initial problem was thought to me to be in the template, this was found not to be true therefore the initial problem is no longer a problem. as a result of this finding the cause of the problem has, in my head, moved to why are multiple sensors being created? this is not as you suggest linked to one intigration but as i said all my sensors in all intigrations official and otherwise.
yes i agree i still have a problem and it’s probably bigger than i thought. I have no clue as to why or how to find out what is causing this, but i know i am a step further to finding out and i hope that with the kind help of those such as yourself, who have forgotten more than i will ever know or understand at some point we can get to the bottom of this and have a system that will run without errors while also providing a resource for others who may hit the same problem.
I never suggested it was limited to a single integration. I focused on the integration representing the “sky adsl router” sensors merely as a starting point. There’s a lengthy debugging session needed to identify the root cause of the problem.
The template error you reported is merely a symptom of the, as yet unidentified, underlying problem. In my opinion, changing the sensor’s entity_id in the template is merely a stop-gap until that sensor also gets sidelined by yet another duplicate. However, if you think the steps you took represent a solution then so be it.
You’re welcome and good luck determining the underlying issue.