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

@@ -219,20 +219,19 @@ variables:
helper_force_brightness: !input helper_force_brightness
helper_hold_delay: 0.1
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
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 }}"
remote_devices: !input remote_devices
remote_devices_names: "{{ remote_devices | map('device_attr', 'name') | list }}"
condition:
- 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:
- choose:
- conditions: