Advertisement
JLindvig

All-In-One

Jan 12th, 2021
1,504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 6.72 KB | None | 0 0
  1. blueprint:
  2.   name: deCONZ - IKEA remote All-In-One
  3.   description: |
  4.    This blueprint utilize a IKEA five button (puck) remote to control a group of lights individually.
  5.    
  6.     REQUIREMENTS:
  7.     ------------------------------------------------------------------------------------------------------------------------------------------------------
  8.     Due to limitations in Blueprints and Home Assistant, you will need the following:
  9.     + A Group combining the lights (https://www.home-assistant.io/integrations/group/)
  10.     + A input_select with a single element with af value of "null", "void" or "empty".
  11.    
  12.     HOW THE REMOTE WORKS:
  13.     ------------------------------------------------------------------------------------------------------------------------------------------------------
  14.     LEFT AND RIGHT:
  15.     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.
  16.    
  17.     DIM UP OR DOWN:
  18.     Short press will in/decrease brightness with the specified step in percent and short transition time.
  19.     Long pres will in/decrease brightness continuesly using a specified long transition time.
  20.    
  21.     POWER:
  22.     Short press toggles the selected light
  23.     Long press turns on ALL lights in the group at 100%
  24.    
  25.     HOW THE AUTOMATION WORKS:
  26.     ------------------------------------------------------------------------------------------------------------------------------------------------------
  27.     We listen on "deconz_event" and extract the numeric representation of the pressed button and duration.
  28.  
  29.     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.
  30.    
  31.     Secondly we choose the appropriate action from the given event.
  32.   source_url: https://github.com/J-Lindvig/HomeAssistant/blob/master/blueprints/automation/J-Lindvig/all_in_remote.yaml
  33.   domain: automation
  34.  
  35.   input:
  36.     remote:
  37.       name: Remote
  38.       description: IKEA five button remote to use
  39.       selector:
  40.         device:
  41.           integration: deconz
  42.           manufacturer: IKEA of Sweden
  43.           model: TRADFRI remote control
  44.  
  45.     light:
  46.       name: Light(s)
  47.       description: The group (not light group) containing the lights
  48.       selector:
  49.         entity:
  50.           domain: group
  51.  
  52.     group:
  53.       name: Control list
  54.       description: "The input_select to store lights. MUST HAVE A SINGLE ELEMENT WITH VALUE 'null', 'void' or 'empty'"
  55.       selector:
  56.         entity:
  57.           domain: input_select
  58.  
  59.     dim_step_pct:
  60.       name: Step
  61.       description: Step, in percent, to de- or increase brightness
  62.       default: 20
  63.       selector:
  64.         number:
  65.           min: 5.0
  66.           max: 100.0
  67.           mode: slider
  68.           step: 5.0
  69.           unit_of_measurement: "%"
  70.  
  71.     short_press_transition:
  72.       name: Transition short
  73.       description: Transtion time used when doing a short press
  74.       default: 0.5
  75.       selector:
  76.         number:
  77.           min: 0.0
  78.           max: 2.0
  79.           mode: slider
  80.           step: 0.1
  81.           unit_of_measurement: "seconds"
  82.  
  83.     long_press_transition:
  84.       name: Transition long
  85.       description: Transtion time used when doing a long press (0 - 100%)
  86.       default: 30
  87.       selector:
  88.         number:
  89.           min: 5.0
  90.           max: 50.0
  91.           mode: slider
  92.           step: 1.0
  93.           unit_of_measurement: "seconds"
  94.  
  95. mode: restart
  96. max_exceeded: silent
  97. variables:
  98.   light_group: !input light
  99.   group: !input group
  100.   dim_step_pct: !input dim_step_pct
  101.   short_press_transition: !input short_press_transition
  102.   long_press_transition: !input long_press_transition
  103.   deconz_data_str: "{'on': True, 'bri_inc': 254, 'transitiontime': 12345}"
  104. trigger:
  105. - platform: event
  106.   event_type: deconz_event
  107.   event_data:
  108.     device_id: !input remote
  109. action:
  110. - variables:
  111.     event: "{{ trigger.event.data.event }}"
  112.     list: "{{ state_attr(light_group, 'entity_id') }}"
  113.     light: "{{ states(group) }}"
  114.  
  115. - choose:
  116.  # INIT
  117.   # This is the initial run - fill the input_select with the entities from the group
  118.   - conditions: "{{ light | lower in ('null', 'void', 'empty') }}"
  119.     sequence:
  120.       - service: input_select.set_options
  121.         data:
  122.           entity_id: "{{ group }}"
  123.           options: "{{ list | tojson }}"
  124.  
  125. - choose:
  126.  # LEFT OR RIGHT
  127.   # Find the previous or next light and give it a short flash
  128.   - conditions: "{{ event in (4002, 5002) }}"
  129.     sequence:
  130.       - service: "input_select.select_{{ 'previous' if event == 4002 else 'next' }}"
  131.         data:
  132.           entity_id: "{{ group }}"
  133.       - variables:
  134.           light: "{{ states(group) }}"
  135.       - repeat:
  136.           count: 2
  137.           sequence:
  138.             - delay:
  139.                 milliseconds: 500
  140.             - service: light.turn_off
  141.               data:
  142.                 entity_id: "{{ light }}"
  143.             - delay:
  144.                 milliseconds: 500
  145.             - service: light.turn_on
  146.               data:
  147.                 entity_id: "{{ light }}"
  148.                 brightness_pct: 100
  149.  
  150.   # SHORT PRESS POWER
  151.   # Toggle the choosen light
  152.   - conditions: "{{ event == 1002 }}"
  153.     sequence:
  154.       - service: light.toggle
  155.         data:
  156.           entity_id: "{{ light }}"
  157.  
  158.   # LONG PRESS POWER
  159.   # Turn on all lights
  160.   - conditions: "{{ event == 1001 }}"
  161.     sequence:
  162.       - service: light.turn_on
  163.         data:
  164.           entity_id: "{{ light_group }}"
  165.           transition: "{{ short_press_transition }}"
  166.  
  167.   # SHORT PRESS UP OG DOWN (DIMMING IN STEPS)
  168.   # Dim the choosen light up or down
  169.   - conditions: "{{ event in (2002, 3002) }}"
  170.     sequence:
  171.       - service: light.turn_on
  172.         data:
  173.           entity_id: "{{ light }}"
  174.           brightness_step_pct: "{{ ( dim_step_pct | int ) if event == 2002 else (0 - ( dim_step_pct | int )) }}"
  175.           transition: "{{ short_press_transition }}"
  176.  
  177.   # LONG PRESS UP (FLOW DIMMING)
  178.   - conditions: "{{ event in (2001, 3001) }}"
  179.     sequence:
  180.       - service: light.turn_on
  181.         data:
  182.           entity_id: "{{ light }}"
  183.  
  184.       - repeat:
  185.           while: []
  186.           sequence:
  187.             - service: light.turn_on
  188.               data:
  189.                 entity_id: "{{ light }}"
  190.                 brightness: >-
  191.                   {%- set brightness = state_attr(light, 'brightness') | int %}
  192.                   {%- set step = (254 / (long_press_transition | int)) | round(0, 'floor') %}
  193.                   {% if event == 3001 %}
  194.                     {% set step = 0 - step %}
  195.                   {% endif %}
  196.                   {{ state_attr(light, 'brightness') | int + step }}
  197.             - delay: 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement