Skip to content

Instantly share code, notes, and snippets.

@J-Lindvig
Created January 14, 2021 13:32
Show Gist options
  • Save J-Lindvig/0fe6c55515970f4417edb03af7322648 to your computer and use it in GitHub Desktop.
Save J-Lindvig/0fe6c55515970f4417edb03af7322648 to your computer and use it in GitHub Desktop.
deCONZ - All-in-One IKEA five button remote aka. “One Remote To Rule 'Em All”
blueprint:
name: deCONZ - IKEA remote All-In-One
description: |
This blueprint utilize a IKEA five button (puck) remote to control a group of lights individually.
REQUIREMENTS:
------------------------------------------------------------------------------------------------------------------------------------------------------
Due to limitations in Blueprints and Home Assistant, you will need the following:
- A Group combining the lights (https://www.home-assistant.io/integrations/group/)
See this example:
group:
living_room:
name: group light for kitchen and living room"
entities:
- light.kitchen
- light.kitchen_table
- light.living_room ( actually a light_group containing multiple single lights combined into one single entity).
+ A input_select with a single element with af value of "null", "void" or "empty".
Example:
input_select:
light_input_select:
name: light input select to handle selection of light in a group"
options:
- null
HOW THE REMOTE WORKS:
------------------------------------------------------------------------------------------------------------------------------------------------------
LEFT AND RIGHT:
With a short press on either the left/right arrow, you will be able to switch between the light in the group. The current selected light give a short flash indicating your selection.
DIM UP OR DOWN:
Short press will in/decrease brightness with the specified step in percent and short transition time.
Long pres will in/decrease brightness continuesly using a transition time stating how long a dim from 0 to 100% shoiuld take.
POWER:
Short press toggles the selected light
Long press turns on ALL lights in the group at 100%
HOW THE AUTOMATION WORKS:
------------------------------------------------------------------------------------------------------------------------------------------------------
We listen on "deconz_event" and extract the numeric representation of the pressed button and duration.
At the very first run, the input_select is populated with the entities stored in the group. We are using a input_select to ease the swithing between light entities.
Secondly we choose the appropriate action from the given event.
USING THE BLUEPRINT IN YAML MODE:
------------------------------------------------------------------------------------------------------------------------------------------------------
If you decide to make the automation directly in YAML it would look like this:
automation:
- alias: Kitchen and Livingroom
description: The All-in-One remote formuse in the kitchen and the livingroom.
use_blueprint:
path: J-Lindvig/all_in_remote.yaml
input:
long_press_transition: '30'
remote: c08819d98af8b341299ea47c702e9a37
light_group: group.all_in_one_group
input_select_group: input_select.all_in_one_test
short_press_transition: '0.5'
dim_step_pct: 20
source_url: https://github.com/J-Lindvig/HomeAssistant/blob/master/blueprints/automation/J-Lindvig/all_in_remote.yaml
domain: automation
input:
remote:
name: Remote
description: IKEA five button remote to use
selector:
device:
integration: deconz
manufacturer: IKEA of Sweden
model: TRADFRI remote control
light_group:
name: Light(s)
description: The group (not light group) containing the lights
selector:
entity:
domain: group
input_select_group:
name: Control list
description: "The input_select to store lights. MUST HAVE A SINGLE ELEMENT WITH VALUE 'null', 'void' or 'empty'"
selector:
entity:
domain: input_select
dim_step_pct:
name: Step
description: Step, in percent, to de- or increase brightness
default: 20
selector:
number:
min: 5.0
max: 100.0
mode: slider
step: 5.0
unit_of_measurement: "%"
short_press_transition:
name: Transition short
description: Transtion time used when doing a short press
default: 0.5
selector:
number:
min: 0.0
max: 2.0
mode: slider
step: 0.1
unit_of_measurement: "seconds"
long_press_transition:
name: Transition long
description: Transtion time used when doing a long press (0 - 100%)
default: 30
selector:
number:
min: 5.0
max: 50.0
mode: slider
step: 1.0
unit_of_measurement: "seconds"
mode: restart
max_exceeded: silent
variables:
light_group: !input light_group
group: !input input_select_group
dim_step_pct: !input dim_step_pct
dim_step: 0
prev_state: ""
prev_brightness: 0
short_press_transition: !input short_press_transition
long_press_transition: !input long_press_transition
trigger:
- platform: event
event_type: deconz_event
event_data:
device_id: !input remote
action:
- variables:
event: "{{ trigger.event.data.event }}"
list: "{{ state_attr(light_group, 'entity_id') }}"
light: "{{ states(group) }}"
dim_step: "{{ (254 / (long_press_transition | int)) | round(0, 'floor') }}"
- choose:
# INIT
# This is the initial run - fill the input_select with the entities from the group
- conditions: "{{ light | lower in ('null', 'void', 'empty') }}"
sequence:
- service: input_select.set_options
data:
entity_id: "{{ group }}"
options: "{{ list | tojson }}"
- choose:
# LEFT OR RIGHT
# Find the previous or next light and give it a short flash
- conditions: "{{ event in (4002, 5002) }}"
sequence:
# Select the choosen light in the list
- service: "input_select.select_{{ 'previous' if event == 4002 else 'next' }}"
data:
entity_id: "{{ group }}"
# Update the light variable and save the state of the light
- variables:
light: "{{ states(group) }}"
prev_state: "{{ states(light) }}"
# Turn on the light and save the brightness of the light
- service: light.turn_on
data:
entity_id: "{{ light }}"
- variables:
prev_brightness: "{{ state_attr(light, 'brightness') | int }}"
# Flash the light - HA style
- repeat:
count: 2
sequence:
- delay:
milliseconds: 500
- service: light.turn_off
data:
entity_id: "{{ light }}"
- delay:
milliseconds: 500
- service: light.turn_on
data:
entity_id: "{{ light }}"
brightness_pct: 100
# Restore previous brightness
- service: light.turn_on
data:
entity_id: "{{ light }}"
brightness: "{{ prev_brightness | int }}"
# Take a second and restore previous state
- delay: 1
- service: "light.turn_{{ prev_state }}"
data:
entity_id: "{{ light }}"
# SHORT PRESS POWER
# Toggle the choosen light
- conditions: "{{ event == 1002 }}"
sequence:
- service: light.toggle
data:
entity_id: "{{ light }}"
# LONG PRESS POWER
# Turn on all lights at 100%
- conditions: "{{ event == 1001 }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ light_group }}"
brightness_pct: 100
# SHORT PRESS UP OG DOWN (DIMMING IN STEPS)
# Dim the choosen light up or down
- conditions: "{{ event in (2002, 3002) }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ light }}"
brightness_step_pct: "{{ ( dim_step_pct | int ) if event == 2002 else (0 - ( dim_step_pct | int )) }}"
transition: "{{ short_press_transition }}"
# LONG PRESS UP OR DOWN (FLOW DIMMING) - HA STYLE...!!!
- conditions: "{{ event in (2001, 3001) }}"
sequence:
# Turn on the light
- service: light.turn_on
data:
entity_id: "{{ light }}"
# While pressing the button in/decrease the brightness with the calculated dim_step
- repeat:
while: []
sequence:
- service: light.turn_on
data:
entity_id: "{{ light }}"
brightness: "{{ state_attr(light, 'brightness') + (0 - dim_step if event == 3001 else dim_step) }}"
- delay: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment