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.

Have you tried the blueprint from nick ? It should not throw any warning at startup as it is not based on mqtt trigger.

I did modify a bit this blueprint in order to get button 1 and 3 / 2 and 4 working as well.

PTM215Z.

Hey @chris-1243 , thank you very much! I didn’t know the Blueprint yet. I’ll try it or yours gladly, if I get the chance. Maybe when the weather gets uncomfortable again, at the moment Smart Home configuration is in pause mode. :wink:

Hi. @chris-1243 I haven’t forgotten you and as announced, I did think recently about testing your blueprint. And as fate would have it, I’ve now stumbled upon the following:

Looks like we’ve got a lot of work ahead of us and you’re already heavily involved. I appreciate your effort. I’ll wait a bit longer with the testing. Maybe you’ll find a way to implement your blueprint with the event integration once it’s integrated into z2m.

It would be great if you could keep me updated on this. Thank you in advance. :wave:

@alexsaas As you saw already, I will try to keep those blueprints updated as much as I can. I am still waiting for the change to become available in order to test and see what have to be edited.

By the time and as, like you, I wanted to suppress those warnings in my log, I created an other blueprint which listens to mqtt. I removed the need of the elapsed function to be used as well. No warning anymore or tricks required at least on my system.

My goal is to get a blueprint working via a mqtt trigger and an other one via the event bus when feasible. Let me know if you want to have a try.

My github repo is not up-to-date for the moment as I am still in a test phase.

1 Like

@alexsaas

The blueprint based on mqtt should be available here

If you want to try feel free. It would normally be completely usable with Z2M 2.0… I disabled the legacy action sensor on my setup and it was perfectly working

One important point. As I used the latest syntax available, your Homeassistant needs to run version 2024.10.x or above

1 Like

Hey @chris-1243 Excuse me, I’ve only just seen that you’ve answered. First of all, I would like to thank you for your commitment and work. I really appreciate that.

Yes, it’s a bit frustrating right now that you don’t know how to test it yet:

This sounds good:

Is the following and removing the elapsed function essential for your new blueprint to run? Because I would then have to switch other automations as well:

The « elapsed » function is just not needed anymore.
For testing, there is no need to change anything in Z2M settings. This function is an option in Z2M not in HA. You may keep your automations running based on the @vandalon blueprint. :wink:

You have then two options (always do a backup first!):

  1. Edit one automation based on the original blueprint.

    • Open it;
    • Click on the three dots in the right corner;
    • Choose « edit in YAML »
      Modify the path to point to my blueprint. (I kept all the basic information like @vandalon did in order to move from on to another easily).
  2. Create or duplicate one running automation and use my blueprint to check if everything is fine on your side.

EDIT: I just saw two minor errors in the description in press 2 and 4 hold and release. You may either download again the blueprint or suppress « is »…

1 Like

Thank you for the clarification and the guidance. That sounds really simple. A dream when it works out so easily. I’ll test it and get back to you with feedback.

Found 1 small typo error:

Thanks!!! Copy/paste error done via my smartphone. It is corrected already

:clap:t2: Whoohoo great work @chris-1243
Your blueprint works as promised, with no discernible difference. Wonderful, no more warnings in the log! Thank you very much!

Welcome…

I might update it in a short period of time as there is an optional template which is not correctly passed… it works but still a minor issue to solve