-
| I need some help. So now I'm trying to use the @mqtt_trigger and I can get it to work for a single switch/lamp combination but I can’t figure out what the correct f-string should look like when using the YAML configuration to start several instantiations. So, @mqtt_trigger('zigbee2mqtt/Home Office Wall Switch', "payload_obj['action'] == 'right_press'")`
@mqtt_trigger('zigbee2mqtt/Home Office Wall Switch', "payload_obj['action'] == 'right_press_release'")
@mqtt_trigger('zigbee2mqtt/Home Office Wall Switch', "payload_obj['action'] == 'right_hold'")
@mqtt_trigger('zigbee2mqtt/Home Office Wall Switch', "payload_obj['action'] == 'right_hold_release'")
def handle_mqtt_message(**kwargs):
    log.info(f"zigbee2mqtt/Home Office Wall Switch right button. kwargs == {kwargs}")works. But how do I get import asyncio
registered_triggers = []
def make_wall_switch_action(config):
    action_q = asyncio.Queue(10)
    # handles the switch action and adds it to the queue.
    @mqtt_trigger(f"'zigbee2mqtt/{config['switch_id']}', \"payload_obj['action'] == '{config['button']}_press'\"")
    @mqtt_trigger(f"'zigbee2mqtt/{config['switch_id']}', \"payload_obj['action'] == '{config['button']}_press_release'\"")
    @mqtt_trigger(f"'zigbee2mqtt/{config['switch_id']}', \"payload_obj['action'] == '{config['button']}_hold'\"")
    @mqtt_trigger(f"'zigbee2mqtt/{config['switch_id']}', \"payload_obj['action'] == '{config['button']}_hold_release'\"")
    def wall_switch_action(**kwargs):
        log.info(f"zigbee2mqtt/{config['switch_id']} {config['button']} button. kwargs == {kwargs}")
@time_trigger("startup")
def wall_switch_action_startup():
    log.info("wall switch action startup.")
    for app in pyscript.app_config:
        log.info(f"wall switch action startup. app = {app}")
        make_wall_switch_action(app)to play ball? configurations.yaml  | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| And I’m an idiot…. When I reduced the scope of the function then I forgot to add the trigger     # register it in the global scope so pyscript sees it.
    registered_triggers.append(wall_switch_action)And the correct (or at least working) configuration is:     @mqtt_trigger(f"zigbee2mqtt/{config['switch_id']}", f"payload_obj['action'] == '{config['button']}_press'")
    @mqtt_trigger(f"zigbee2mqtt/{config['switch_id']}", f"payload_obj['action'] == '{config['button']}_press_release'")
    @mqtt_trigger(f"zigbee2mqtt/{config['switch_id']}", f"payload_obj['action'] == '{config['button']}_hold'")
    @mqtt_trigger(f"zigbee2mqtt/{config['switch_id']}", f"payload_obj['action'] == '{config['button']}_hold_release'") | 
Beta Was this translation helpful? Give feedback.
And I’m an idiot….
When I reduced the scope of the function then I forgot to add the trigger
And the correct (or at least working) configuration is: