[ZHA] Philips Hue Tap Dial Switch: toggle / dim multiple lights + event

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

GitHub link

I based this blueprint on a couple of other ZHA blueprints for this device:

Feel free to mix and match, these are the features that my blueprint has that I couldn’t figure out in the other blueprints:

  • each button can be associated with multiple lights. It will toggle all the lights in the same way a light group works: if at least one is on, it turns them all off, and if they are all off, it turns them all on.
  • a light can be associated with more than one button. You could use buttons 1-3 for individual lights and button 4 for all 3 lights at once.
  • the dimmer dial controls the brightness only for the lights that are currently on. If you turn on a light with button 1, then another one with button 2, you can then use the dial to dim up or down only these two
  • as a bonus, if none of the lights is on, the dimmer dial dims up all the lights associated with the 4 buttons starting from 0.
  • Edit: added an event emitted for each light that is toggled. I use that event to suspend motion activation for the lights when switched on.
blueprint:
  name: Hue tap dial switch
  description: Control multiple lights with a Hue tap dial switch
  source_url: https://github.com/GordonFreemanK/ha-blueprints/blob/main/hue_tap_dial_switch.yaml
  domain: automation
  input:
    switch:
      name: Switch
      description: The switch that will trigger the automation
      selector:
        device:
          integration: zha
          manufacturer: Signify Netherlands B.V.
          model: RDM002
          multiple: false
    button_1_lights:
      name: Button 1 lights
      description: The lights to toggle with Button 1
      selector:
        entity:
          domain: light
          multiple: true
    button_2_lights:
      name: Button 2 lights
      description: The lights to toggle with Button 2
      selector:
        entity:
          domain: light
          multiple: true
      default: []
    button_3_lights:
      name: Button 3 lights
      description: The lights to toggle with Button 3
      selector:
        entity:
          domain: light
          multiple: true
      default: []
    button_4_lights:
      name: Button 4 lights
      description: The lights to toggle with Button 4
      selector:
        entity:
          domain: light
          multiple: true
      default: []
    brightness:
      name: Brightness
      description: The brightness to turn on the lights at
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: '%'
      default: 80
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input switch
variables:
  command: "{{ trigger.event.data.command }}"
  button_1_lights: !input button_1_lights
  button_2_lights: !input button_2_lights
  button_3_lights: !input button_3_lights
  button_4_lights: !input button_4_lights
action:
  - choose:
    - conditions: "{{ command == 'recall' }}"
      sequence:
      - variables:
          scene: "{{ trigger.event.data.args[1] }}"
          lights: >
            {% if scene == 1 %}
              {{ button_1_lights }}
            {% elif scene == 0 %}
              {{ button_2_lights }}
            {% elif scene == 5 %}
              {{ button_3_lights }}
            {% elif scene == 4 %}
              {{ button_4_lights }}
            {% endif %}
          state: "{{ expand(lights) | selectattr('state','eq','on') | list | length > 0 }}"
      - if:
          - condition: template
            value_template: "{{ state }}"
        then:
          - service: light.turn_off
            target:
              entity_id: "{{ lights }}"
        else:
          - service: light.turn_on
            target:
              entity_id: "{{ lights }}"
            data:
              brightness_pct: !input brightness
      - repeat:
          for_each: "{{ lights }}"
          sequence:
            - event: light_toggled
              event_data:
                state: "{{ not state }}"
                entity_id: "{{ repeat.item }}"
    - conditions: "{{ command == 'step_with_on_off' }}"
      sequence:
      - variables:
          step_mode: "{{ trigger.event.data.params.step_mode }}"
          step_size: "{{ trigger.event.data.params.step_size }}"
      - choose:
        - conditions: "{{ step_mode == 'StepMode.Up' }}"
          sequence:
          - variables:
              lights: >
                {% set lights_all = expand([button_1_lights, button_2_lights, button_3_lights, button_4_lights]) %}
                {% set lights_on = lights_all | selectattr('state','eq','on') | list %}
                {% set lights_used = lights_on if lights_on | length > 0 else lights_all %}
                {{ lights_used | map(attribute='entity_id') | unique | list }}
          - service: light.turn_on
            target:
              entity_id: "{{ lights }}"
            data:
              brightness_step_pct: "{{ step_size }}"
              transition: 1
        - conditions: "{{ step_mode == 'StepMode.Down' }}"
          sequence:
          - variables:
              lights: >
                {{ expand([button_1_lights, button_2_lights, button_3_lights, button_4_lights])
                  | selectattr('state','eq','on')
                  | map(attribute='entity_id')
                  | unique
                  | list }}
          - service: light.turn_on
            target:
              entity_id: "{{ lights }}"
            data:
              brightness_step_pct: '{{ -step_size }}'
              transition: 1

Just imported. Seems to be working quite nicely, thank you!

Every button needs to be assigned, which seems to be an unnecessary requirement. I have only two lights at the moment, so I added them twice as a quick workaround.

Strange, the default: [] on buttons 2-4 allows not assigning them (but button 1 is indeed mandatory). I’ve got one configured with only 3 buttons.