Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

zigbee2mqtt question #699

Answered by phsdv
phsdv asked this question in Q&A
Feb 16, 2025 · 2 comments · 4 replies
Discussion options

I switched my Zigbee system to zigbee2mqtt but have some questions on how to handle events from switches. I tried setting up a mqtt_trigger like this:

@mqtt_trigger('zigbee2mqtt/schakelaar_ouders_slaapkamer/action')
def handle_mqtt_message(**kwargs):
 log.warning(f"{kwargs}")

From the zigbee2mqtt logs I can see that the topic 'zigbee2mqtt/schakelaar_ouders_slaapkamer/action' changes when I click on the switch. However I keep getting errors like this:

2025年02月16日 11:03:35.174 ERROR (MainThread) [custom_components.pyscript] task_watchdog: got exception Traceback (most recent call last):
 File "/config/custom_components/pyscript/trigger.py", line 1020, in stop
 Mqtt.notify_del(self.mqtt_trigger[0], self.notify_q)
 ~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
 Mqtt.notify_del(self.mqtt_trigger[0], self.notify_q)
 ~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Am I missing something, or is this a bug? I am using HA 2025.2 and everything is updated to the latest version.

You must be logged in to vote

After rebooting home assistant the errors went away. I guess that pyscript did not load the mqtt libs after I installed mqtt. Only after a reboot that did happen.

Replies: 2 comments 4 replies

Comment options

try this one:

@mqtt_trigger('zigbee2mqtt/schakelaar_ouders_slaapkamer')
def handle_mqtt_message(**kwargs):
 log.warning(f"{kwargs}")
# and trigger to a certain type of action like so
@mqtt_trigger('zigbee2mqtt/schakelaar_ouders_slaapkamer', "payload_obj['action'] == 'single'")
def trigger_on_action_single(**kwargs):
 log.warning(f"action single")
You must be logged in to vote
3 replies
Comment options

Same error for both unfortunately.

Comment options

try listening to the topic and trigger the action.
https://community.home-assistant.io/t/how-to-listen-to-mqtt-topic-under-dev-tools/422762/2
maybe the payload comes empty.
I have no more ideas for now.

Comment options

I did that, the payload is 'on' or 'off', as it should

Comment options

After rebooting home assistant the errors went away. I guess that pyscript did not load the mqtt libs after I installed mqtt. Only after a reboot that did happen.

You must be logged in to vote
1 reply
Comment options

The following code is working for me:

@mqtt_trigger('zigbee2mqtt/schakelaar_ouders_slaapkamer/action')
def sw_slaapkamer(payload):
 if 'on' == payload:
 Ouders.on(circadian=True)
 if 'off' == payload:
 Ouders.off()
Answer selected by phsdv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /