-
Notifications
You must be signed in to change notification settings - Fork 58
-
I need some help.
I’m trying to change my pyscript so that it doesn’t use the click sensors that was removed in Zigbee2MQTT 2.0.0.
With "legacy_action_sensor: true" enabled in Zigbee2MQTT everything it’s working as intended.
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?
My f-string must be wrong but I haven't been able to figure out the correct way.
configurations.yaml
pyscript:
apps:
wall_switch_action:
- switch_id: Home Office Wall Switch
button: left
- switch_id: Home Office Wall Switch
button: right
Beta Was this translation helpful? Give feedback.
All reactions
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['bu...
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.