Templating changes in 2021.10.0

I copied and pasted your example. In my template editor it gives an answer of zero. In my configuration / logs there is nothing. I tried clearing the logs and re doing the code and still nothing in my logs.

This was done on my tablet. I did the same thing on my computer and the warning showed in the logs.

Why would it be device dependent?

Are you viewing the text logs or the logs in the UI?

Hello,

I also have a template problem that I can’t solve.

      total_pagar_shelly_em_casa:
        friendly_name: "Fatura Energia"
        icon_template: "mdi:currency-eur"
        value_template: >-
          {{ states('sensor.eletricidade_custo_mes_shelly_em_casa_s_iva')|float + states('sensor.taxas_impostos_shelly_em_casa')|float + states('sensor.total_iva_shelly_em_casa')|float }}
        unit_of_measurement: "€"
2021-10-09 12:52:15 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'unknown' when rendering template '{{ states('sensor.eletricidade_custo_mes_shelly_em_casa_s_iva')|float + states('sensor.taxas_impostos_shelly_em_casa')|float + states('sensor.total_iva_shelly_em_casa')|float(default=0) }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12

Can anyone give me a light?

Thanks

I followed the directions, which is from the ui.

Ui logs are prone to update issues on browsers, especially iOS 15. So refresh the page or use the text logs.

1 Like

You only provided a default for 1 of the floats, all 3 need one. You also don’t need the word default, you can just provide the number.

Su logs I presume?

home-assistant.logs in your config folder, its what the UI logs are based off of.

OK…
I’m not very good at templates, how can I solve this case?
Thanks

Looks like your system has a little problem because, as per my previous post, I do get a warning message thereby proving Home Assistant is capable.

Start by checking the configuration of the logger integration. If you didn’t configure it, warning is the default logging level.

If you didn’t alter its default settings then I don’t know what else may be responsible for suppressing the warning messages.

So, the bases on this are already covered. I put in a PR to change the functionality, but to keep things consistent in all of templates (every method, if statements, and filters), many more changes would need to occur. Also, this was already covered in the docs as expected functionality. 3rd bullet past the notes:

1 Like

Which command from CLI? to view the home-assistant.log. I do not see this option from the docs.

No the problem is the way the logs are displaying. It works on some of my devices not on all. Seems it works on all my PCs so I will use them to edit.

On which clients does it not work?

Tablet. Still think it is crazy that you’re required to make this change prior to the Dec release but the existing tool to help figure out the errors doesn’t show the warning. If a template generates a warning I would think most people would want to see the warning in the editor. I believe this would make the tool much better.

I thought I would share one of my experiences…

My SolarEdge sensors are cloud based, and I use template sensors with them to do a few things, such as changing units of the cloud sensors from Wh to kWh, etc. After upgrading to 2021.10, I started getting warnings for these template sensors regarding unavailable while using float. Sure enough I found that the cloud based sensors were going unavailable several times a day, but my template energy sensors were going to 0 during this time (presumably because float default was 0).

As there is now a is_number() filter in 2021.10, I am now using is_number now to qualify my template sensors and do the conversions (say Wh to kWh) only if the cloud sensor has a numeric state. So if the cloud based sensors go unavailable (or anything else non-numeric), so will my template sensors.

1 Like
tail -f /config/home-assistant.log

The test results I posted above were from my tablet. Android 10 and MS Edge.

I don’t know why your one client (a tablet) is selective about which log entries it does/doesn’t show. Very strange.

I agree with petro that this is probably the exact use-case that spurred the development team to tighten-up how default values are handled.

Anomalous values were being masked by silently rendering them as 0. Now that you have discovered this was happening in your template, you’ve taken measures to mitigate it and thereby making your template more error-resistant (and producing more consistent results). Good work! :+1:

1 Like

As petro said, maybe a cache issue.