Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support mqtt based triggers #33

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d04e2f4
Updated IKEA E1743 TRÅDFRI On/Off Switch & Dimmer controller to use m…
yarafie Dec 19, 2024
61218f4
Updated for zigbee2mqtt v2.0.0 mqtt triggers
yarafie Dec 20, 2024
a83ae8b
Fixed misplaced commments
yarafie Dec 20, 2024
ee39837
Optimized code
yarafie Dec 21, 2024
1cc8738
Updated for zigbee2mqtt v2.0.0 mqtt triggers
yarafie Dec 21, 2024
1cdd662
Updated for Zigbee2MQTT_V2
yarafie Dec 21, 2024
6fac99a
Update ikea_e2001_e2002.yaml
LewisSpring Dec 22, 2024
22249aa
Updated for Zigbee2MQTT_V2
yarafie Dec 21, 2024
cf2e607
Merge branch 'main' of github.com:yarafie/awesome-ha-blueprints
yarafie Dec 22, 2024
487f9c3
Fixed zha selector
yarafie Dec 22, 2024
4cf4cc6
Added manufacturer and model for deconz selector.
yarafie Dec 22, 2024
5ad4ef4
Added manufacturer and model for deconz selector
yarafie Dec 22, 2024
d673a00
Added Manufacturer and Model for input selectors
yarafie Dec 22, 2024
16a8107
Added Manufacturer and model to selector
yarafie Dec 22, 2024
1b27c6a
Added manufacturer and model to selector
yarafie Dec 22, 2024
e1d84c7
Added manufacturer and model to selector
yarafie Dec 22, 2024
03e9b56
Added manufacturer and model to selector
yarafie Dec 22, 2024
a7e2958
Fixed indentation in ikea_e1744.yaml
yarafie Jan 2, 2025
104bf96
Merge branch 'main' into main
LewisSpring Jan 2, 2025
6ef7783
Update philips_324131092621.yaml
LewisSpring Jan 2, 2025
4325a9b
Update remaining Osram, Philips and Xiaomi blueprints. Phew!
LewisSpring Jan 2, 2025
b4219ca
Added last_controller_rvent checks where applicable
yarafie Jan 4, 2025
395129b
Fix Xiaomi indentation. Thanks @hvorragend
LewisSpring Jan 4, 2025
d1d35b8
Merge branch 'main' into main
LewisSpring Jan 4, 2025
aa3aff3
Fixed trigger in ikea_e1766.yaml
yarafie Jan 5, 2025
98c6b02
modified: philips_324131092621.yaml Fixed triggers subtype for zigb…
yarafie Jan 5, 2025
e399f69
Remove HA Minimum Version
LewisSpring Jan 5, 2025
5cb27a9
Added Support for zigbee2mqtt mqtt device triggers when legacy=false
yarafie Jan 7, 2025
a32bc18
Added Support for zigbee2mqtt mqtt device triggers when legacy=false
yarafie Jan 7, 2025
a6e680d
fixed z2m_legacy= code
yarafie Jan 7, 2025
13ddef2
Fixed check if event is relative to a real state change
yarafie Jan 7, 2025
f3f2898
Updated version
yarafie Jan 7, 2025
966c495
Minor Changes
yarafie Jan 7, 2025
e7274cc
Updated all with new zigbee2mqtt logic preserving legacy
yarafie Jan 8, 2025
c5267b6
Starting all comments in code from column 2
yarafie Jan 8, 2025
d4aa5d5
Adding space after # for comments
yarafie Jan 8, 2025
933e114
Prettier - Enforce code style
yarafie Jan 8, 2025
5d33257
github-actions: bump creyD/prettier_action from 4.2 to 4.3 (#523)
dependabot[bot] Jan 5, 2025
6db3765
npm-website: bump @docusaurus/core from 2.0.1 to 2.3.1 in /website (#…
dependabot[bot] Jan 5, 2025
8d6161d
npm-website: bump http-cache-semantics from 4.1.0 to 4.1.1 in /websit…
dependabot[bot] Jan 5, 2025
491dc37
github-actions: bump reviewdog/action-eslint from 1.17 to 1.18 (#525)
dependabot[bot] Jan 5, 2025
0fdcb24
npm-website: bump eslint from 8.21.0 to 8.35.0 in /website (#526)
dependabot[bot] Jan 5, 2025
afaef6e
npm-website: bump eslint-config-prettier from 8.5.0 to 8.7.0 in /webs…
dependabot[bot] Jan 5, 2025
6bf81bb
npm-website: bump loader-utils from 2.0.2 to 2.0.4 in /website (#449)
dependabot[bot] Jan 5, 2025
a190446
github-actions: bump s0/git-publish-subdir-action from 2.5.1 to 2.6.0…
dependabot[bot] Jan 5, 2025
a7b91c9
npm-website: bump react-bootstrap-icons from 1.8.4 to 1.10.2 in /webs…
dependabot[bot] Jan 5, 2025
088e219
github-actions: bump dessant/lock-threads from 3 to 4 (#458)
dependabot[bot] Jan 5, 2025
23db247
npm-website: bump body-parser and express in /website (#633)
dependabot[bot] Jan 5, 2025
cca2af1
npm-website: bump prettier from 2.7.1 to 2.8.4 in /website (#513)
dependabot[bot] Jan 5, 2025
0f7600e
npm-website: bump @sideway/formula from 3.0.0 to 3.0.1 in /website (#…
dependabot[bot] Jan 5, 2025
c7a4e58
npm-website: bump cross-spawn from 7.0.3 to 7.0.6 in /website (#626)
dependabot[bot] Jan 5, 2025
029c326
github-actions: bump actions/cache from 3.0.6 to 3.2.6 (#524)
dependabot[bot] Jan 5, 2025
baa0c64
npm-website: bump ua-parser-js from 0.7.31 to 0.7.33 in /website (#498)
dependabot[bot] Jan 5, 2025
fe6af3e
github-actions: bump actions/stale from 5 to 7 (#473)
dependabot[bot] Jan 5, 2025
7894c4a
npm: bump prettier from 2.7.1 to 2.8.4 (#512)
dependabot[bot] Jan 5, 2025
cb68275
npm-website: bump json5 in /website (#635)
dependabot[bot] Jan 5, 2025
e122a9c
npm-website: bump webpack from 5.73.0 to 5.97.1 in /website (#637)
dependabot[bot] Jan 5, 2025
eacef43
npm-website: bump micromatch from 4.0.5 to 4.0.8 in /website (#636)
dependabot[bot] Jan 5, 2025
a7df02f
npm-website: bump nanoid from 3.3.4 to 3.3.8 in /website (#628)
dependabot[bot] Jan 5, 2025
b6a5f4b
npm-website: bump http-proxy-middleware from 2.0.6 to 2.0.7 in /websi…
dependabot[bot] Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 112 additions & 9 deletions blueprints/controllers/ikea_e1524_e1810/ikea_e1524_e1810.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Blueprint metadata
blueprint:
domain: automation
homeassistant:
min_version: 2023.6.0
LewisSpring marked this conversation as resolved.
Show resolved Hide resolved
name: Controller - IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote
description: |
# Controller - IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote

Controller automation for executing any kind of action triggered by the provided IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote. Allows to optionally loop an action on a button long press.
Supports deCONZ, ZHA, Zigbee2MQTT.
Supports deCONZ, ZHA, Zigbee2MQTT and Zigbee2MQTT_V2 with legacy=false.

Automations created with this blueprint can be connected with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks) supported by this controller.
Hooks allow to easily create controller-based automations for interacting with media players, lights, covers and more.
Expand All @@ -15,12 +18,9 @@ blueprint:

🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.

ℹ️ Version 2025.01.03-EPMATT
source_url: https://github.com/lsismeiro/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1524_e1810/ikea_e1524_e1810.yaml
ℹ️ Version 2025-01-01

domain: automation
homeassistant:
min_version: 2023.5.0
source_url: https://github.com/lsismeiro/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1524_e1810/ikea_e1524_e1810.yaml
input:
integration:
name: (Required) Integration
Expand All @@ -31,12 +31,24 @@ blueprint:
- deCONZ
- ZHA
- Zigbee2MQTT
- Zigbee2MQTT_V2
yarafie marked this conversation as resolved.
Show resolved Hide resolved
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: (deCONZ, ZHA, Zigbee2MQTT_V2) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA, Zigbee2MQTT_V2.
yarafie marked this conversation as resolved.
Show resolved Hide resolved
default: ''
selector:
device:
filter:
- integration: mqtt
manufacturer: IKEA
model: TRADFRI remote control (E1524/E1810)
- integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI remote control
- integration: deconz
manufacturer: IKEA of Sweden
model: TRADFRI remote control
multiple: false
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.
Expand Down Expand Up @@ -367,6 +379,21 @@ variables:
button_down_release: [brightness_down_release]
button_center_short: [toggle]
button_center_long: [toggle_hold]
zigbee2mqtt_v2:
button_left_short: [arrow_left_click]
button_left_long: [arrow_left_hold]
button_left_release: [arrow_left_release]
button_right_short: [arrow_right_click]
button_right_long: [arrow_right_hold]
button_right_release: [arrow_right_release]
button_up_short: [brightness_up_click]
button_up_long: [brightness_up_hold]
button_up_release: [brightness_up_release]
button_down_short: [brightness_down_click]
button_down_long: [brightness_down_hold]
button_down_release: [brightness_down_release]
button_center_short: [toggle]
button_center_long: [toggle_hold]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_left_short: '{{ actions_mapping[integration_id]["button_left_short"] }}'
Expand All @@ -384,7 +411,7 @@ variables:
button_center_short: '{{ actions_mapping[integration_id]["button_center_short"] }}'
button_center_long: '{{ actions_mapping[integration_id]["button_center_long"] }}'
# integrations which need to store the previous press event to determine which button was released
integrations_with_prev_event_storage: [zha]
integrations_with_prev_event_storage: [zha, zigbee2mqtt, zigbee2mqtt_v2]
# build data to send within a controller event
controller_entity: !input controller_entity
controller_device: !input controller_device
Expand All @@ -397,6 +424,77 @@ trigger:
event_type: state_changed
event_data:
entity_id: !input controller_entity
# triggers for zigbee2mqtt_v2
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: arrow_left_click
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: arrow_left_hold
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: arrow_left_release
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: arrow_right_click
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: arrow_right_hold
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: arrow_right_release
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_up_click
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_up_hold
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_up_release
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_down_click
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_down_hold
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_down_release
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: toggle
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: toggle_hold
# trigger for other integrations
- platform: event
event_type:
Expand All @@ -412,6 +510,8 @@ condition:
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "zigbee2mqtt_v2" -%}
{{ trigger.payload }}
yarafie marked this conversation as resolved.
Show resolved Hide resolved
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
Expand All @@ -422,6 +522,7 @@ condition:
# 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 }}'
- '{{ integration_id != "zigbee2mqtt_v2" or trigger.payload != last_controller_event }}'
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 @@ -434,6 +535,8 @@ action:
trigger_action: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "zigbee2mqtt_v2" -%}
{{ trigger.payload }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
Expand Down
85 changes: 76 additions & 9 deletions blueprints/controllers/ikea_e1743/ikea_e1743.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Blueprint metadata
blueprint:
domain: automation
homeassistant:
min_version: "2023.6.0"
min_version: 2023.6.0
name: Controller - IKEA E1743 TRÅDFRI On/Off Switch & Dimmer
#YAR - CHANGED Supports deCONZ, ZHA, Zigbee2MQTT.
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
description: |
# Controller - IKEA E1743 TRÅDFRI On/Off Switch & Dimmer

Controller automation for executing any kind of action triggered by the provided IKEA E1743 TRÅDFRI On/Off Switch & Dimmer. Allows to optionally loop an action on a button long press.
Supports deCONZ, ZHA, Zigbee2MQTT.
Supports deCONZ, ZHA, Zigbee2MQTT and Zigbee2MQTT_V2 with legacy=false.

Automations created with this blueprint can be connected with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks) supported by this controller.
Hooks allow to easily create controller-based automations for interacting with media players, lights, covers and more.
Expand All @@ -17,11 +20,10 @@ blueprint:

🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.

ℹ️ Version 2023.10.05
ℹ️ Version 2025-01-01

#YAR - ADD END
source_url: https://github.com/lsismeiro/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1743/ikea_e1743.yaml
domain: automation
homeassistant:
min_version: 2023.5.0
input:
integration:
name: (Required) Integration
Expand All @@ -32,12 +34,26 @@ blueprint:
- deCONZ
- ZHA
- Zigbee2MQTT
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
- Zigbee2MQTT_V2
#YAR - ADD END
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: (deCONZ, ZHA, Zigbee2MQTT_V2) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA, Zigbee2MQTT_V2.
default: ''
selector:
device:
filter:
- integration: mqtt
manufacturer: IKEA
model: TRADFRI on/off switch (E1743)
- integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
- integration: deconz
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
multiple: false
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.
Expand Down Expand Up @@ -217,6 +233,15 @@ variables:
button_down_short: ['off']
button_down_long: [brightness_move_down]
button_down_release: [brightness_stop]
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
zigbee2mqtt_v2:
button_up_short: ['on']
button_up_long: [brightness_move_up]
button_up_release: [brightness_stop]
button_down_short: ['off']
button_down_long: [brightness_move_down]
button_down_release: [brightness_stop]
#YAR - ADD END
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_up_short: '{{ actions_mapping[integration_id]["button_up_short"] }}'
Expand All @@ -226,7 +251,10 @@ variables:
button_down_long: '{{ actions_mapping[integration_id]["button_down_long"] }}'
button_down_release: '{{ actions_mapping[integration_id]["button_down_release"] }}'
# integrations which need to store the previous press event to determine which button was released
integrations_with_prev_event_storage: [zha, zigbee2mqtt]
#YAR - CHANGED integrations_with_prev_event_storage: [zha, zigbee2mqtt]
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
integrations_with_prev_event_storage: [zha, zigbee2mqtt, zigbee2mqtt_v2]
#YAR - ADD END
# build data to send within a controller event
controller_entity: !input controller_entity
controller_device: !input controller_device
Expand All @@ -239,6 +267,34 @@ trigger:
event_type: state_changed
event_data:
entity_id: !input controller_entity
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
# triggers for zigbee2mqtt_V2
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: 'on'
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: 'off'
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_move_up
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_move_down
- platform: device
domain: mqtt
device_id: !input controller_device
type: action
subtype: brightness_stop
#YAR - ADD END
# trigger for other integrations
- platform: event
event_type:
Expand All @@ -250,20 +306,27 @@ condition:
- condition: and
conditions:
# check that the button event is not empty
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
- >-
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "zigbee2mqtt_v2" -%}
{{ 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"] }}
#YAR - ADD END
# only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
yarafie marked this conversation as resolved.
Show resolved Hide resolved
# 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 }}'
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
- '{{ integration_id != "zigbee2mqtt_v2" or trigger.payload != last_controller_event }}'
#YAR - ADD END
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 @@ -273,14 +336,18 @@ action:
# extract button event from the trigger
# provide a single string value to check against
- variables:
#YAR - ADD - To Support Zigbee2MQTT_V2 with legacy=false
trigger_action: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "zigbee2mqtt_v2" -%}
{{ 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 -%}
#YAR - ADD END
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
Expand Down
Loading