Error message every minute

Hi All,

I am getting the below error message every minute. It seemed to start a few days ago after I had some dramas with my HA server crashing. The error was there with 0.78.3 and remains after upgrading to 0.80.2 this morning. Running HassIO on HassOS.

018-10-18 13:13:47 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi_aqara is taking over 10 seconds.
2018-10-18 13:14:06 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: ‘mappingproxy object’ has no attribute ‘timestamp’
2018-10-18 13:14:14 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-10-18 13:15:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: ‘mappingproxy object’ has no attribute ‘timestamp’
2018-10-18 13:16:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: ‘mappingproxy object’ has no attribute ‘timestamp’
2018-10-18 13:17:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: ‘mappingproxy object’ has no attribute ‘timestamp’

Any ideas what this could be? It doesnt seem to point to anything specific.

sounds like you have an automation that runs every minute that’s not formatted correctly. It is good enough to pass the syntax check but not good enough to work…

As far as I can remember I don’t have any automations that are set to run every minute, plus I haven’t created any new ones at the time that this started happening.

can you check your logbook and see if you find something that would change around the same time? Maybe it’s a template sensor that updates once a min ?

the logbook doesnt show an event every minute. There are times where many minutes go by (even an hour) without an entry, yet the error is logged every minute

based on the error referring to a ‘template condition’ I just looked through my automations and the below seems to be the only one with a template in the condition section.

alias: Alarm auto arm
initial_state: 'on'
trigger:
  - platform: state
    entity_id: binary_sensor.passage_multi_sensor_sensor
    to: 'off'
    for:
      minutes: 45
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: device_tracker.davess7lan
      state: 'not_home'
    - condition: state
      entity_id: device_tracker.rowess7lan
      state: 'not_home'
    - condition: template
      value_template: '{{as_timestamp(now()) - as_timestamp(states.binary_sensor.kitchen_multi_sensor_sensor.last_changed) > 1800 }}'
    - condition: template
      value_template: '{{as_timestamp(now()) - as_timestamp(states.binary_sensor.lounge_multisensor_sensor.last_changed) > 1800 }}'
    - condition: template
      value_template: '{{as_timestamp(now()) - as_timestamp(states.binary_sensor.master_bedroom_multisensor_sensor.last_changed) > 1800 }}'
    - condition: template
      value_template: '{{as_timestamp(now()) - as_timestamp(states.binary_sensor.motion_sensor_158d0001ad43db.last_changed) > 1800 }}'
action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.kitchen
      volume_level: '0.90'
  - service: tts.google_say
    entity_id: media_player.kitchen
    data:
      message: 'Arming house alarm in one minute'
  - delay: '00:00:30'
  - service: alarm_control_panel.alarm_arm_away
    entity_id: alarm_control_panel.house
  - service: media_player.volume_set
    data:
      entity_id: media_player.kitchen
      volume_level: '0.50'

does that look like it has an error in it? I have stayed away from templates for the most part because I’m still trying to work them out

Can you try and replace
as_timestamp(states.binary_sensor.kitchen_multi_sensor_sensor.last_changed)
with
(as_timestamp(states.binary_sensor.master_bedroom_multisensor_sensor.last_changed | default(0))) | int
this will ensure that should you have no data for one of your sensors (yet) it won’t throw an error message

would I need to do the same for all 4 of them in the automation?

I also tried turning off that automation but the errors still persisted

yes you would. and if the automation is off and it still pops up then it’s not this one.
Still a good thing to have to avoid future errors (I’m in the process of doing this for all my automations)
Not sure what else could be generating this error message, as it does look like it’s a condition related one from an automation. Sorry…

You’re looking in the wrong place. Do you have a template sensor that acts as an alarm clock? The templates you just posted aren’t using the timestamp attribute. If I recall correctly, the only states object that has that attribute is in the input_datetime domain.

You just reminded me that I have automations inside packages that I hadn’t checked for templates. Perhaps one of these is causing the issue?

part of my alarm clock package:

automation:
  alias: 'bedroom light on and play music'
  initial_state: 'on'  
  trigger:
    platform: template
    value_template: '{{ states.sensor.time.state == (states.input_datetime.bedroom_alarm_clock_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'
  condition:


condition:
  - condition: template
    value_template: "{{ now().date() == states('input_datetime.rent_inspection_date') }}"

This is a snippet from another package:

