MQTT - Dict Object has no attribute

Following this as my logs are filling up with these as well

2021-06-03 15:20:27 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'click' when rendering '{{ value_json.click }}'
2021-06-03 15:20:27 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'action' when rendering '{{ value_json.action }}'
2021-06-03 15:21:48 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:23:10 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:23:10 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:23:10 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:23:20 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:29:14 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:29:38 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:32:19 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'click' when rendering '{{ value_json.click }}'
2021-06-03 15:32:19 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'action' when rendering '{{ value_json.action }}'
2021-06-03 15:35:13 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:37:00 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:42:05 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:43:39 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:48:29 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:51:02 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:55:20 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 15:56:14 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 16:02:42 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 16:03:04 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 16:09:03 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
2021-06-03 16:09:36 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'click' when rendering '{{ value_json.click }}'

Hi everyone, I have just updated my Core to 2021.6.4 and zigbee2mqtt to 1.19.1-1. These are the latest version as of now. And I’m getting similar error flooding the log and seems as of now, we don’t have any solution to resolve this, right?

Please advise.

Logger: homeassistant.helpers.template
Source: helpers/template.py:1366
First occurred: 10:54:12 AM (617 occurrences)
Last logged: 3:25:27 PM

Template variable warning: 'dict object' has no attribute 'linkquality' when rendering '{{ value_json.linkquality }}'
Template variable warning: 'dict object' has no attribute 'power_outage_memory' when rendering '{{ value_json.power_outage_memory }}'
Template variable warning: 'dict object' has no attribute 'temperature' when rendering '{{ value_json.temperature }}'
Template variable warning: 'dict object' has no attribute 'update_available' when rendering '{{ value_json.update_available}}'
Template variable warning: 'dict object' has no attribute 'click' when rendering '{{ value_json.click }}'

Assuming it is expected that those attributes are missing from the json sometimes, you could do, e.g.,

{% if "linkquality" in value_json %}
  {{ value_json.linkquality }}
{% else %}
  0
{% endif %}

May i know where can i define the condition to set some default values?

I know those errors are generated from zigbee2mqtt as some attributes are null values. But not sure if we can set some dummy values for those attributes because the zigbee2mqtt are doing the broadcast.

Heh?

Those lines replace

{{ value_json.linkquality }}

What you do in case those attributes are missing (i.e. the “0” part) is up to you

Hi, I understood the condition. But should I create an automation for that? Or script? Or something else?

I don’t get it.

You are obviously using the {{ value_json.linkquality }} template somewhere. Replace it with the lines above, which are also a template, just more elaborate.

e.g.

value_template: {{ value_json.linkquality }}

value_template: >-
  {% if "linkquality" in value_json %}
    {{ value_json.linkquality }}
  {% else %}
    0
  {% endif %}
1 Like

No…no… I’m not using it. It was the zigbee2mqtt…some of the devices are broadcasting a null attributes and cause the HA capture this as warning.

Oh, the MQTT discovery part?
Yeah, Z2T issue, then.

Can someone help me out on supprression this warning? I have no idea. Thank you.

error:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1366
First occurred: June 26, 2021, 8:18:48 PM (57 occurrences)
Last logged: 5:30:30 AM

Template variable warning: 'dict object' has no attribute '6/28/2021' when rendering '{% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true ) %} {% set holiday = value_json.MAJOR_JP.static[ today ] %} {% if holiday | trim == "" %} {% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year %} {% set holiday = value_json.MAJOR_JP.dynamic[ today ] %} {% endif %} {{ holiday }}'
Template variable warning: 'dict object' has no attribute '7/08/2021' when rendering '{% set today = as_timestamp(now() + timedelta(days = 11))|timestamp_custom('%-m/%d/%Y', true ) %} {% set delivery = "" %} {% if delivery | trim == "" %} {% set delivery = value_json.MAJOR_JP.jcb[ today ] %} {% endif %} {{ delivery }}'
Template variable warning: 'dict object' has no attribute '7/04' when rendering '{% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) %} {% set holiday = value_json.MAJOR_JP.static[ today ] %} {% if holiday | trim == "" %} {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year %} {% set holiday = value_json.MAJOR_JP.dynamic[ today ] %} {% endif %} {{ holiday }}'
Template variable warning: 'dict object' has no attribute '7/04/2021' when rendering '{% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) %} {% set holiday = value_json.MAJOR_JP.static[ today ] %} {% if holiday | trim == "" %} {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year %} {% set holiday = value_json.MAJOR_JP.dynamic[ today ] %} {% endif %} {{ holiday }}'
Template variable warning: 'dict object' has no attribute 'click' when rendering '{{ value_json.click }}'

