Thank you @petro and @123 you both have been very helpful in getting me through this learning curve. I am finally starting to understand what each line means in the template (still making mistakes) but getting there. This site has help me
I still don’t understand some of the arguments. Is HA using a combination of Python / Jinja for what is allowed? For example I had used the word multiply in my template ( must have copied it from someones code) and I can’t understand why instead of just using " * ". Where can I get more information on “allowed” operations?
Where do I find the filters that were added to HA?
I would think now that they are making sure the code has the correct defaults, maybe there should be some documentation if HA is allowing differences than what is in the Jinja docs.
When you do markdown cards do they follow the jinja docs, CSS or a combination?
For those curious, the multiply filter seems to make its first appearance in a PR from 2015:
It’s not clear from the PR what problem it was intended to solve. Perhaps the only notable thing is that it automatically converts strings to float before performing the multiplication. I don’t see any reference to it in the documentation.
Hello guys!
I have same problem as many here, and i can’t find a solution for my case anywhere. I have date and time “assembled” together and currently it works fine, but of course it will need change in December. But, all options i tried - none of them work. My code, which now results in warning:
If i try "float(‘Pon’) is an error. If i insert "default = “Pon” at the end i always get “Pon”, no matter what day it is (Pon meand Mon in my language).
Exactly. Above “composition” gives me today’s date and current time:
Sre, 13. Okt - 20:53
Which would be (in english) : Wed, 13th. Oct - 20:53
If there’s any easier way i’m very open to suggestions. I’m not skilled programmer, i manage to “assemble” thing like this with internet searh&help (from you, guys!) and that’s pretty much it…
Yeeeeah! It works! Thanks a lot! Now I will play a bit with your template in Template Editor to try understand how it works… i like to at least try to understand what i’m doing…
Now only thing left in core’s log is warning for my sensor “sensor.danes”. How do i change this into new format:
this sensor should give me only day of the week. I have same template for month name, too. It’s easy for “native englishmen”, since they have such names easier available (it’s not needed to convert to local)…
to be honest, i’m not quite sure why “float” is needed for strings…?
EDIT: is this correct? It gives correct result in template editor… I removed [:x]part, because day length is “day dependant”…
The float function can’t convert non-numeric strings into numbers. When it can’t convert the string it simply reports 0 by default (or whatever default value you specify).
Effectively, you are trying to do this and it will always report 0
I guess i wrote wrong… with day of the week i meant NAME of that day (as you already figured it out…).
So, if i understand correct float is for conversion to numbers and as such not needed in my case? As i said, i made this on the base of what i found on the internet, and since it worked i left it this way… if this is the case then my question is really in wrong place. Sorry for that, my basic question is how to add default to float…
2021-10-08 14:03:34 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'None' when rendering template '{{value_json.currentZ|float}}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12
to the “HomeAssistant Discovery” plugin in OctoPrint and have summitted a pull request to fix issue #78.
Template warning: ‘as_timestamp’ got invalid input ‘unknown’ when rendering template ‘{{as_timestamp(strptime(states(‘sensor.afvalinfo_kerstboom’), ‘%d-%m-%Y’)) |timestamp_custom(’%A’) | as_timestamp(‘0’)}}’ but no default was specified. Currently ‘as_timestamp’ will return ‘None’, however this template will fail to render in Home Assistant core 2021.12
Template warning: ‘timestamp_custom’ got invalid input ‘None’ when rendering template ‘{{as_timestamp(strptime(states(‘sensor.afvalinfo_kerstboom’), ‘%d-%m-%Y’)) |timestamp_custom(’%A’) | as_timestamp(‘0’)}}’ but no default was specified. Currently ‘timestamp_custom’ will return ‘None’, however this template will fail to render in Home Assistant core 2021.12
Template warning: ‘strptime’ got invalid input ‘unknown’ when rendering template ‘{{as_timestamp(strptime(states(‘sensor.afvalinfo_’), ‘%d-%m-%Y’)) |timestamp_custom(’%A’) | as_timestamp(‘0’)}}’ but no default was specified. Currently ‘strptime’ will return ‘unknown’, however this template will fail to render in Home Assistant core 2021.12
Template warning: ‘as_timestamp’ got invalid input ‘unknown’ when rendering template ‘{{as_timestamp(strptime(states(‘sensor.afvalinfo_’), ‘%d-%m-%Y’)) |timestamp_custom(’%A’) | as_timestamp(‘0’)}}’ but no default was specified. Currently ‘as_timestamp’ will return ‘None’, however this template will fail to render in Home Assistant core 2021.12
Template warning: ‘timestamp_custom’ got invalid input ‘None’ when rendering template ‘{{as_timestamp(strptime(states(‘sensor.afvalinfo_’), ‘%d-%m-%Y’)) |timestamp_custom(’%A’) | as_timestamp(‘0’)}}’ but no default was specified. Currently ‘timestamp_custom’ will return ‘None’, however this template will fail to render in Home Assistant core 2021.12
Hi there, I do get them same warnings but could not find the cause, could anybody help on that? Thanks!
Template warning: ‘float’ got invalid input ‘unavailable’ when rendering template ‘{% set daily_min = states(‘sensor.daily_wohnen_temp_min’) | float %} {% set current = states(‘sensor.indoor_temperature’) | float %} {% if daily_min == ‘unknown’ %} 99 {% elif (now().hour == 0 and now().minute == 0) %} {{ current | float }} {% else %} {{ current if current <= daily_min | float else daily_min | float }} {% endif %}’ but no default was specified. Currently ‘float’ will return ‘0’, however this template will fail to render in Home Assistant core 2021.12
and the code is:
value_template: >-
{% set daily_min = states('sensor.daily_outdoor_temp_min') | float %}
{% set current = states('sensor.outdoor_temperature') | float %}
{% if daily_min == 'unknown' %}
99
{% elif (now().hour == 0 and now().minute == 0) %}
{{ current | float }}
{% else %}
{{ current if current <= daily_min | float else daily_min | float }}
{% endif %}
The message indicates the float filter was given a value of unavailable. That means this returned unavailable
states('sensor.daily_outdoor_temp_min')
float cannot convert unavailable to a numeric value so it will report a default value. Traditionally, float’s default value is 0 but, in the future, you will be obligated to specify a default value. If you fail to provide a default value in the current version (2021.10.0) you get a warning message but starting in 2021.12.0 it will be an error message.
If the value of states('sensor.daily_outdoor_temp_min') is unavailable and you do this:
{% set daily_min = states('sensor.daily_outdoor_temp_min') | float(0) %}
you won’t get a warning message and daily_min will be set to 0 (but you can set the default value to whatever you prefer).
BTW, this line in your template will never be true:
{% if daily_min == 'unknown' %}
daily_min’s value is set by float and it never returns unknown (unless you make that it’s default value).
Does this mean that Jinja had default values for the filters and this was changed on this coming release? I tried to look up default Jinja filter values and could not find any information. I would think if there is a default setting for the filter it should be set and be able to be over written by a user.