action:
  - wait_template: "{{ is_state('sensor.time', 'input_datetime.rent_inspection_start_time') }}"
  - service: alarm_control_panel.alarm_disarm

I’m wondering if it is the second one listed above as it didnt seem to work when I ran a test on it

after playing around by turning off automations I have tracked the error down to the Alarm Clock package. This previously did not create errors before I upgraded to 0.78.3. could someone please help me fix the issue in the above alarm clock code?

The easiest way to troubleshoot templates is by putting them in the template editor and seeing if they return the value you are expecting…

I figured it out. Due to a HA server crash last week I didn’t have a value set for the alarm clock input_datetime. I have now entered a value and it seems to be happy

It’s definitely this template:

    value_template: '{{ states.sensor.time.state == (states.input_datetime.bedroom_alarm_clock_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'

That fires every minute.

So, if you do this for that template, it will never happen again. Even after a server crash:

    value_template: >
      {% if states.input_datetime.bedroom_alarm_clock_time.attributes.timestamp is defined %}
        {{ states.sensor.time.state == (states.input_datetime.bedroom_alarm_clock_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}
      {% else %}
        False
      {% endif %}
1 Like

awesome! thank you so much

hi all
i think i have something similar…
i get this error:

Error rendering data template: UndefinedError: ‘mappingproxy object’ has no attribute ‘volume_level’

and after seeing this post. i think it’s this code, can someone tell me what i need to change?

  • alias: Set Home Cinema Main Slider Position
    initial_state: ‘on’
    trigger:

    • platform: state
      entity_id: media_player.receiver
      condition:
    • condition: template
      value_template: “{{ not is_state_attr(‘media_player.receiver’, ‘volume_level’, states(‘input_number.living_room’) | int / 100) }}”
      action:
    • service: input_number.set_value
      entity_id: input_number.living_room
      data_template:
      value: “{{ trigger.to_state.attributes.volume_level | multiply(100) | int }}”
  • alias: Set Home Cinema Main Volume
    trigger:

    • platform: state
      entity_id: input_number.living_room
      condition:
    • condition: template
      value_template: “{{ not is_state_attr(‘media_player.receiver’, ‘volume_level’, states(‘input_number.living_room’) | int / 100) }}”
      action:
    • service: media_player.volume_set
      entity_id: media_player.receiver

It’s most likely this line:

value: "{{ trigger.to_state.attributes.volume_level | multiply(100) | int }}"

if you change that to pull directly from the entity_id instead of the trigger object, you won’t get that error. That error shouldn’t appear anyways because the trigger.to_state.attributes should always have volume_level. So something else is causeing that to trigger, probably on startup. So you could ignore the error. But anyways, the 2 ways to fix it are:

value: "{{ state_attr('media_player.receiver', 'volume_level') | multiply(100) | int }}"

or if you still want to use trigger

action:
  - condition: template
    value_template: "{{ 'volume_level' in trigger.to_state.attributes }}"
  - service: input_number.set_value
    data_template:
      entity_id: input_number.living_room
      value: "{{ trigger.to_state.attributes.volume_level | multiply(100) | int }}"

Thank you! This cleared 6 errors I had in my log :grinning:

Hi.
I’m having a similar problem.
Every minute I get:

2020-02-16 21:18:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:19:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:20:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:21:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:22:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:23:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:24:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:25:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:26:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:27:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:28:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
2020-02-16 21:29:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'

I spent the whole sunday looking for a fix, but I didn’t find the cause yet.
In logbook I can’t see anything triggering each minute.
I tried to exclude some packges and i tried to follow every suggestion found by googling, but the error is still there.
I really don’t how to find where the problem is.
I tried to apply this to some templates:

this is a templating error and it’s basically saying that HA cannot find attributes in an empty object.

So you need to look through all your templates in which you use  `states.<entity_id>.attributes.<attr>`  . One of those is giving you problems. And the problem is, that  `<entity_id>`  is bad or the component has not set it up yet.

typically you can prevent this in templates by adding an if statement wrapped around your object:

Copy to clipboard

{% if states.device.domain %}
{{ states.device.domain.attributes.attr }}
{% else %}
Unknown
{% endif %}

But the problem did not go away.
I checked all my automation to find if I used a template in some condition.
I searched in all yaml file for “.attributes.” and I commented or put an if condition in al recurrencies.

Can someone help me in finding where the problem is?
Thank you very much.