-
Notifications
You must be signed in to change notification settings - Fork 58
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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")
Beta Was this translation helpful? Give feedback.
All reactions
-
Same error for both unfortunately.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
I did that, the payload is 'on' or 'off', as it should
Beta Was this translation helpful? Give feedback.
All reactions
-
😕 1
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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()
Beta Was this translation helpful? Give feedback.