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

After every reboot HA shows this warning:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:1020
Integration: Automatisierung (documentation, issues)
First occurred: 07:40:34 (2 occurrences)
Last logged: 07:40:34

Error evaluating condition in 'NameOfMyAutomation1': In 'condition': In 'template' condition: TypeError: argument of type 'NoneType' is not iterable
Error evaluating condition in 'NameOfMyAutomation2': In 'condition': In 'template' condition: TypeError: argument of type 'NoneType' is not iterable

I use this blueprint https://gist.github.com/vandalon/d2a327297d579b304549e96c66765992 for automate my EnOcean PTM 215z switches. The automations works as well, but warnings still there.

I think it‘s a problem at startup, when something isn‘t soon available at HAs start.

Maybe i found out that the error could be in this section of the blueprint:

condition:
  - condition: template
    value_template: >
      {{
        ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined)
        or 'press_' in trigger.payload_json.action
      }}

I have no idea how to fix it. Could anyone please help me?

This ought to do it.

condition:
  - condition: template
    value_template: >
      {% if trigger.payload_json is defined %}
        {{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined)
           or 'press_' in trigger.payload_json.action }}
      {% else %}
        false
      {% endif %}

Wow! Thanks for the very quick answer. It was probably a good idea that I asked here.

Unfortunately I won’t be able to test it for another 3-4 hours and then report back. So far, thank you very much. It would be great if it solved the problem. I’ve been searching for hours and haven’t found a solution.

Sorry but I’m a bit anxious. But the else false doesn’t affect the rest of the blueprint or automation, does it?

All it does is test whether trigger.payload_json is valid each time the automation is triggered, before trying to do the lookup that is causing your error. If it isn’t, the automation will not run on that occasion.

If you want it run anyway, change the false to true.

Thanks again.

It’s not that we misunderstand each other. The warning message did not appear when the automation was triggered! The automation ran without errors. The warning message only appeared every time Home Assistant was fully restarted or shut down and started.
It’s as if Home Assistant loaded the blueprints or automations once when it started and then discovered that the value was missing. Maybe because zigbee2MQTT hasn’t started yet and therefore no value can be determined?

Yeah, I understood that. That’s what my addition checks for: whether a value can be determined. If it can’t, either do nothing (false) or run anyway (true), the choice is yours.

Okay thank you very much. Please bear with me. This is all still a bit new for me.

I’ll try true and then false later and report back. Unfortunately I can’t test it at the moment. I was just afraid that the automation wouldn’t even run if it was set to false. I’ll see it later.

To be clear, it will trigger as before. The condition block contains optional tests to decide whether the automation should proceed once triggered.

It’s entirely your choice how you want to handle the startup condition where it appears to trigger but not have a JSON payload to work with.

Looking at the rest of the blueprint, the action: block depends on that payload, so I’d suggest using false in the condition, otherwise the error is just going to be created by the next step.

Ah okay. Now I think I understand it. Then I’ll better try with false and then I’ll quickly find out whether something fails. Thank you for your time with my problem!

@alexsaas Alexsaas:

condition:
  - condition: template
    value_template: >
      {% if trigger.payload_json is defined %}
        {{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined)
           or 'press_' in trigger.payload_json.action }}
      {% else %}
        false
      {% endif %}

I would suggest this code be passed back to the author in the form of an issue (start-up spamming the error log) and a suggest fix (above).

Then this would be fixed for everyone…

Unfortunately, I have to report that the suggested solution didn’t help. The exact same warning is displayed. I also disabled the previous automations and created a completely new one with the corrected blueprint. Unfortunately the warning remains after a full system reboot.

@Sir_Goodenough

Good idea, I already thought of that and sent the author of the blueprint a message with a link to this topic using the message function. Let’s see if he reacts. But unfortunately the solution doesn’t work.

You need to remove the property… since it won’t be defined either at startup.

condition:
  - condition: template
    value_template: >
      {% if trigger is defined %}
        {{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined)
        or 'press_' in trigger.payload_json.action }}
      {% else %}
        false
      {% endif %}
1 Like

@Didgeridrew

Oh it’s so frustrating! Unfortunately your solution doesn’t work either. The warning message is exactly the same.

BTW @Troon @Didgeridrew a question about indentation in the following line:
or ‘press_’ in trigger.payload_json.action }}
there are only 11 spaces before or. Does that matter? Studio Code Server highlights this location in red. But I also tried with 12 spaces. This changes nothing.

Maybe we are all looking in the wrong place in the blueprint? But actually the warning message already refers to this section, right?

Could you post the YAML for the automation as it exists on your system?

Trigger has to be defined, because it has to trigger to get there at all. The trigger is anything that happens in the topic, so this is likely being triggered by the online availability at startup.

I’m thinking maybe:

      {% if trigger.payload_json.action is defined %}
        {{ ('release_' in trigger.payload_json.action and trigger.payload_json.elapsed is defined)
        or 'press_' in trigger.payload_json.action }}
      {% else %}
        false
      {% endif %}

If that doesn’t work, tightening the trigger a bit to only allow trigger in a payload change instead of any change to the topic would be the better move possibly.
You would have to study the triggers to see what you can narrow it to for this, but that is what I would do.

1 Like

OP can’t reply for a bit due to new user throttling.

I don’t do DM’s.
I’ll wait for a reply here or not to respond.
It doesn’t really matter, though. The owner of the BP needs to fix this or take the thing down. Noone wants the software they download to spam the logs.
Ans personally I put about as much time into this as I care to today.

Sorry, I’m now able to leave a reply again after I was blocked by forum software.

Unfortunately, all the solutions shown here do not eliminate this warning message in the logs. The automations that use this blueprint run as desired and without errors.

I guess I need to dig deeper into template and scripting of Home Assistant. I think the message appears because at the Home Assistant startup the entities or zigbee2MQTT or MQTT broker is not ready yet, while Home Assistant reloads the automations after startup. I think this is where I have to start. I just don’t know how yet.

I would definitely like to thank everyone here who has spent so much time with my problem. I appreciate that.