@petro@123 Could you guys please help, my log is piling up and I have used strptime in the past and with the new HA update its throwing warnings.
Here is my code:
- platform: template
sensors:
minutes_next_alarm_ahmed:
friendly_name: "Minutes until Next Alarm Ahmed"
unit_of_measurement: "m"
value_template: >-
{% set dummy = states("sensor.time") %}
{{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60 +4.59)|int}}
availability_template: "{{ not is_state('sensor.sm_g986b_next_alarm','unavailable') }}"
attribute_templates:
time: "{{ state_attr('sensor.sm_g986b_next_alarm','Local Time') }}"
- platform: template
sensors:
minutes_next_alarm_ahmed_original:
friendly_name: "Minutes until Next Alarm Ahmed 5mins ahead"
unit_of_measurement: "m"
value_template: >-
{% set dummy = states("sensor.time") %}
{{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}
availability_template: "{{ not is_state('sensor.sm_g986b_next_alarm','unavailable') }}"
attribute_templates:
time: "{{ state_attr('sensor.sm_g986b_next_alarm','Local Time') }}"
And here are the non-stop warnings:
2021-10-11 12:22:21 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'unavailable' when rendering template '{% set dummy = states("sensor.time") %} {{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60 +4.59)|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
2021-10-11 12:22:21 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'unavailable' when rendering template '{% set dummy = states("sensor.time") %} {{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|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
2021-10-11 12:22:21 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'unavailable' when rendering template '{% set dummy = states("sensor.time") %} {{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|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
@petro ok that worked perfect… how about when I have some value after timestamp?
Like in this code:
- platform: template
sensors:
blue_bin_in_days:
friendly_name: Blue Bin
icon_template: 'mdi:recycle'
value_template: >-
{% set date_in = states.sensor.recyclables_eventdate.state|replace('\n', '') %}
{% set bin = strptime((date_in), "%a, %d %B %Y") %}
{% set diff = as_timestamp(bin) - as_timestamp(now()) %}
{% set days = ((diff / 86400)+1) | int %}
{% if days == 0 %}
Today
{% elif days == 1 %}
Tomorrow
{% elif days == 7 %}
1 Week
{% elif days == 14 %}
2 Weeks
{% else %}
{{ days }} days
{% endif %}
As the above throws the following warnings:
2021-10-11 12:22:21 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'strptime' got invalid input '2021-10-20T00:00:00' when rendering template '{% set date_in = states.sensor.recyclables_eventdate.state|replace('\n', $
Today
{% elif days == 1 %}
Tomorrow
{% elif days == 7 %}
1 Week
{% elif days == 14 %}
2 Weeks
{% else %}
{{ days }} days
{% endif %}' but no default was specified. Currently 'strptime' will return '2021-10-20T00:00:00', however this template will fail to render in Home Assistant core 2021.12
2021-10-11 12:22:21 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'strptime' got invalid input '2021-10-20T00:00:00' when rendering template '{% set date_in = states.sensor.recyclables_eventdate.state|replace('\n', $
Today
{% elif days == 1 %}
Tomorrow
{% elif days == 7 %}
1 Week
{% elif days == 14 %}
2 Weeks
{% else %}
{{ days }} days
{% endif %}' but no default was specified. Currently 'strptime' will return '2021-10-20T00:00:00', however this template will fail to render in Home Assistant core 2021.12
sorry did you mean to say I should add default=0 to this line? like:
{% set diff = as_timestamp(bin, default=0) - as_timestamp(now(), default=0) %}
because I did that and still get the same warning. Unless you meant I should use this as_timestamp(whatever_you_currently_have, default=0) instead of strptime((date_in) in this line {% set bin = strptime((date_in), "%a, %d %B %Y") %}