sensor:

  - platform: command_line
    name: Holidaytomorrow
    command: 'cat /config/www/data/days.json'
    value_template: >
      {% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true )  %}
      {% set holiday =  value_json.MAJOR_JP.static[ today ] %}
      {% if holiday | trim == "" %}
        {% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year  %}
        {% set holiday =  value_json.MAJOR_JP.dynamic[ today ] %}
      {% endif %}
      {{ holiday }}
    scan_interval: 14400

  - platform: command_line
    name: Holidayinaweek
    command: 'cat /config/www/data/days.json'
    value_template: >
      {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true )  %}
      {% set holiday =  value_json.MAJOR_JP.static[ today ] %}
      {% if holiday | trim == "" %}
        {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year  %}
        {% set holiday =  value_json.MAJOR_JP.dynamic[ today ] %}
      {% endif %}
      {{ holiday }}
    scan_interval: 14400

You’re trying to access an element of your dict without checking if the key exists.
If it doesn’t, you get the warning
Rather than the above, do something like

{% if today in value_json.MAJOR_JP.static %}

Hi. I am getting this error now.

error:

Template variable warning: 'holiday' is undefined when rendering '{% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) %} {% if today in value_json.MAJOR_JP.static %} {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year %} {% set holiday = value_json.MAJOR_JP.dynamic[ today ] %} {% endif %} {{ holiday }}'

sensor:

  - platform: command_line
    name: Holidayinaweek
    command: 'cat /config/www/data/days.json'
    value_template: >
      {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true )  %}
      {% if today in value_json.MAJOR_JP.static %}
        {% set today = as_timestamp(now() + timedelta(days = 7))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year  %}
        {% set holiday =  value_json.MAJOR_JP.dynamic[ today ] %}
      {% endif %}
      {{ holiday }}
    scan_interval: 14400

You using it while not initialized.
Use set holiday = '' or whatver before the if.

ok. sorry. I have edit for the following and it looks like the original error has came back.

sensor:

  - platform: command_line
    name: Holidaytomorrow
    command: 'cat /config/www/data/days.json'
    value_template: >
      {% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true )  %}
      {% set holiday = '' %}
      {% if today in value_json.MAJOR_JP.static %}
        {% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year  %}
        {% set holiday =  value_json.MAJOR_JP.dynamic[ today ] %}
      {% endif %}
      {{ holiday }}
    scan_interval: 14400

Error:

Template variable warning: 'dict object' has no attribute '6/28/2021' when rendering '{% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true ) %} {% set holiday = '' %} {% if today in value_json.MAJOR_JP.static %} {% set today = as_timestamp(now() + timedelta(days = 1))|timestamp_custom('%-m/%d', true ) ~ '/' ~ now().year %} {% set holiday = value_json.MAJOR_JP.dynamic[ today ] %} {% endif %} {{ holiday }}'

Same problem here:

2021-07-13 14:03:40 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: ‘dict object’ has no attribute ‘click’ when rendering ‘{{ value_json.click }}’

2021-07-13 14:03:40 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: ‘dict object’ has no attribute ‘action’ when rendering ‘{{ value_json.action }}’

Im using a WXKG02LM with zigbee2mqtt

Same error but not related to Z2M. I followed this ‘tutorial’ to switch the screen on/off from my tablet: Fully Kiosk Browser
Since this is configured, and it works great, I have below error:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1779
First occurred: 10:25:10 AM (75 occurrences)
Last logged: 11:03:11 AM

Template variable warning: 'dict object' has no attribute 'isScreenOn' when rendering '{{ value_json.isScreenOn }}'

