Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thomasmaxson/46933a9ad0271a8517b2faef372857ba to your computer and use it in GitHub Desktop.

Select an option

Save thomasmaxson/46933a9ad0271a8517b2faef372857ba to your computer and use it in GitHub Desktop.
Home Assistant Blueprint to control your devices with an IKEA RODRET, IKEA SOMRIG and IKEA TRÅDFRI 2 Button remote using ZHA or MQTT.
# This blueprint uses an IKEA TRÅDFRI, RODRET and SOMRIG 2 Button Remote Control connected through ZHA or MQTT.
# This blueprint allows you to control lights and run custom actions with the remote's buttons
#
# | Button Type | Interaction | Action Choices |
# | ------------- | ------------ | ----------------------- |
# | Power On | Press | - Toggle light(s) state |
# | | | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Power On | Press & Hold | - Increase brightness |
# | | | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Power Off | Press | - Toggle light(s) state |
# | | | - Run custom action |
# | ------------- | ------------ | ----------------------- |
# | Power Off | Press & Hold | - Decrease brightness |
# | | | - Run custom action |
# | ------------- | ------------ | ----------------------- |
blueprint:
name: IKEA RODRET, SOMRIG or TRÅDFRI, 2 Button Remote Control
description: Control devices with your IKEA RODRET, SOMRIG or TRÅDFRI 2 button remotes.
author: Thomas Maxson
source_url: https://gist.github.com/thomasmaxson/46933a9ad0271a8517b2faef372857ba
homeassistant:
min_version: 2024.6.0
domain: automation
input:
remote:
name: Remote
description: >-
Select the IKEA remote to to use
<br>Choose from RODRET, SOMRIG or TRÅDFRI 2 button remotes
default: []
selector:
device:
multiple: false
filter:
- integration: mqtt
manufacturer: IKEA
model: RODRET wireless dimmer/power switch
- integration: mqtt
manufacturer: IKEA
model: SOMRIG shortcut button
- integration: mqtt
manufacturer: IKEA
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: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
event_button_type:
name: Event Type
description: >-
Select the event you want the remote to do.
<br>&bull; _Toggle light_: Toggle the power state of the light(s)
<br>&bull; _Custom Action_: Trigger your own custom action
default: "toggle"
selector:
select:
options:
- label: Toggle light
value: toggle
- label: Custom action
value: action
light_config:
name: Light Configuration
icon: mdi:lightbulb-on
collapsed: true
input:
light:
name: Light(s)
description: Select the light entities you wish to control.
default: []
selector:
entity:
multiple: true
filter:
domain: light
brightness_on_percent:
name: Brightness Level When Light Turns on
description: >-
Level of brightness to set the light(s) to when turning on.
<br>&bull; Set 1-100 to use a specific brightness level
<br>&bull; Set to 0 to use the lights last brightness level
selector:
number:
mode: slider
unit_of_measurement: "%"
min: 0
max: 100.0
step: 1.0
default: 0
brightness_step:
name: Brightness Step
description: Incremental value to increase or decrease lights brightness.
selector:
number:
mode: slider
unit_of_measurement: "%"
min: 5
max: 100
step: 5.0
default: 20
repeat_delay:
name: Repeat Delay
description: Delay between the brightness adjustment steps.
selector:
number:
mode: slider
unit_of_measurement: seconds
min: 0.25
max: 5
step: 0.25
default: 1
repeat_max_count:
name: Maximum loop repeats
description: >-
Maximum number of times to repeat the brightness event(s).
<br>&bull; Used as a safety limit to prevent an endless loop, just in case the corresponding stop event is not received.
default: 10
selector:
number:
min: 1
max: 100
mode: slider
step: 1
custom_button_events:
name: Custom Button Events
description: Define custom actions to override the default light control actions.
icon: mdi:sync-alert
collapsed: true
input:
event_button_press_on_single:
name: Override On Button Press Event
description: The action to perform on _press_ of the **On Button**.
default: []
selector:
action: null
event_button_press_on_hold:
name: Override On Button Press and Hold Event
description: >-
The action to perform on _press and hold_ of the **On Button**.
<br>Use with care, before the _press and hold_ event, this buttons _press_ event gets triggered.
default: []
selector:
action: null
event_button_press_off_single:
name: Override Off Button Press Event
description: The action to perform on _press_ of the **Off Button**.
default: []
selector:
action: null
event_button_press_off_hold:
name: Override Off Button Press and Hold Event
description: >
The action to perform on _press and hold_ of the **Off Button**.
<br>Use with care, before the _press and hold_ event, this buttons _press_ event gets triggered.
default: []
selector:
action: null
automation_config:
name: Configuration
icon: mdi:cog
collapsed: true
input:
config_mode:
name: Automation Mode
description: Mode that automation runs in.
default: restart
selector:
select:
options:
- single
- restart
- queued
- parallel
custom_value: false
multiple: false
config_max_num:
name: Mode Max
description: >
Maximum number of runs that can be executed or queued at a time.
<br>Ignored by _Single_ and _Restart_ Modes.
default: 10
selector:
number:
mode: slider
unit_of_measurement: runs
min: 1.0
max: 15.0
step: 1.0
mode: !input config_mode
max: !input config_max_num
max_exceeded: silent
variables:
var_remote: !input remote
var_light: !input light
var_brightness_on_percent: !input brightness_on_percent
var_brightness_step: !input brightness_step
var_repeat_delay: !input repeat_delay
var_repeat_max_count: !input repeat_max_count
var_event_button_type: !input event_button_type
triggers:
- alias: On (Dash, Line or 1 Dot) Button Press (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: "on"
id: trigger_on_single_press_zha
- alias: On (Dash, Line or 1 Dot) Button Press (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: "on"
id: trigger_on_single_press_mqtt
- alias: On (Dash, Line or 1 Dot) Button Press and Hold (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: "move_with_on_off"
id: trigger_on_hold_press_zha
- alias: On (Dash, Line or 1 Dot) Button Press and Hold (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: "brightness_move_up"
id: trigger_on_hold_press_mqtt
- alias: On (Dash, Line or 1 Dot) Button Release (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: "stop_with_on_off"
id: trigger_on_release_zha
- alias: On (Dash, Line or 1 Dot) Button Release (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: "brightness_stop"
id: trigger_on_release_mqtt
- alias: Off (Circle or 2 Dots) Button Press (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: "off"
id: trigger_off_single_press_zha
- alias: Off (Circle or 2 Dots) Button Press (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: "off"
id: trigger_off_single_press_mqtt
- alias: Off (Circle or 2 Dots) Button Press and Hold (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: "move"
id: trigger_off_hold_press_zha
- alias: Off (Circle or 2 Dots) Button Press and Hold (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: "brightness_move_down"
id: trigger_off_hold_press_mqtt
- alias: Off (Circle or 2 Dots) Button Release (via ZHA event)
trigger: event
event_type: zha_event
event_data:
device_id: !input remote
command: "stop_with_on_off"
id: trigger_off_release_zha
- alias: Off (Circle or 2 Dots) Button Release (via MQTT event)
trigger: device
domain: mqtt
device_id: !input remote
type: action
subtype: "brightness_stop"
id: trigger_off_release_mqtt
conditions:
- condition: template
value_template: "{{ var_remote | count > 0 }}"
actions:
- variables:
var_all_lights_on: >-
{{ expand( var_light ) | selectattr( "state", "eq", "on" ) | map( attribute = "entity_id" ) | list }}
var_all_lights_off: >-
{{ expand( var_light ) | selectattr( "state", "eq", "off" ) | map( attribute = "entity_id" ) | list }}
var_first_light_on: >-
{{ [] if ( var_light | length <= 0 ) else expand( var_light ) | selectattr( "state", "eq", "on" ) | map( attribute = "entity_id" ) | list | first }}
- alias: "Determine button event to execute"
choose:
- alias: "Button: On, Press"
conditions:
- alias: "Check if triggered by On button press"
condition: trigger
id:
- trigger_on_single_press_zha
- trigger_on_single_press_mqtt
sequence:
- alias: "Determine event action to trigger"
choose:
- alias: "For On button press, manage light on/off state"
conditions:
- alias: "Check if correct action choice is selected"
condition: and
conditions:
- alias: "Check if should toggle light(s)"
condition: template
value_template: "{{ var_event_button_type == 'toggle' }}"
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_all_lights_on | length == 0 }}"
sequence:
- alias: "Determine how to turn on light(s)"
if:
- alias: "Check if light brightness option is greater than 0"
condition: template
value_template: "{{ var_brightness_on_percent | int > 0 }}"
then:
- alias: "Turn on light(s) with the configured brightness level"
action: light.turn_on
target:
entity_id: "{{ var_all_lights_off }}"
data:
brightness_pct: !input brightness_on_percent
else:
- alias: "Turn on light(s)"
action: light.turn_on
target:
entity_id: "{{ var_all_lights_off }}"
- alias: "For On button press, run custom action"
conditions:
- alias: "Check if correct action choice is selected"
condition: template
value_template: "{{ var_event_button_type == 'action' }}"
sequence: !input event_button_press_on_single
- alias: "Button: On, Press and Hold"
conditions:
- alias: "Check if triggered by On button press and hold"
condition: trigger
id:
- trigger_on_hold_press_zha
- trigger_on_hold_press_mqtt
sequence:
- alias: "Determine event action to trigger"
choose:
- alias: "For On button press, manage light state"
conditions:
- alias: "Check if correct action choice is selected"
condition: and
conditions:
- alias: "Check if should toggle light(s)"
condition: template
value_template: "{{ var_event_button_type == 'toggle' }}"
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_all_lights_on | length > 0 }}"
sequence:
- alias: "Repeat brightness increase for the light(s) that are on"
repeat:
until:
- alias: "Check if triggered by button press"
condition: trigger
id:
- trigger_on_release_zha
- trigger_on_release_mqtt
- alias: "Check if the maximum repeat count reached"
condition: template
value_template: "{{ repeat.index > var_repeat_max_count | int }}"
- alias: "Wait for button to be released"
condition: template
value_template: "{{ wait.trigger is not none }}"
sequence:
- alias: "Increase brightness for light(s) that are on"
action: light.turn_on
target:
entity_id: "{{ var_all_lights_on }}"
data:
brightness_step_pct: "{{ var_brightness_step * 1 | int }}"
- alias: "Delay between brightness increase steps"
delay:
seconds: "{{ var_repeat_delay | float }}"
- alias: "For On button press and hold, run custom action"
conditions:
- alias: "Check if correct action choice is selected"
condition: template
value_template: "{{ var_event_button_type == 'action' }}"
sequence: !input event_button_press_on_hold
- alias: "Button: Off, Press"
conditions:
- alias: "Check if triggered by Off button press"
condition: trigger
id:
- trigger_off_single_press_zha
- trigger_off_single_press_mqtt
sequence:
- alias: "Determine event action to trigger"
choose:
- alias: "For Off button press, manage light on/off state"
conditions:
- alias: "Check if correct action choice is selected"
condition: and
conditions:
- alias: "Check if should toggle light(s)"
condition: template
value_template: "{{ var_event_button_type == 'toggle' }}"
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_all_lights_on | length > 0 }}"
sequence:
- alias: "Turn off light(s) if set, otherwise execute custom action"
if:
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_light | length > 0 }}"
then:
- alias: "Turn off light(s)"
action: light.turn_off
target:
entity_id: "{{ var_all_lights_on }}"
- alias: "For Off button press, run custom action"
conditions:
- alias: "Check if correct action choice is selected"
condition: template
value_template: "{{ var_event_button_type == 'action' }}"
sequence: !input event_button_press_off_single
- alias: "Button: Off, Press and Hold"
conditions:
- alias: "Check if triggered by On button press and hold"
condition: trigger
id:
- trigger_off_hold_press_zha
- trigger_off_hold_press_mqtt
sequence:
- alias: "Determine event action to trigger"
choose:
- alias: "For Off button press, manage light state"
conditions:
- alias: "Check if correct action choice is selected"
condition: and
conditions:
- alias: "Check if should toggle light(s)"
condition: template
value_template: "{{ var_event_button_type == 'toggle' }}"
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_all_lights_on | length > 0 }}"
sequence:
- alias: "Decrease brightness for light(s) if set, otherwise execute custom action"
if:
- alias: "Check if light(s) to be controlled are set"
condition: template
value_template: "{{ var_light | length > 0 }}"
then:
- alias: "Repeat brightness decrease for the light(s) that are on"
repeat:
until:
- alias: "Check if triggered by button press"
condition: trigger
id:
- trigger_off_release_zha
- trigger_off_release_mqtt
- alias: "Check if the maximum repeat count reached"
condition: template
value_template: "{{ repeat.index > var_repeat_max_count | int }}"
- alias: "Wait for button to be released"
condition: template
value_template: "{{ wait.trigger is not none }}"
sequence:
- alias: "Decrease brightness for light(s) that are on"
action: light.turn_on
target:
entity_id: "{{ var_all_lights_on }}"
data:
brightness_step_pct: "{{ var_brightness_step * -1 | int }}"
- alias: "Delay between brightness decrease steps"
delay:
seconds: "{{ var_repeat_delay | float }}"
- alias: "For Off button press and hold, run custom action"
conditions:
- alias: "Check if correct action choice is selected"
condition: template
value_template: "{{ var_event_button_type == 'action' }}"
sequence: !input event_button_press_off_hold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment