Skip to content

Commit

Permalink
(IKEA E1743) - Migrate to zigbee2mqtt MQTT device triggers (mqtt) (#661)
Browse files Browse the repository at this point in the history
* Added Support for zigbee2mqtt MQTT device triggers (mqtt)
Preserving backwards compatability with zigbee2mqtt legacy entity action events (sensor.<DEVICE>_action) (legacy)

* Cleaned up code

* bump blueprint version to 2025.01.10

* clean up comments

* prettier write

* update controller entity input description

* docs: add support for deprecated inputs

* docs: update input docs and changelog for ikea e1743

* more compact boolean tests in jinja templates

* reorder selectors, add blakadder source

* Cleaned up code and re-organized to use as base

* improve blueprint docs, add changelog link

* docs: add breaking change notice to changelog

* prettier: format

* Migrate to Zigbee2MQTT MQTT Device Triggers.

* Migrate to Zigbee2MQTT MQTT Device Triggers.

* Migrate to Zigbee2MQTT MQTT Device Triggers.

* Improved readability

* Migrate to Zigbee2MQTT MQTT Device Triggers.

* docs(ikea_e1743): update changelog, remove old input

* docs(ikea_e1743): bump version

---------

Co-authored-by: EPMatt <[email protected]>
  • Loading branch information
yarafie and EPMatt authored Jan 22, 2025
1 parent f7d899e commit 47b2f5c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 44 deletions.
99 changes: 65 additions & 34 deletions blueprints/controllers/ikea_e1743/ikea_e1743.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ blueprint:
Hooks allow to easily create controller-based automations for interacting with media players, lights, covers and more.
See the list of [Hooks available for this controller](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1743#available-hooks) for additional details.
📕 Full documentation regarding this blueprint is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1743).
## More Info
🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.
ℹ️ Version 2025.01.23
📝 [Changelog](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1743/#changelog)
📕 [Full documentation](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1743)
🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**. Please consider **[leaving a star on GitHub](https://github.com/EPMatt/awesome-ha-blueprints)**! 🌟
ℹ️ Version 2025.01.02
source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1743/ikea_e1743.yaml
domain: automation
homeassistant:
min_version: 2023.5.0
min_version: 2024.10.0
input:
integration:
name: (Required) Integration
Expand All @@ -31,18 +34,29 @@ blueprint:
- ZHA
- Zigbee2MQTT
controller_device:
name: (deCONZ, ZHA) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA.
name: (Required) (deCONZ, ZHA, Zigbee2MQTT) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA, Zigbee2MQTT.
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.
default: ''
selector:
entity:
domain: sensor
filter:
# source: https://www.zigbee2mqtt.io/devices/E1743.html#ikea-e1743
# source: https://zigbee.blakadder.com/Ikea_E1743.html
- integration: mqtt
manufacturer: IKEA
model: TRADFRI on/off switch
# For backwards compatibility with z2m 1.x. model_id is added to end of model rather than a seperate attribute in z2m 2.x
- integration: mqtt
manufacturer: IKEA
model: TRADFRI on/off switch (E1743)
# source: https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Supported-Devices
- integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
- integration: deconz
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
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 @@ -209,6 +223,7 @@ variables:
button_down_long: [move_1_83]
button_down_release: [stop]
zigbee2mqtt:
# source: https://www.zigbee2mqtt.io/devices/E1743.html#ikea-e1743
button_up_short: ['on']
button_up_long: [brightness_move_up]
button_up_release: [brightness_stop]
Expand All @@ -226,43 +241,59 @@ 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
controller_device: !input controller_device
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{controller_entity}}{% else %}{{controller_device}}{% endif %}'
controller_id: !input controller_device
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
# trigger for other integrations
- platform: event
triggers:
# triggers for zigbee2mqtt mqtt device action
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: 'on'
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: 'off'
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_move_up
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_move_down
- trigger: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_stop
# triggers for other integrations
- trigger: event
event_type:
- deconz_event
- zha_event
event_data:
device_id: !input controller_device
condition:
conditions:
- condition: and
conditions:
# check that the button event is not empty
- >-
{%- 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:
actions:
# 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
# if the delay expires and the automation is still running it means it's the last run and execution can continue
Expand All @@ -273,7 +304,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 All @@ -282,7 +313,7 @@ action:
trigger_delta: '{{ (as_timestamp(now()) - ((states(helper_last_controller_event) | from_json).t if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\":\".*\"|\"t\":\d+\.\d+)(,)?){2}\}$")) else as_timestamp("1970-01-01 00:00:00"))) * 1000 }}'
last_controller_event: '{{ (states(helper_last_controller_event) | from_json).a if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\":\".*\"|\"t\":\d+\.\d+)(,)?){2}\}$")) else "" }}'
# update helper
- service: input_text.set_value
- action: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
Expand All @@ -299,7 +330,7 @@ action:
- conditions: '{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_press_delay | int }}'
sequence:
# store the double press event in the last controller event helper
- service: input_text.set_value
- action: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
Expand Down Expand Up @@ -382,7 +413,7 @@ action:
- conditions: '{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_press_delay | int }}'
sequence:
# store the double press event in the last controller event helper
- service: input_text.set_value
- action: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
Expand Down
19 changes: 11 additions & 8 deletions website/docs/blueprints/controllers/ikea_e1743.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ This integration provides the entity which must be provided to the blueprint in
/>
<Input
name='Controller Device'
description='The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA.'
description='The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA, Zigbee2MQTT.'
selector='device'
required='deCONZ, ZHA'
/>
<Input
name='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.'
selector='entity'
required='Zigbee2MQTT'
required='deCONZ, ZHA, Zigbee2MQTT'
/>
<Input
name='Helper - Last Controller Event'
Expand Down Expand Up @@ -258,3 +252,12 @@ It's also important to note that the controller doesn't natively support double
- **2021-10-26**: Standardize blueprints structure and inputs naming across the whole collection. Improve blueprint documentation. No functionality change.
- **2022-08-08**: Optimize characters usage for the `helper_last_controller_event` text input.
- **2025-01-02**: Remove spaces to match new helper format in Home Assistant 2023.5.x. ([@LordSushiPhoenix](https://github.com/LordSushiPhoenix))
- **2025-01-23**:

:warning: **Breaking Change**:

Migrate to Zigbee2MQTT MQTT Device Triggers. ([@yarafie](https://github.com/yarafie))

The `controller_entity` input has been deprecated, and `controller_device` is now mandatory.
If you are a Zigbee2MQTT user and plan to update this blueprint, please make sure to remove the `controller_entity` input from your automation config and add the device ID of your controller to the `controller_device` input.
To obtain the device ID from your controller, configure the automation from the UI and use the device selector dropdown on the `controller_device` input to select your controller.
5 changes: 3 additions & 2 deletions website/src/components/blueprints_docs/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const styles = {
},
}

function Input({ selector, required, name, description }) {
function Input({ selector, required, name, description, deprecated }) {
const selectorVal = selector ? selectors[selector] : selectors.none
return (
<div>
Expand All @@ -62,7 +62,8 @@ function Input({ selector, required, name, description }) {
<Badge variant='warning'>{required} Required</Badge>
) : (
<Badge variant='info'>Optional</Badge>
)}
)}{' '}
{deprecated && <Badge variant='danger'>Deprecated</Badge>}
</span>
<br />
<p style={styles.inputDescription} className='margin-top--sm'>
Expand Down

0 comments on commit 47b2f5c

Please sign in to comment.