Files
ha-blueprints/ikea_E1743-E2201-E2213_ZHA-Z2M_control-light.yaml
Damien 02935e6ad6 feat: allow multiple remotes (#17)
* feat!: allow multiple remotes

* doc: add fancy emojis

* fix: press-dots2-z2m-e2213

* chore: add PR labeling and changelog template
2025-02-05 09:57:52 +01:00

324 lines
9.8 KiB
YAML

blueprint:
homeassistant:
min_version: 2024.10.0
author: damru
domain: automation
name: Ikea's Tradfri, Rodret or Somrig 💡 Light control
description: >
## 💡 Control a light with **IKEA TRADFRI ON/OFF** or ***IKEA RODRET** or **IKEA SOMRIG** remotes
Only for use with [ZHA](https://www.home-assistant.io/integrations/zha/)
or Zigbee2MQTT (cf [MQTT](https://www.home-assistant.io/integrations/mqtt)
+ [Z2M addon](https://www.zigbee2mqtt.io/guide/installation/03_ha_addon.html)).
Available controls:
- Press **on** (Tradfri, Rodret) or **1 dot** (Somrig) to turn on the light
(Optional: set the target brightness by enabling **Force Brightness** and setting a **Brightness** value)
- Press **off** (Tradfri, Rodret) or **2 dots** (Somrig) to turn off the light
- Hold **on** (Tradfri, Rodret) or **1 dot** (Somrig) button to increase the brightness
- Hold **off** (Tradfri, Rodret) or **2 dots** (Somrig) button to decrease the brightness down to 1%
input:
remote_devices:
name: Remotes
description: >
IKEA remote (Tradfri, Rodret, Somrig) to use.
default: ""
selector:
device:
filter:
- integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
- integration: zha
manufacturer: IKEA of Sweden
model: RODRET Dimmer
- integration: zha
manufacturer: IKEA of Sweden
model: SOMRIG shortcut button
- integration: mqtt
manufacturer: IKEA
model: TRADFRI on/off switch
- integration: mqtt
manufacturer: IKEA
model: RODRET wireless dimmer/power switch
- integration: mqtt
manufacturer: IKEA
model: SOMRIG shortcut button
# DEPRECATED - for removal, keeping for z2m v1 backward compatibility
- integration: mqtt
manufacturer: IKEA
model: TRADFRI on/off switch (E1743)
# DEPRECATED - for removal, keeping for z2m v1 backward compatibility
- integration: mqtt
manufacturer: IKEA
model: RODRET wireless dimmer/power switch (E2201)
# DEPRECATED - for removal, keeping for z2m v1 backward compatibility
- integration: mqtt
manufacturer: IKEA
model: SOMRIG shortcut button (E2213)
multiple: true
light:
name: Light
description: Light to control
selector:
entity:
filter:
domain: light
multiple: false
brightness_section:
name: Brightness
icon: mdi:lightbulb-on-50
collapsed: true
input:
helper_force_brightness:
name: Force brightness
description: Force the brightness to **Brightness** value when light turns on.
default: false
selector:
boolean: {}
helper_brightness:
name: Brightness
description:
Target light brightness when turning on. Requires **Force brightness**
to be enabled.
default: 50
selector:
number:
unit_of_measurement: "%"
min: 1.0
max: 100.0
step: 1.0
mode: slider
mode: restart
max_exceeded: silent
triggers:
# TRADFRI - E1743 + RODRET - E2201
- trigger: event
event_type: zha_event
event_data:
command: "on"
cluster_id: 6
endpoint_id: 1
id: press-on-zha-e1743-e2201
- trigger: mqtt
topic: "+/+/action"
payload: "on"
id: press-on-z2m-e1743-e2201
- trigger: event
event_type: zha_event
event_data:
command: "off"
cluster_id: 6
endpoint_id: 1
id: press-off-zha-e1743-e2201
- trigger: mqtt
topic: "+/+/action"
payload: "off"
id: press-off-z2m-e1743-e2201
- trigger: event
event_type: zha_event
event_data:
command: move_with_on_off
cluster_id: 8
endpoint_id: 1
id: hold-on-zha-e1743-e2201
- trigger: mqtt
topic: "+/+/action"
payload: brightness_move_up
id: hold-on-z2m-e1743-e2201
- trigger: event
event_type: zha_event
event_data:
command: move
cluster_id: 8
endpoint_id: 1
id: hold-off-zha-e1743-e2201
- trigger: mqtt
topic: "+/+/action"
payload: brightness_move_down
id: hold-off-z2m-e1743-e2201
- trigger: event
event_type: zha_event
event_data:
endpoint_id: 1
cluster_id: 8
id: release-zha-e1743-e2201
- trigger: mqtt
topic: "+/+/action"
payload: brightness_stop
id: release-z2m-e1743-e2201
# SOMRIG - E2213
- trigger: event
event_type: zha_event
event_data:
command: short_release
endpoint_id: 1
id: press-dots1-zha-e2213
- trigger: mqtt
topic: "+/+/action"
payload: 1_short_release
id: press-dots1-z2m-e2213
- trigger: event
event_type: zha_event
event_data:
command: short_release
endpoint_id: 2
id: press-dots2-zha-e2213
- trigger: mqtt
topic: "+/+/action"
payload: 2_short_release
id: press-dots2-z2m-e2213
- trigger: event
event_type: zha_event
event_data:
command: long_press
endpoint_id: 1
id: hold-dots1-zha-e2213
- trigger: mqtt
topic: "+/+/action"
payload: 1_long_press
id: hold-dots1-z2m-e2213
- trigger: event
event_type: zha_event
event_data:
command: long_press
endpoint_id: 2
id: hold-dots2-zha-e2213
- trigger: mqtt
topic: "+/+/action"
payload: 2_long_press
id: hold-dots2-z2m-e2213
- trigger: event
event_type: zha_event
event_data:
command: long_release
endpoint_id: 1
id: release-hold-dots1-zha-e2213
- trigger: mqtt
topic: "+/+/action"
payload: 1_long_release
id: release-hold-dots1-z2m-e2213
- trigger: event
event_type: zha_event
event_data:
command: long_release
endpoint_id: 2
id: release-hold-dots2-zha-e2213
- trigger: mqtt
topic: "+/+/action"
payload: 2_long_release
id: release-hold-dots2-z2m-e2213
variables:
helper_force_brightness: !input helper_force_brightness
helper_hold_delay: 0.1
helper_hold_dim_step: 4
light: !input light
remote_devices: !input remote_devices
remote_device: >-
{% set is_zha = trigger.platform == "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: template
value_template: "{{ remote_device in remote_devices }}"
actions:
- choose:
- conditions:
- condition: trigger
id:
- press-on-zha-e1743-e2201
- press-on-z2m-e1743-e2201
- press-dots1-zha-e2213
- press-dots1-z2m-e2213
sequence:
- choose:
- conditions: "{{ helper_force_brightness }}"
sequence:
- action: light.turn_on
target:
entity_id: !input light
data:
brightness_pct: !input helper_brightness
default:
- action: light.turn_on
target:
entity_id: !input light
data: {}
- conditions:
- condition: trigger
id:
- press-off-zha-e1743-e2201
- press-off-z2m-e1743-e2201
- press-dots2-zha-e2213
- press-dots2-z2m-e2213
sequence:
- action: light.turn_off
target:
entity_id: !input light
data: {}
- conditions:
- condition: trigger
id:
- hold-on-zha-e1743-e2201
- hold-on-z2m-e1743-e2201
- hold-dots1-zha-e2213
- hold-dots1-z2m-e2213
sequence:
- repeat:
while:
- condition: trigger
id:
- hold-on-zha-e1743-e2201
- hold-on-z2m-e1743-e2201
- hold-dots1-zha-e2213
- hold-dots1-z2m-e2213
sequence:
- parallel:
- action: light.turn_on
target:
entity_id: !input light
data:
brightness_step_pct: "{{ helper_hold_dim_step }}"
transition: "{{ helper_hold_delay }}"
- delay: "{{ helper_hold_delay }}"
- conditions:
- condition: trigger
id:
- hold-off-zha-e1743-e2201
- hold-off-z2m-e1743-e2201
- hold-dots2-zha-e2213
- hold-dots2-z2m-e2213
sequence:
- variables:
brightness_pct: "{{ iif(is_state(light, 'on'), state_attr(light, 'brightness'), 0) * 100 / 255 }}"
total_iterations_to_zero: "{{ (brightness_pct / helper_hold_dim_step) | round(0, 'ceil') }}"
- repeat:
count: "{{ total_iterations_to_zero - 1 }}"
sequence:
- parallel:
- action: light.turn_on
target:
entity_id: !input light
data:
brightness_step_pct: "{{ helper_hold_dim_step | int * -1 }}"
transition: "{{ helper_hold_delay }}"
- delay: "{{ helper_hold_delay }}"
- action: light.turn_on
target:
entity_id: !input light
data:
brightness_pct: 1
transition: "{{ helper_hold_delay }}"