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.
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.
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.
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.)
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.
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.
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
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'
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.
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.
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.
@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.
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
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.
You have then two options (always do a backup first!):
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).
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 »…
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.
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!