According the tutorial my sensors.yaml contains:

  - platform: rest
    name: foo
    json_attributes:
      - batteryLevel
      - kioskMode
      - screenBrightness
      - motionDetectorState
      - maintenanceMode
      - appFreeMemory
      - appUsedMemory
      - totalFreeMemory
      - totalUsedMemory
      - startUrl
      - currentPage
    resource: !secret foo_rest
    value_template: '{{ value_json.isScreenOn }}'

I want to get red of this error but don’t know how

Same problem (not Z2M). It’s happening with several sensors from a raspberry pi monitor plugin I have:

2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'clock_speed' when rendering '{{value_json.clock_speed}}'
2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'load_1m' when rendering '{{value_json.load_1m}}'
2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'load_5m' when rendering '{{value_json.load_5m}}'
2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'load_15m' when rendering '{{value_json.load_15m}}'
2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'net_tx' when rendering '{{value_json.net_tx}}'
2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'net_rx' when rendering '{{value_json.net_rx}}'
2022-01-03 12:42:26 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'wifi_ssid' when rendering '{{value_json.wifi_ssid}}'
etc...

The same for me…

I used this GitHub - Sennevds/system_sensors: Logging of system sensor specific for the RPI and sending them to a MQTT broker for monitor other rpi.

I started the script with load_1m, load_5m and load_15m monitor and all worked.
Then, i removed this 3 sensors, and started to log this error:


2022-03-13 00:58:53 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'load_1m' when rendering '{{value_json.load_1m}}'
2022-03-13 00:58:53 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'load_5m' when rendering '{{value_json.load_5m}}'
2022-03-13 00:58:53 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'load_15m' when rendering '{{value_json.load_15m}}'

I think that MQTT has them saved somewhere… or not?

1 Like

I have a Tekelek sonic tank level monitor (Tek 766) connected over LoRaWAN and delivering payloads via MQTT into Home Assistant.

It send updates every 6 hours or so (which is configurable) however sending the battery state is not as easily configurable to synchronise with the level payloads.

This means that sometimes the Battery reading is not there and then these errors occur. This manifests in the UI where the battery percentage goes from it real reading (83%) to 0%.

Is there no way in Home Assistant that the battery sensor simply does not update when there is no reading? I don’t mind the errors in the logs, it is the resulting inaccurate readings that is the trouble…

I hope that it will help some of you but this is how I had it working in my case (Zigbee Bridge from Sonoff flashed with Tasmota):

mqtt:
  sensor:
    - state_topic: "tele/tasmota_F1234F/SENSOR"
      name: "Bedroom_Temperature"
      device_class: temperature
      value_template: "{% if value_json['ZbReceived']['0x123A'].Temperature is defined %} {{ value_json['ZbReceived']['0x123A'].Temperature }} {% else %} {{ state('sensor.Bedroom_Temperature') }} {% endif %}"
      unit_of_measurement: "°C"
    - state_topic: "tele/tasmota_F1234F/SENSOR"
      name: "Bedroom_Humidity"
      device_class: humidity
      value_template: "{% if value_json['ZbReceived']['0x123A'].Humidity is defined %} {{ value_json['ZbReceived']['0x123A'].Humidity }} {% else %} {{ state('sensor.Bedroom_Humidity') }} {% endif %}"
      unit_of_measurement: "%"

In my case my Zigbee sensors return only one value at a time, either ‘Temperature’ or ‘Humidity’, but inside the exact same JSON topic from my bridge, and when I had one the other was always reset inside HA.
Here I use “is defined” to check the presence of the value and set the current state if it’s not defined, this way when I get ‘Humidity’ it doesn’t reset the ‘Temperature’ value to “unknown” :slight_smile:

Here are two example topics I got from my bridge (to explain the issue):

tele/tasmota_F1234F/SENSOR = {"ZbReceived":{"0x123A":{"Device":"0x123A","Name":"Bedroom_Sensor","Temperature":19.77,"Endpoint":1,"LinkQuality":58}}}
tele/tasmota_F1234F/SENSOR = {"ZbReceived":{"0x123A":{"Device":"0x123A","Name":"Bedroom_Sensor","Humidity":60.48,"Endpoint":1,"LinkQuality":52}}}

My solution is based on the following pages:

1 Like