Skip to content

Commit

Permalink
Add MQTT Device
Browse files Browse the repository at this point in the history
Leverage HA 2024.2 support for direct MQTT device triggers
  • Loading branch information
robvanoostenrijk authored Feb 23, 2024
1 parent 9ee5920 commit fe11d1b
Showing 1 changed file with 73 additions and 18 deletions.
91 changes: 73 additions & 18 deletions blueprints/controllers/ikea_e2001_e2002/ikea_e2001_e2002.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ blueprint:
🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.
ℹ️ Version 2022.08.08
ℹ️ Version 2024.02.23
source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e2001_e2002/ikea_e2001_e2002.yaml
domain: automation
input:
Expand All @@ -34,13 +34,15 @@ blueprint:
default: ''
selector:
device:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation. Choose a value only if the remote is integrated with Zigbee2MQTT.
mqtt_device:
name: (Zigbee2MQTT) MQTT Device
description: The MQTT device to use for the automation. Choose a value only if the remote is integrated with Zigbee2MQTT.
default: ''
selector:
entity:
domain: sensor
device:
manufacturer: IKEA
model: STYRBAR remote control (E2001/E2002)
multiple: false
helper_last_controller_event:
name: (Required) Helper - Last Controller Event
description: Input Text used to store the last event fired by the controller. You will need to manually create a text input entity for this, please read the blueprint Additional Notes for more info.
Expand Down Expand Up @@ -350,17 +352,73 @@ variables:
# integrations which need to store the previous press event to determine which button was released
integrations_with_prev_event_storage: [zha, zigbee2mqtt]
# build data to send within a controller event
controller_entity: !input controller_entity
mqtt_device: !input mqtt_device
controller_device: !input controller_device
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{controller_entity}}{% else %}{{controller_device}}{% endif %}'
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{mqtt_device}}{% else %}{{controller_device}}{% endif %}'
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
# triggers for zigbee2mqtt
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "arrow_left_click"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "arrow_left_hold"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "arrow_left_release"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "arrow_right_click"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "arrow_right_hold"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "arrow_right_release"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "on"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "brightness_move_up"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "brightness_stop"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "off"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "brightness_move_down"
- platform: device
domain: mqtt
device_id: !input mqtt_device
type: action
subtype: "brightness_stop"
# trigger for other integrations
- platform: event
event_type:
Expand All @@ -375,17 +433,14 @@ condition:
- >-
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{{ trigger.payload }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
# only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
# this is required since multiple state_changed events are fired for a single button press, with the result of the automation being triggered multiple times
- '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'
action:
# debouncing - when automation is triggered multiple times, the last automation run is the one which completes execution, due to mode restart
# therefore previous runs must wait for the debounce delay before executing any other action
Expand All @@ -397,7 +452,7 @@ action:
- variables:
trigger_action: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{{ trigger.payload }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
Expand Down

0 comments on commit fe11d1b

Please sign in to comment.