Pirol_62
(Joerg)
February 23, 2020, 5:47pm
1
Hi,
I got the following error:
Sun Feb 23 2020 18:43:21 GMT+0100 (Mitteleuropäische Normalzeit)
Error during template condition: UndefinedError: 'None' has no attribute 'state'
Erfolgreich gespeichert
This error appears every 2.5 Minutes.
I checked every template in automation, sensors, binary sensors and switches.
All templates are working.
Where could that come from.
I’m on a fresh installed 105.3 and rasp 3+
My guess without seeing any config is that you are doing this somewhere
states.sensor.my_sensor.state
rather than
states('sensor.my_sensor')
If the entity you are referring to is unavailable, even temporarily, you will get these errors using the first type of usage.
See warning in this section . There are multiple suggested methods.
1 Like
Pirol_62
(Joerg)
February 23, 2020, 10:09pm
3
Thanks, I will try it.
You’re right, I use the first version.
Pirol_62
(Joerg)
February 24, 2020, 7:08am
4
Hi,
ok, I changed that. But this doesn’t solve my issue.
There must be something else.
As it is around every 2.5 Minutes, I guess that must be a sensor or binary_sensor.
I dont’t have automations running in such a frequency.
Is that assumtion right? Or do I miss something?
Do you have a lot of templates? If not, please post them here and we can take a look.
Pirol_62
(Joerg)
February 24, 2020, 8:55am
6
I have tons of templates, I try it:
Here are the relevant sensors:
- platform: template
sensors:
days_to_leave:
friendly_name: 'Tage bis Urlaub'
value_template: '{{ (as_timestamp(states.calendar.gmail_urlaub.attributes.start_time) /86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) /86400) |int }}'
unit_of_measurement: 'Tage'
active_harmony_scene:
friendly_name: 'Aktive Szene'
value_template: '{{ state_attr("remote.wohnzimmer", "current_activity") }}'
next_sunrise:
friendly_name: Sunrise
value_template: '{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom("%H:%M") }}'
next_sunset:
friendly_name: Sunset
value_template: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom("%H:%M") }}'
cover_livingroom_position:
friendly_name: 'Position Rollo WZ'
value_template: '{{state_attr("cover.rolladen_wohnzimmer", "current_position")}}'
unit_of_measurement: '%'
cover_kitchen_position:
friendly_name: 'Position Rollo Küche'
value_template: '{{state_attr("cover.rolladen_kuche", "current_position")}}'
unit_of_measurement: '%'
last_called_alexa:
entity_id:
- media_player.wohnzimmer
- media_player.schlafzimmer
- media_player.kuche
- media_player.gastezimmer
- media_player.office
- media_player.fitnessraum
value_template: >
{%- for entity in states.media_player -%}
{%- if state_attr(entity.entity_id, 'last_called') == True -%}
{{ entity.entity_id }}
{%- endif -%}
{%- endfor -%}
office_temperature:
friendly_name_template: "Office Temperatur"
value_template: >
{{ states.sensor.office.state |float + 2 |round(1) }}
unit_of_measurement: '°C'
waschmaschine_watts:
friendly_name_template: "{{ states.switch.waschmaschine.name}} Aktueller Verbrauch"
value_template: >
{% if states.switch.waschmaschine.attributes.current_power_w %}
{{ states.switch.waschmaschine.attributes["current_power_w"] | float }}
{% else %}
-1
{% endif %}
unit_of_measurement: 'W'
waschmaschine_today_kwh:
friendly_name_template: "{{ states.switch.waschmaschine.name}} heutiger Verbrauch"
value_template: >
{% if states.switch.waschmaschine.attributes.today_energy_kwh %}
{{ states.switch.waschmaschine.attributes["today_energy_kwh"] | float }}
{% else %}
-1
{% endif %}
unit_of_measurement: 'kWh'
trockner_watts:
friendly_name_template: "{{ states.switch.trockner.name}} Aktueller Verbrauch"
value_template: >
{% if states.switch.trockner.attributes.current_power_w %}
{{ states.switch.trockner.attributes["current_power_w"] | float }}
{% else %}
-1
{% endif %}
unit_of_measurement: 'W'
trockner_today_kwh:
friendly_name_template: "{{ states.switch.trockner.name}} heutiger Verbrauch"
value_template: >
{% if states.switch.trockner.attributes.today_energy_kwh %}
{{ states.switch.trockner.attributes["today_energy_kwh"] | float }}
{% else %}
-1
{% endif %}
unit_of_measurement: 'kWh'
outside_temperature:
friendly_name_template: "Außenttemperatur"
value_template: >
{% if states('input_select.weather_mode') == 'Netatmo' %}
{{ states('sensor.netatmo_imeerbus121_garten_temperature') }}
{% else %}
{{ states('sensor.yr_temperature') }}
{%- endif %}
unit_of_measurement: '°C'
outside_humidity:
friendly_name_template: "Luftfeuchtigkeit außen"
value_template: >
{% if states('input_select.weather_mode') == 'Netatmo' %}
{{ states('sensor.netatmo_imeerbus121_garten_humidity') }}
{% else %}
{{ states.sensor.yr_humidity.state }}
{%- endif %}
unit_of_measurement: '%'
outside_wind_speed:
friendly_name_template: "Windstärke"
value_template: >
{% if states('input_select.weather_mode') == 'Netatmo' %}
{{ states('sensor.netatmo_imeerbus121_wind_garten_wind_strength') }}
{% else %}
{{ (states('sensor.yr_wind_speed') |float * 3.6) |round(1) }}
{%- endif %}
unit_of_measurement: 'km/h'
outside_rain:
friendly_name_template: "Regen aktuell"
value_template: >
{% if states('input_select.weather_mode') == 'Netatmo' %}
{{ states('sensor.netatmo_imeerbus121_rs_garten_sum_rain_1') |float |round(2) }}
{% else %}
{{ states('sensor.yr_precipitation') }}
{%- endif %}
unit_of_measurement: 'mm'
outside_pressure:
friendly_name_template: "Luftdruck"
value_template: >
{% if states('input_select.weather_mode') == 'Netatmo' %}
{{ states('sensor.netatmo_imeerbus121_wohnzimmer_pressure') }}
{% else %}
{{ states('sensor.yr_pressure') }}
{%- endif %}
unit_of_measurement: 'hPa'
current_motion_location:
friendly_name_template: "Bewegung Ort"
value_template: >
{% if states('binary_sensor.presence_26') == 'on' %}
Wohnzimmer
{% elif states('binary_sensor.presence_35') == 'on' %}
Treppe oben
{% elif states('binary_sensor.presence_32') == 'on' %}
Treppe unten
{% elif states('binary_sensor.presence_29') == 'on' %}
Schlafzimmer
{% elif states('binary_sensor.presence_2') == 'on' %}
Office
{% elif states('binary_sensor.presence_5') == 'on' %}
'Gästezimmer'
{% elif states('binary_sensor.presence_8') == 'on' %}
Fitnessraum
{% else %}
ruhig
{%- endif %}
temperature_trend:
friendly_name: 'Temperatur Trend'
value_template: >
{% if states('binary_sensor.temp_rising') == 'on' %}
Up
{% elif states('binary_sensor.temp_falling') == 'on' %}
Down
{% else %}
stable
{% endif %}
Pirol_62
(Joerg)
February 24, 2020, 8:58am
7
and the relevant binary_sensors:
- platform: template
sensors:
all_lights_state:
value_template: >
{{ is_state('group.all_light_groups', 'on') }}
device_class: light
open_window:
value_template: >
{{ is_state('group.check_window', 'on') }}
device_class: door
washer_state:
value_template: >
{{ is_state('variable.washing_mode', 'on') }}
device_class: power
dryer_state:
value_template: >
{{ is_state('variable.dryer_mode', 'on') }}
device_class: power
notebook_joerg:
value_template: >
{{ is_state('device_tracker.pc19er', 'home') }}
device_class: connectivity
desktop_yvonne:
value_template: >
{{ is_state('device_tracker.desktop_gnesrek', 'home') }}
device_class: connectivity
homematic_online:
value_template: >
{{ states('sensor.access_point') |int > 1 or states('sensor.access_point') != 'unknown' }}
device_class: connectivity
netatmo_online:
value_template: >
{{ states('device_tracker.netatmo_personal_weather_station') == 'home' }}
device_class: connectivity
I see you are still using states.xxx.xxx notation in a lot of templates. Try changing all of them to the states(xxxx) notation as @MatthewFlamm suggested.
Pirol_62
(Joerg)
February 24, 2020, 9:33am
9
I found the bug!!!
In the end, you forced me, to check and change all templates in my automations.
I have 155 - puh…
There I found this one:
- id: '20012'
alias: Alert when a critical device goes offline
trigger:
- platform: state
entity_id: binary_sensor.homematic_online, binary_sensor.netatmo_online
from: 'Online'
to: 'Offline'
for:
minutes: 5
condition:
condition: and
conditions:
- condition: template
value_template: >
{% if states.automation.alert_when_a_critical_device_goes_offline.last_triggered is not none %}
{% if as_timestamp(now()) | int - as_timestamp(states.automation.alert_when_a_critical_device_goes_offline.attributes.last_triggered) | int > 3600 %} true {% else %} false
{% endif %}
{% else %}
false
{% endif %}
The trigger pointed to a sensor, which had to be renamed during my new installation of 105.3.
I changed the sensor to a binary one.
But I will change the notation of the other templates step by step I swear.
Thank you.
1 Like