I receive an error which describes a code, which has already been replaced:
The error:
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:167
Integration: Template (documentation, issues)
First occurred: 06:00:00 (1 occurrences)
Last logged: 06:00:00
TemplateError('TypeError: '<' not supported between instances of 'str' and 'int'') while processing template 'Template("{% set stunde = now().hour %} {% set ivar = states('input_number.display_night_view_hour') |int %} {% if stunde >= ivar or stunde <= 5 %} true {% elif now().month in (3,10) and (stunde >= ivar or (stunde == 6 and states('sensor.lightlevel_terrasse') < 35)) %} true {% elif now().month in (11,12,1,2) and (stunde >= ivar or stunde <= 7) %} true {% else %} false {% endif %}")' for attribute '_state' in entity 'binary_sensor.display_night_view'
Which was the first verion of this binary sensor and was clear to me.
The current code which has ben reloaded at least 4 times:
display_night_view:
value_template: >
{% set stunde = now().hour %}
{% set ivar = states('input_number.display_night_view_hour') |int %}
{% set lightlevel = states('sensor.lightlevel_terrasse') |int %}
{% if stunde >= ivar or stunde <= 5 %}
true
{% elif now().month in (3,10) and (stunde >= ivar or (stunde == 6 and lightlevel < 35)) %}
true
{% elif now().month in (11,12,1,2) and (stunde >= ivar or (stunde <= 7 and lightlevel < 35)) %}
true
{% else %}
false
{% endif %}
Pretty sure that only works for the new template integration. You are using the legacy template sensor platform. That requires a Home Assistant restart.
Yes, the template entities. Up to now, it works with a simple reload of them. If not, then it must be new. I liked the idea of creating a new sensor, reload the templates and it’s available
But I’m quite sure that at least up to January I could simply reload the templates and got my new sensors or binary_sensors. This is a step back imo.
But as I almost finished with my HA, it’s not that important
I’m sure the reload only ever applied to the new integration. In any case it is easy to convert your sensor to the new format:
template:
- binary_sensor:
- name: "Display Night View"
state: >
{% set stunde = now().hour %}
{% set ivar = states('input_number.display_night_view_hour') |int %}
{% set lightlevel = states('sensor.lightlevel_terrasse') |int %}
{% if stunde >= ivar or stunde <= 5 %}
{{ true }}
{% elif now().month in (3,10) and (stunde >= ivar or (stunde == 6 and lightlevel < 35)) %}
{{ true }}
{% elif now().month in (11,12,1,2) and (stunde >= ivar or (stunde <= 7 and lightlevel < 35)) %}
{{ true }}
{% else %}
{{ false }}
{% endif %}
Or compacting the template a bit:
template:
- binary_sensor:
- name: "Display Night View"
state: >
{% set stunde = now().hour %}
{% set ivar = states('input_number.display_night_view_hour') |int %}
{% set lightlevel = states('sensor.lightlevel_terrasse') |int %}
{{ (ivar <= stunde <= 5) or
(now().month in (3,10) and (stunde >= ivar or (stunde == 6 and lightlevel < 35))) or
(now().month in (11,12,1,2) and (stunde >= ivar or (stunde <= 7 and lightlevel < 35))) }}
Ah, now I understood: There is a new template section in the config file.
So I have to move all template sensors and binary sensors to that section.
Looks like it is no big deal. Will do that by the time. Are there any restrictions to keep in mind?
In principle I simply have to rename all value_template into state then, right?