a breaking change for template behaviour was introduced recently.
among other warnings I get:
Template warning: 'as_timestamp' got invalid input 'unavailable' when rendering template '{{ ((as_timestamp(states('sensor.date_time').replace(',','')) | int) + 1*60) == ((as_timestamp(states('sensor.pixel_5_next_alarm')) | int)) }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2021.12
Even tough, I tought it’s only related to ‘float’ I did a try and error and changed it to:
Template warning: 'as_timestamp' got invalid input 'unavailable' when rendering template '{{ ((as_timestamp(states('sensor.date_time').replace(',','')) | int(default=0)) + 1*60) == ((as_timestamp(states('sensor.pixel_5_next_alarm')) | int(default=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
479 / 5000
Resultados de traducción
I have this sensor so that the ssl certificates are given to me in days instead of week and I can’t get it to work, can you help me please? Thank you.
`` `- platform: template
scan_interval: 86400
sensors:
cert_ssl:
friendly_name: ‘Ssl Certificate’
value_template:> -
{{(((as_timestamp (states.sensor.cert_expiry_timestamp_warrior_kick_duckdns_org_32123.state) | int) - (now (). timestamp () | int)) / 86400) | int | round (0)}}
unit_of_measurement: ‘days’```
I have tried with as_timestamp (0) but nothing, not default = 0
Look through your template, find the as_timestamp and add the default in the appropriate spot. Use my previous example as a guide. If you can’t get it working, post what you tried here.
Also, please keep your posts in english. So use google translate before posting. Thanks.
2022-02-10 20:42:07 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'int' got invalid input 'unavailable' when rendering template '{% if (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int is integer) and (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int - states('sensor.house_power_consumption') | int > 0) %}
{% if (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int is integer) and ((states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int - states('sensor.house_power_consumption') | int) > 5999) %}
5999
{% else %}
{{ (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int - states('sensor.house_power_consumption') | int) }}
{% endif %}
{% else %}
0
{% endif %}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1
at night, there is no sun, so the fonrius inverter is off.
{% if (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') is not string) and (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int - states('sensor.house_power_consumption') | int > 0) %}
{% if (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') is not string) and ((states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int - states('sensor.house_power_consumption') | int) > 5999) %}
5999
{% else %}
{{ (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int - states('sensor.house_power_consumption') | int) }}
{% endif %}
{% else %}
0
{% endif %}
All you had to do was supply default values for the |int filters you are using. e.g. instead of |int you could supply a default value of 0 like this |int(0), or none, like this |int(none).
You should also add an availability template to render the state of your sensor unavailable if this happens. This will protect against erroneous Energy Dashboard readings.
In addition to what tom said, you also want to keep the conversions to 1 instance and not many instances.
{% set power_ac = states('sensor.power_ac_fronius_inverter_1_http_192_168_1_148') | int(none) %}
{% set consumption = states('sensor.house_power_consumption') | int(none) %}
{% if none in [ power_ac, consumption ] and power_ac - consumption <= 0 %}
0
{% else %}
{{ [ power_ac - consumption, 5999] | min }}
{% endif %}
This has 1 conversion from string to int for each sensor, and it’s functionally identical to your other method.
Some things to note, if statements have order of operations. When you use if x and y, it resolves things left to right. If the left arugment fails, it doesn’t resolve the right because the and will fail no matter the value of the right. The if statement above none in [ power_ac, consumption ] is resolved before power_ac - consumption <= 0, which ensures that power_ac - consumption <= 0 will be numbers when the first statement passes, but it will not error when it fails.
TemplateError(‘ValueError: Template error: as_timestamp got invalid input ‘None’ when rendering template ‘{% set time = state_attr(‘sensor.tide_bhb’, ‘next_high_tide_time’) %} {% set ftime = as_timestamp(time)|timestamp_custom(’%I:%M %p’) %} {{ ftime }}’ but no default was specified’) while processing template ‘Template<template=({% set time = state_attr(‘sensor.tide_bhb’, ‘next_high_tide_time’) %} {% set ftime = as_timestamp(time)|timestamp_custom(’%I:%M %p’) %} {{ ftime }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.next_high_tide’
How did I fix this error?
My template sensor is:
{% set time = state_attr('sensor.tide_bhb', 'next_high_tide_time') %}
{% set ftime = as_timestamp(time)|timestamp_custom('%I:%M %p') %}
{{ ftime }}