Warning after reboot. TypeError: argument of type 'NoneType' is not iterable

As a supplement, as requested by @Troon , here is the YAML of an automation that uses this blueprint. I changed the names and freindly names of devices, scenes, etc. for this. The automation works as desired. As a test, I also created a simple automation with this blueprint, in which only one button triggers a light.turn_on and I deactivated all other automations = error message still remains after system restart. So I think it’s not the automation, but the blueprint.

- id: '1706641054316'
  alias: MyAutomationName
  description: ''
  use_blueprint:
    path: custom/z2m_-_switch_foh_enocean_ptm215z_vandalon.yaml
    input:
      controller: NameOfMySwitch
      button_2_pressed:
      - choose:
        - conditions:
          - condition: device
            type: is_off
            device_id: f2e1e6c4492a18281b527f101ac60f87
            entity_id: 437d653d063aaa35f3c8764197636412
            domain: light
          sequence:
          - service: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.MyScene1
        - conditions:
          - condition: device
            type: is_on
            device_id: f2e1e6c4492a18281b527f101ac60f87
            entity_id: 437d653d063aaa35f3c8764197636412
            domain: light
          sequence:
          - type: turn_off
            device_id: f2e1e6c4492a18281b527f101ac60f87
            entity_id: 437d653d063aaa35f3c8764197636412
            domain: light
      button_4_pressed:
      - choose:
        - conditions:
          - condition: device
            type: is_off
            device_id: 29539fe0af9e029a4b5685b4e8092f3a
            entity_id: ca8e008aa62aeaf183b5ead3006b56a1
            domain: light
          sequence:
          - service: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.MyScene2
        - conditions:
          - condition: device
            type: is_on
            device_id: 29539fe0af9e029a4b5685b4e8092f3a
            entity_id: ca8e008aa62aeaf183b5ead3006b56a1
            domain: light
          sequence:
          - type: turn_off
            device_id: 29539fe0af9e029a4b5685b4e8092f3a
            entity_id: ca8e008aa62aeaf183b5ead3006b56a1
            domain: light
      button_2_held:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice1/set
          payload: '{"brightness_move": -51}'
      button_2_released:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice1/set
          payload: '{"brightness_move": "stop"}'
      button_4_held:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice2/set
          payload: '{"brightness_move": -51}'
      button_4_released:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice2/set
          payload: '{"brightness_move": "stop"}'
      button_1_held:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice1/set
          payload: '{"brightness_move": 51}'
      button_1_released:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice1/set
          payload: '{"brightness_move": "stop"}'
      button_3_pressed: []
      button_3_released:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice2/set
          payload: '{"brightness_move": "stop"}'
      button_3_held:
      - service: mqtt.publish
        metadata: {}
        data:
          qos: '0'
          retain: false
          topic: zigbee2mqtt/MyLightDevice2/set
          payload: '{"brightness_move": 51}'

I did explain what is happening. The HA restart triggers the device online response. Since this blueprint triggers every time the base topic is sent, it triggers this, but there is no actions data, so the log gets spammed.

So you need to supply a default state, which we were trying to do, or change the trigger to trigger only when there is a change to the action part of the topic. To do that you have to see what the responses are when the actions happen and adjust the trigger so it works when it is supposed to and not when it’s not. This is something the author should do, but if you want to contribute, that’s cool. Their stuff is in a gist and not a repo so it’s really hard to contribute, but that is not my battle.

Good luck, and let us know questions as you progress.

@Sir_Goodenough

Thank you very much for the detailed explanation. Since English is not my mother tongue, I have to read and understand the answer in peace first. But I think it will be very time-consuming and painful. I’ll keep you posted.

I have a half quick’n’dirty solution In the meantime, I have built an automation that deactivates the relevant automations after a restart and, after z2m is available again, waits a bit and then reactivates them. It takes a while after z2m until the PTM 215z have reported for the first time. (I’ve studied the logbook.) :wink:

It works and the warning messages no longer appear. I know this is not the best solution, actually something like this should be integrated into the blueprint somehow. But currently, I don’t know how to do that.

If you’re interested, I could post the YAML of this automation here.

1 Like

Hi. I (hopefully for the last time) return to the topic.

I found a better (maybe the right) solution for me. The previous solution with the additional automation was not entirely satisfactory for me. But now I have found a way to edit the blueprint so that the error messages in question no longer appear.

I have supplemented the relevant section of the blueprint with another condition (in front of the existing one). This is what it looks like now:

condition:
  - condition: template
    value_template: >-
      {{ as_timestamp(now()) - as_timestamp(states.binary_sensor.zigbee2mqtt_bridge_connection_state.last_changed) | int > 30 }}
  - condition: template
    value_template: >-
      {{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) 
      or 'press_' in trigger.payload_json.action }}

This ensures that the blueprint/automation is only rendered when the connection z2m (for example after a system restart) has already existed for 30 seconds. If it takes longer in the future due to further integrations, you can quickly change the value in the blueprint.

It’s actually quite easy if you know what you need to change and how. That took me a while. But now I’m happy. :slightly_smiling_face:

It looks like an OK work around but not a fix. For instance if you are working on a new sensor that requires HA reboot and doesn’t have an easy button to reset it, and you have to restart more often that 30 minutes, etc.

If you want to improve on this, I can help, just let me know.

update:

I looked at some of my Z2M stuff which is I think is what you are using, and leaving the original alone except changing the trigger to this just might ‘fix’ your problem…
from

trigger:
  - platform: mqtt
    topic: "{{ base_topic ~ '/' ~ controller }}"

to

trigger:
  - platform: mqtt
    topic: "{{ base_topic ~ '/' ~ controller ~ '/action' }}"

This should only trigger when an action is sent, not with availability or battery level or whatever else is going on is sent. HA is complaining when there is a trigger anytime there is no action statement. Until an action is generated, it will spam errors after the time delay even.

You would have to test it. If it works I would bother the original author until they add those 12 characters and fix if for everyone…

Hi. I have tested it. Unfortunately, the automations no longer work and I have even more error messages in the log:

2024-02-04 19:48:20.441 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:48:20.441 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation1':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:48:20.598 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:48:20.598 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation1':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:48:23.312 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:48:23.312 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation1':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:48:23.581 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:48:23.581 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation1':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:57:31.571 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:57:31.571 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation2':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:57:31.696 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:57:31.696 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation2':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:57:33.348 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:57:33.348 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation2':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'
2024-02-04 19:57:33.518 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'payload_json' when rendering '{{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined) or 'press_' in trigger.payload_json.action }}'
2024-02-04 19:57:33.518 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'MyAutomation2':
In 'condition':
In 'template' condition: UndefinedError: 'dict object' has no attribute 'payload_json'

So I undid it again.

Thanks for trying. I was sure I had it…

It’s my turn to say thank you for continuing to try to help me.

But I don’t understand the following part of your comment:

It looks like an OK work around but not a fix. For instance if you are working on a new sensor that requires HA reboot and doesn’t have an easy button to reset it, and you have to restart more often that 30 minutes, etc.

My fix or workaround is only integrated into this blueprint and only two automations for two of these enOcean wall switches use this blueprint. And my addition only tells the blueprint that it only works when the Zigbee network has been running for at least 30 seconds. So it’s not clear to me how another sensor (that you mentioned) could be affected by this?

As I understand it, no other Zigbee devices should be affected by this.