Skip to content

Instantly share code, notes, and snippets.

@lymbada
Last active August 17, 2022 09:54
Show Gist options
  • Save lymbada/aff74b97d01f1a567bdebf13710d4a92 to your computer and use it in GitHub Desktop.
Save lymbada/aff74b97d01f1a567bdebf13710d4a92 to your computer and use it in GitHub Desktop.
Ikea Button with Deconz to control RGB (HS) Light(s)
# Copyright (c) 2022, Matthew Tilney
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
blueprint:
name: DeconZ Ikea Button RGB Light
description: "Interface an Ikea Zigbee Button switch via DeconZ to provide simple
control of light(s) with RGB Lightoff:\n - short press = turn off\n - long
(hold) = cycle through the Hue (of HSV) of the light. (~10.8sec for full cycle)\nLighton:\n
\ - shor press = turn on\n - long (hold) = slowly raise the brightness up
(until the value you desire or 100%)\n"
domain: automation
input:
remote:
name: Remote
description: The Ikea Button remote control from Deconz
selector:
device:
integration: deconz
manufacturer: IKEA of Sweden
model: TRADFRI SHORTCUT Button
multiple: false
light:
name: Light
description: The RGB light(s) that will be controlled
selector:
target:
entity:
domain: light
saturation:
name: Saturation
description: The Saturation (whiteness) value to be applied when cycling Hue (colour)
selector:
number:
min: 10
max: 100
step: 1
unit_of_measurement: "%"
mode: slider
source_url: https://gist.github.com/lymbada/aff74b97d01f1a567bdebf13710d4a92
mode: restart
trigger:
- platform: event
event_type: deconz_event
event_data:
device_id: !input remote
variables:
lights: !input light
action:
- variables:
event: '{{ trigger.event.data.event }}'
- service: system_log.write
data:
level: warning
message: ' {{lights}} {{lights.entity_id[0]}} That was the Lights (up) #######################
Current Colour: {% if is_state(lights.entity_id[0],"on")%}{{(state_attr(lights.entity_id[0],"hs_color")[0]
+ 10) % 360}}{% endif %} ####################### '
logger: automations.log
- if:
- condition: template
value_template: '{{is_state(lights.entity_id[0],''off'')}}
'
then:
- choose:
- conditions:
- '{{ event == 1002 }}'
sequence:
- service: light.turn_on
target: !input light
data:
transition: 1
- conditions:
- '{{ event == 1001 }}'
sequence:
repeat:
while:
- condition: template
value_template: '{{ repeat.index < 10 }}'
sequence:
- service: light.turn_on
target: !input light
data:
transition: 1
brightness_step_pct: 10
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 297
- conditions:
- '{{ event == 1003 }}'
sequence:
- service: light.turn_on
target: !input light
else:
- choose:
- conditions:
- '{{ event == 1002 }}'
sequence:
- service: light.turn_off
target: !input light
data:
transition: 1
- conditions:
- '{{ event == 1001 }}'
sequence:
repeat:
while:
- condition: template
value_template: '{{ is_state(lights.entity_id[0],"on") }}'
sequence:
- service: light.turn_on
target: !input light
data:
hs_color:
- '{{ (state_attr(lights.entity_id[0],"hs_color")[0] + 10) % 360}}'
- !input saturation
transition: 0.28
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 297
- conditions:
- '{{ event == 1003 }}'
sequence:
- service: light.turn_on
target: !input light
@lymbada
Copy link
Author

lymbada commented Aug 16, 2022

  • add slider for Saturation value (so that it could be configured on per-automation basis (currently set as default of 100/max)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment