Skip to content

Instantly share code, notes, and snippets.

@notherealmarco
Last active February 4, 2022 23:07
Show Gist options
  • Save notherealmarco/6c7313e0411341d9dd6be40162dd67a9 to your computer and use it in GitHub Desktop.
Save notherealmarco/6c7313e0411341d9dd6be40162dd67a9 to your computer and use it in GitHub Desktop.
Home Assistant all-in-one blueprit to use the IKEA E1743 as a Smart Dimmer remote

Incorporation URL: https://gist.github.com/notherealmarco/6c7313e0411341d9dd6be40162dd67a9

Smart Dimmer x IKEA E1743

This is an all in one Blueprit to use my Smart Dimmer dimming algorithms with the IKEA E1743 remote.

If you're already familiar with Smart Dimmer: you don't need to create the script if you use this blueprint.

Supported dimming algorithms

Timestamp: this algorithm should be used only if the lights are not ZHA devices compatible with the Zigbee Light Link standard. When you call the dimmming function (e.g. you hold down a button), the lights starts dimming to the highest/lowest brightness level with a 3s transition. When the button is released, the a new brightness will be calculated based on the time (in microseconds) the button has been pressed and sent to the lamp.

This algorithm has a known issue: sometimes the lights jumps to a completely different brightness when the button is released.

ZHA ZLL: this algoritm is optimized for Zigbee devices, when the button is released, a special Zigbee raw command is sent to the light, which stops the transition and answers with the current brightness. This command is not natively supported by Home Assistant, so I need to send a raw message, that's why I need the IEEE address.

ZHA Group: same as ZHA ZLL but for Zigbee groups (native Zigbee groups managed through the ZHA integration, doesn't work with software defined groups like the light_group component).

Note: You may need to click on "reconfigure device" (ZHA device page) if the light doesn't push back it's current brightness

Configuration

Input Value Notes
Remote The remote device
Light All the lights you want to turn on/off and dimm At least one entity is needed, do not add only areas or devices
Dimmer helper (input_boolean) An input_boolean helper You can use the same entity for every instance of this blueprint
Dimmer helper (input_text) An input_text helper You can use the same entity for every instance of this blueprint
Dimming mode The algorithm to use, see above Timestamp may be unstable for now, I need to find a way to address the issue
IEEE or Group ID Light's Zigbee IEEE address if you selected "ZHA ZLL light" as dimming mode, Zigbee group ID if you selected "ZHA Group" This value doesn't matter if you're using Timestamp

Usage

Just press the buttons

blueprint:
name: Smart Dimmer x ZHA Tradfri Double
description: >-
Smart Dimmer for the ZHA Tradfri Double. All in one blueprint.
domain: automation
input:
remote:
name: IKEA TRADFRI remote control
description: Select the remote control you wish to use.
selector:
device:
integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
light:
name: Light 1
description: Select the light entity you wish to control.
selector:
target:
entity:
domain: light
light2:
name: Light 2
description: Select the light entity you wish to control.
selector:
target:
entity:
domain: light
dimmer:
name: Dimmer helper (input_boolean)
description: An input_boolean helper that can be used to store temporary data.
selector:
entity:
domain: input_boolean
cts:
name: Dimmer helper (input_text)
description: An input_text helper that can be used to store temporary data.
selector:
entity:
domain: input_text
l1mode:
name: Light 1 dimming mode
default: "Timestamp"
selector:
select:
options:
- Timestamp (BETA)
- ZHA ZLL light
- ZHA Group of ZLL lights
l1ieee:
name: Light 1's IEEE or Group ID
default: "0"
selector:
text:
l2mode:
name: Light 2 dimming mode
default: "Timestamp"
selector:
select:
options:
- Timestamp
- ZHA ZLL light
- ZHA Group of ZLL lights
l2ieee:
name: Light 2's IEEE or Group ID
default: "0"
selector:
text:
mode: restart
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
- choose:
# Short-Press the on button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "on" }}'
- condition: template
value_template: '{{ is_state(main_light_eid, "off") }}'
sequence:
- service: light.turn_on
target: !input light
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "on" }}'
- condition: template
value_template: '{{ is_state(main_light_eid, "on") }}'
sequence:
- service: light.turn_off
target: !input light
# Long-Press the on button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move_with_on_off" }}'
- condition: template
value_template: '{{ (is_state(main_light_eid, "off")) or (state_attr(main_light_eid, "brightness") < 200) }}'
- condition: or
conditions:
- condition: template
value_template: '{{ is_state(main_light_eid, "off") }}'
- condition: template
value_template: '{{ state_attr(main_light_eid, "brightness") < 30 }}'
- condition: state
entity_id: !input dimmer
state: "on"
sequence:
- service: input_boolean.turn_off
target:
entity_id: !input dimmer
- service: input_text.set_value
data:
entity_id: !input cts
value: "1 {{ now().timestamp() }} {{ state_attr(main_light_eid, 'brightness') if states(main_light_eid) == 'on' else 1 }}"
- service: light.turn_on
target: !input light
data:
brightness: 255
transition: 3
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move_with_on_off" }}'
- condition: template
value_template: '{{ is_state(main_light_eid, "on") }}'
- condition: template
value_template: '{{ state_attr(main_light_eid, "brightness") > 30 }}'
- condition: or
conditions:
- condition: template
value_template: '{{ state_attr(main_light_eid, "brightness") > 200 }}'
- condition: state
entity_id: !input dimmer
state: "off"
sequence:
- service: input_boolean.turn_on
target:
entity_id: !input dimmer
- service: input_text.set_value
data:
entity_id: !input cts
value: "1 {{ now().timestamp() }} {{ state_attr(main_light_eid, 'brightness') if states(main_light_eid) == 'on' else 1 }}"
- service: light.turn_on
target: !input light
data:
brightness: 1
transition: 3
# Short-Press the off button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "off" }}'
- condition: template
value_template: '{{ is_state(main_light2_eid, "off") }}'
sequence:
- service: light.turn_on
target: !input light2
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "off" }}'
- condition: template
value_template: '{{ is_state(main_light2_eid, "on") }}'
sequence:
- service: light.turn_off
target: !input light2
# Long-Press the off button
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move" }}'
- condition: template
value_template: '{{ (is_state(main_light2_eid, "off")) or (state_attr(main_light2_eid, "brightness") < 200) }}'
- condition: or
conditions:
- condition: template
value_template: '{{ is_state(main_light2_eid, "off") }}'
- condition: template
value_template: '{{ state_attr(main_light2_eid, "brightness") < 30 }}'
- condition: state
entity_id: !input dimmer
state: "on"
sequence:
- service: input_boolean.turn_on
target:
entity_id: !input dimmer
- service: input_text.set_value
data:
entity_id: !input cts
value: "2 {{ now().timestamp() }} {{ state_attr(main_light2_eid, 'brightness') if states(main_light2_eid) == 'on' else 1 }}"
- service: light.turn_on
target: !input light2
data:
brightness: 255
transition: 3
- conditions:
- condition: template
value_template: '{{ trigger.event.data.command == "move" }}'
- condition: template
value_template: '{{ is_state(main_light2_eid, "on") }}'
- condition: template
value_template: '{{ state_attr(main_light2_eid, "brightness") > 30 }}'
- condition: or
conditions:
- condition: template
value_template: '{{ state_attr(main_light2_eid, "brightness") > 200 }}'
- condition: state
entity_id: !input dimmer
state: "off"
sequence:
- service: input_boolean.turn_on
target:
entity_id: !input dimmer
- service: input_text.set_value
data:
entity_id: !input cts
value: "2 {{ now().timestamp() }} {{ state_attr(main_light2_eid, 'brightness') if states(main_light2_eid) == 'on' else 1 }}"
- service: light.turn_on
target: !input light2
data:
brightness: 1
transition: 3
default:
- choose:
- conditions:
- condition: template
value_template: '{{ states(cts_entity).split(" ")[0] == "1" }}'
- condition: template
value_template: '{{ l1mode == "Timestamp" }}'
sequence:
- service: light.turn_on
target: !input light
data:
brightness: '{% set delta = (now().timestamp() - (states(cts_entity).split(" ")[1]|float)) %}{% set start = (((states(cts_entity).split(" ")[2]|int) / 3)|round) %}{% set up = states(dimmer_entity) == "off" %}{{ (((255 - start) / 3) * (delta + 0.2)) + start if up else 240 - (((255 - start) / 3) * (delta + 0.2)) }}'
transition: 0
- conditions:
- condition: template
value_template: '{{ states(cts_entity).split(" ")[0] == "1" }}'
- condition: template
value_template: '{{ l1mode == "ZHA ZLL light" }}'
sequence:
- service: zha.issue_zigbee_cluster_command
data:
ieee: !input l1ieee
cluster_id: 8
endpoint_id: 1
command: 3
command_type: server
args: []
- conditions:
- condition: template
value_template: '{{ states(cts_entity).split(" ")[0] == "1" }}'
- condition: template
value_template: '{{ l1mode == "ZHA Group of ZLL lights" }}'
sequence:
- service: zha.issue_zigbee_group_command
data:
group: !input l1ieee
cluster_id: 8
command: 3
args: []
# 2
- conditions:
- condition: template
value_template: '{{ states(cts_entity).split(" ")[0] == "2" }}'
- condition: template
value_template: '{{ l2mode == "ZHA ZLL light" }}'
sequence:
- service: zha.issue_zigbee_cluster_command
data:
ieee: !input l2ieee
cluster_id: 8
endpoint_id: 1
command: 3
command_type: server
args: []
- conditions:
- condition: template
value_template: '{{ states(cts_entity).split(" ")[0] == "2" }}'
- condition: template
value_template: '{{ l2mode == "ZHA Group of ZLL lights" }}'
sequence:
- service: zha.issue_zigbee_group_command
data:
group: !input l2ieee
cluster_id: 8
command: 3
args: []
default:
- service: light.turn_on
target: !input light2
data:
brightness: '{% set delta = (now().timestamp() - (states(cts_entity).split(" ")[1]|float)) %}{% set start = (((states(cts_entity).split(" ")[2]|int) / 3)|round) %}{% set up = states(dimmer_entity) == "off" %}{{ (((255 - start) / 3) * (delta + 0.2)) + start if up else 240 - (((255 - start) / 3) * (delta + 0.2)) }}'
transition: 0
variables:
main_light: !input light
maind_light: !input light2
dimmer_entity: !input dimmer
cts_entity: !input cts
l1mode: !input l1mode
l2mode: !input l2mode
l1ieee: !input l1ieee
l2ieee: !input l2ieee
main_light_eid: '{% if main_light["entity_id"] is string %}{{ main_light["entity_id"] }}{% else %}{{ main_light["entity_id"][0] }}{% endif %}'
main_light2_eid: '{% if maind_light["entity_id"] is string %}{{ maind_light["entity_id"] }}{% else %}{{ maind_light["entity_id"][0] }}{% endif %}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment