Help needed with automation and json template warning

Hi all!
I have these automations (created about 3 months ago via web interface)

- id: '20210406174401'
  alias: SWITCH 1 - SINGOLO
  description: ''
  trigger:
  - platform: device
    domain: mqtt
    device_id: 145b5920014fcf022d0383fe02450fb8
    type: action
    subtype: single
    discovery_id: 0x00158d00066f963e action_single
  condition: []
  action:
  - service: light.turn_on
    target:
      entity_id: light.01107f
  mode: single
- id: '20210406174400'
  alias: SWITCH 1 - DOPPIO
  description: ''
  trigger:
  - platform: device
    domain: mqtt
    device_id: 145b5920014fcf022d0383fe02450fb8
    type: action
    subtype: double
    discovery_id: 0x00158d00066f963e action_double
  condition: []
  action:
  - service: light.turn_off
    target:
      entity_id: light.01107f
  mode: single

Device is a Xiaomi WXKG11LM 1 button, connected via Zigbee2Mqtt.

From 2021.04.0 I have these warning in logs:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1335
First occurred: 10:59:46 (2 occurrences)
Last logged: 10:59:46

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

How can I fix them? Thank you

Wait for the update of Zigbee2MQTT :slight_smile: In the mean time, just ignore them, they are only warnings.

1 Like

Same problem here. But I noticed a certain delay on the device because of that.

Logger: homeassistant.helpers.template
Source: helpers/template.py:1335
First occurred: 3:42:07 (16 occurrences)
Last logged: 3:42:16

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

Got the same but related to the upgrade to 2021.4.3.
The error seems to be exactly the same, same place in template.py, but a template I’ve done myself. The template has been working for a couple of years (until upgrade to 2021.4.3). The issue occurs every 30 seconds. I dunno if there are relations, but my HA installation seems to crash once a day. It cannot fetch data for my integrations (e.g. Miele, REST, Uhomeupnor, basically everything). Think that error is related to some sort of overflow of all the ‘dict object’ warnings… but that’s just a guess.
My exact error is just like yours:

2021-04-13 19:44:45 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'sonnen' when rendering '{{ value_json.sonnen }}'

For kicks my template is here:

  #PV panels (Sonnen)
  - platform: rest
    name: JSON sonnen
    json_attributes:
      - Consumption_W
      - GridFeedIn_W
      - Production_W
      - USOC
    resource: http://<redacted>/api/v1/status
    value_template: '{{ value_json.sonnen }}'
  - platform: template
    sensors:
      sonnen_consumption:
        friendly_name: 'Consumption W'
        value_template: '{{ states.sensor.json_sonnen.attributes["Consumption_W"] }}'
        unit_of_measurement: W
      sonnen_gridfeedin:
        friendly_name: 'Grid feed-in W'
        value_template: '{{ states.sensor.json_sonnen.attributes["GridFeedIn_W"] }}'
        unit_of_measurement: W
      sonnen_production:
        friendly_name: 'Production W'
        value_template: '{{ states.sensor.json_sonnen.attributes["Production_W"] }}'
        unit_of_measurement: W
      sonnen_usoc:
        friendly_name: 'State of Charge %'
        value_template: '{{ states.sensor.json_sonnen.attributes["USOC"] }}'
        unit_of_measurement: "%"

Hope someones looks at this issue :slight_smile: Thanks

I use Home assistant with Zigbee2mqtt-AddOn
Current version: 1.18.2-1

I got following Warnings in Homeasistant Log:

...

2021-04-14 09:24:35 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'linkquality' when rendering '{{ value_json.linkquality }}'
2021-04-14 09:24:36 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'linkquality' when rendering '{{ value_json.linkquality }}'
2021-04-14 09:24:43 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'requested_brightness_level' when rendering '{{ value_json.requested_brightness_level }}'
2021-04-14 09:24:43 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'requested_brightness_percent' when rendering '{{ value_json.requested_brightness_percent }}'
...

They are throwing with different variables (equested_brightness_percent,requested_brightness_level ,linkquality etc.)
They were starting after update to:
core-2021.4.4

I guess, Hassio changed exception handling.
I had an if/else Block, which worked up to core-2021.4.4. Then it throws same Warning

        {% if  trigger.event.data.room  %}
            {{ trigger.event.data.room }}
        {% else %}
            {{ trigger.event.data._intent.siteId }}
        {% endif %} 

I changed it to:

        {% if  trigger.event.data.room is defined  %}
            {{ trigger.event.data.room }}
        {% else %}
            {{ trigger.event.data._intent.siteId }}
        {% endif %}

That works and no warning any more
I guess, after core-2021.4.4, all variables needs to be checked.
I hoped that helps

Hmmm. Changed
value_template: '{{ value_json.sonnen }}'
to
value_template: 'OK'

Seems to have removed the errors from the log at least. I hope it also brings back stability…

This is covered in the breaking changes and it even provides a solution. Check out the template section in breaking changes.

value_template: '{{ value_json.sonnen | default }}'

I saw that, but I have no clue where to look to fix this. If I look at my log I see this as an example:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1335 
First occurred: 1:26:44 PM (55 occurrences) 
Last logged: 1:48:05 PM

Template variable warning: 'dict object' has no attribute 'led_indication' when rendering '{{ value_json.led_indication }}'
Template variable warning: 'dict object' has no attribute 'energy' when rendering '{{ value_json.energy }}'
Template variable warning: 'dict object' has no attribute 'temperature' when rendering '{{ value_json.temperature }}'
Template variable warning: 'dict object' has no attribute 'voltage' when rendering '{{ value_json.voltage }}'
Template variable warning: 'dict object' has no attribute 'current' when rendering '{{ value_json.current }}'

This does not tell what entity is reporting the error, so I have no clue where to go and fix it. My guess is, that this is Zigbee2mqtt entity or entities but I have many entities reporting temperature, and voltage as an example.

It’s all handled on the zigbee2mqtt side’s discovery. I don’t know how that works, so I can’t help you.

I can add to this discussion that in my case I’ve scoured all my files (config, automations, sensors, etc.) and cannot find some templates mentionned in the logs…
All the templates I use I have corrected using default value, but there seems to be some entities defined elsewhere (inside plugins ?).
Do we have to wait for the developpers of every plugins to fix them ?

Yes, if they are provided by MQTT discovery and you didn’t manually configure them.

For me, it is caused by Zigbee entities. Zigbee2mqtt.

When I press or hold a button on an IKEA switch:

When power on/off IKEA power outlet: