fix: improve remote device identification for MQTT triggers (#23)

* fix: improve remote device identification for MQTT triggers

* chore: move mqtt topic variable

* fix: correct formatting in remote_devices_names variable
This commit is contained in:
Damien
2025-03-07 09:01:15 +01:00
committed by GitHub
parent 4904d063da
commit ef0961d554
2 changed files with 18 additions and 20 deletions

View File

@@ -307,21 +307,20 @@ triggers:
payload: 2_long_release payload: 2_long_release
id: release-hold-dots2-z2m-e2213 id: release-hold-dots2-z2m-e2213
variables: variables:
is_mqtt: "{{ trigger.platform == 'mqtt' }}"
is_zha: "{{ trigger.platform == 'event' and trigger.event.event_type == 'zha_event' }}"
mqtt_topic: "{{ trigger.topic }}"
on_double_press_exposed: !input on_double_press_exposed on_double_press_exposed: !input on_double_press_exposed
off_double_press_exposed: !input off_double_press_exposed off_double_press_exposed: !input off_double_press_exposed
remote_devices: !input remote_devices remote_devices: !input remote_devices
remote_device: >- remote_devices_names: "{{ remote_devices | map('device_attr', 'name') | list }}"
{% set is_zha = trigger.platform == "event" and trigger.event.event_type == "zha_event" %}
{% set is_mqtt = trigger.platform == "mqtt" %}
{% set device_name = trigger.topic.split("/")[1] if is_mqtt else none %}
{{
(trigger.event.data.device_id if is_zha) or
(device_id(trigger.topic.split("/")[1]) if is_mqtt and device_name)
}}
mqtt_topic: "{{ trigger.topic }}"
condition: condition:
- condition: template - condition: template
value_template: "{{ remote_device in remote_devices }}" value_template: >-
{{
(trigger.event.data.device_id in remote_devices if is_zha) or
(trigger.topic.split('/')[1] in remote_devices_names if is_mqtt)
}}
actions: actions:
- choose: - choose:
- conditions: - conditions:

View File

@@ -219,20 +219,19 @@ variables:
helper_force_brightness: !input helper_force_brightness helper_force_brightness: !input helper_force_brightness
helper_hold_delay: 0.1 helper_hold_delay: 0.1
helper_hold_dim_step: 4 helper_hold_dim_step: 4
is_mqtt: "{{ trigger.platform == 'mqtt' }}"
is_zha: "{{ trigger.platform == 'event' and trigger.event.event_type == 'zha_event' }}"
light: !input light light: !input light
remote_devices: !input remote_devices
remote_device: >-
{% set is_zha = trigger.platform == "event" and trigger.event.event_type == "zha_event" %}
{% set is_mqtt = trigger.platform == "mqtt" %}
{% set device_name = trigger.topic.split("/")[1] if is_mqtt else none %}
{{
(trigger.event.data.device_id if is_zha) or
(device_id(trigger.topic.split("/")[1]) if is_mqtt and device_name)
}}
mqtt_topic: "{{ trigger.topic }}" mqtt_topic: "{{ trigger.topic }}"
remote_devices: !input remote_devices
remote_devices_names: "{{ remote_devices | map('device_attr', 'name') | list }}"
condition: condition:
- condition: template - condition: template
value_template: "{{ remote_device in remote_devices }}" value_template: >-
{{
(trigger.event.data.device_id in remote_devices if is_zha) or
(trigger.topic.split('/')[1] in remote_devices_names if is_mqtt)
}}
actions: actions:
- choose: - choose:
- conditions: - conditions: