Philips Tap Dial Switch with double tap and 4 dial actions

So I separated the automations into two for now. One handles the buttons, and I only consider the “press release” event for the first click, as otherwise, I get both “press” and “press release” events. The other handles the “hold” action. The other automation only takes the “dial” actions to separate the three settings: brightness step slow and fast. It’s working well, although it’s not optimized, but I’m taking it step by step. I’d like to add the double-click, so I think I would need to create an automation that doesn’t trigger the other one with a single click, but it’s not easy. If you have any ideas, please let me know.

alias: Philips Hue Dial Switch - Actions de Rotation
description: Gérer les actions de rotation du dial
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/hue_tap_dial_switch/action
condition:
  - condition: template
    value_template: >-
      {{ trigger.payload in ['dial_rotate_right_fast', 'dial_rotate_right_step',
      'dial_rotate_right_slow', 'dial_rotate_left_fast',
      'dial_rotate_left_step', 'dial_rotate_left_slow'] }}
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload in ['dial_rotate_right_fast'] }}"
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '1' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allcentris
                    data:
                      brightness_step: 80
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '2' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.hue_color_lamp_1
                    data:
                      brightness_step: 80
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '3' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.table
                    data:
                      brightness_step: 80
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '4' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allhue
                    data:
                      brightness_step: 80
                      transition: 1
            default:
              - service: light.turn_on
                target:
                  entity_id: all
                data:
                  brightness_step: 80
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload in ['dial_rotate_right_step'] }}"
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '1' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allcentris
                    data:
                      brightness_step: 5
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '2' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.hue_color_lamp_1
                    data:
                      brightness_step: 5
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '3' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.table
                    data:
                      brightness_step: 5
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '4' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allhue
                    data:
                      brightness_step: 5
                      transition: 1
            default:
              - service: light.turn_on
                target:
                  entity_id: all
                data:
                  brightness_step: 5
                  transition: 1
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload in ['dial_rotate_right_slow'] }}"
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '1' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allcentris
                    data:
                      brightness_step: 20
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '2' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.hue_color_lamp_1
                    data:
                      brightness_step: 20
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '3' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.table
                    data:
                      brightness_step: 20
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '4' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allhue
                    data:
                      brightness_step: 20
                      transition: 1
            default:
              - service: light.turn_on
                target:
                  entity_id: all
                data:
                  brightness_step: 20
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload in ['dial_rotate_left_fast'] }}"
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '1' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allcentris
                    data:
                      brightness_step: -80
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '2' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.hue_color_lamp_1
                    data:
                      brightness_step: -80
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '3' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.table
                    data:
                      brightness_step: -80
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '4' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allhue
                    data:
                      brightness_step: -80
                      transition: 1
            default:
              - service: light.turn_on
                target:
                  entity_id: all
                data:
                  brightness_step: -80
                  transition: 1
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload in ['dial_rotate_left_step'] }}"
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '1' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allcentris
                    data:
                      brightness_step: -5
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '2' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.hue_color_lamp_1
                    data:
                      brightness_step: -5
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '3' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.table
                    data:
                      brightness_step: -5
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '4' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allhue
                    data:
                      brightness_step: -5
                      transition: 1
            default:
              - service: light.turn_on
                target:
                  entity_id: all
                data:
                  brightness_step: -5
                  transition: 1
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload in ['dial_rotate_left_slow'] }}"
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '1' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allcentris
                    data:
                      brightness_step: -20
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '2' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.hue_color_lamp_1
                    data:
                      brightness_step: -20
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '3' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.table
                    data:
                      brightness_step: -20
                      transition: 1
              - conditions:
                  - condition: template
                    value_template: >-
                      {{
                      states('input_text.philips_hue_dial_switch_last_pressed')
                      == '4' }}
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.allhue
                    data:
                      brightness_step: -20
                      transition: 1
            default:
              - service: light.turn_on
                target:
                  entity_id: all
                data:
                  brightness_step: -20
                  transition: 1
mode: parallel
max: 10

alias: Philips Hue Dial Switch juste bouton
description: Update last pressed button
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/hue_tap_dial_switch/action
condition:
  - condition: template
    value_template: "{{ 'dial' not in trigger.payload }}"
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_1_press_release' }}"
            alias: Button 1 Press/Release
        sequence:
          - service: light.toggle
            target:
              entity_id: light.allcentris
            data: {}
          - service: input_text.set_value
            data:
              value: "1"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_1_hold' }}"
            alias: Button 1 Hold
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.salon_lumiere_naturelle
            data: {}
          - service: input_text.set_value
            data:
              value: "1"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_2_press_release' }}"
            alias: Button 2 Press/Release
        sequence:
          - service: light.toggle
            target:
              entity_id: light.hue_color_lamp_1
            data: {}
          - service: input_text.set_value
            data:
              value: "2"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_2_hold' }}"
            alias: Button 2 Hold
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.salon_concentration
            data: {}
          - service: input_text.set_value
            data:
              value: "2"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_3_press_release' }}"
            alias: Button 3 Press/Release
        sequence:
          - service: light.toggle
            target:
              entity_id: light.table
            data: {}
          - service: input_text.set_value
            data:
              value: "3"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_3_hold' }}"
            alias: Button 3 Hold
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.salon_hocus_pocus
            data: {}
          - service: input_text.set_value
            data:
              value: "3"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_4_press_release' }}"
            alias: Button 4 Press/Release
        sequence:
          - service: light.toggle
            target:
              entity_id: light.allhue
            data: {}
          - condition: template
            value_template: "{{ is_state('light.centris_centre', 'on') }}"
          - service: input_text.set_value
            data:
              value: "4"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
      - conditions:
          - condition: template
            value_template: "{{ trigger.payload == 'button_4_hold' }}"
            alias: Button 4 Hold
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.salon_festive_fun
            data: {}
          - service: input_text.set_value
            data:
              value: "4"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
mode: parallel
max: 10

I can’t figure out the double press, and the single one doesn’t work with this code. I can’t find where my error is. If someone could give me advice on where the error might be, I have error logs for data values every time it runs, and the code stops even though my counter is incrementing, and the input text corresponds to the value changes, but it won’t execute the actions. Thank you.

alias: Philips Hue Dial Switch double action 2
description: ""
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/hue_tap_dial_switch/action
    alias: Button
    id: button
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.payload in
              ['button_1_press_release','button_2_press_release','button_3_press_release','button_4_press_release','button_1_hold',
              'button_2_hold' ,'button_3_hold' , 'button_4_hold'] }}
        alias: Update Last Pressed
        sequence:
          - if:
              - condition: template
                value_template: >-
                  {% set s = trigger.payload.split('_')[1] %} {{ s !=
                  states('input_text.philips_hue_dial_switch_last_pressed') }}
            then:
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.philips_hue_dial_switch_button_counter
            alias: Prevent different buttons to be registered as double press
          - service: input_text.set_value
            data:
              #value: 1
              value: "{% set s = trigger.payload.split('_')[1] %} {{ 's' }}"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
            alias: Update the input text helper with the last pressed button number
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.philips_hue_dial_switch_button_counter
            alias: Increase the counter helper with 1
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 500
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.payload in ['button_1_press_release',
              'button_2_press_release','button_3_press_release',
              'button_4_press_release', 'button_1_hold', 'button_2_hold' ,
              'button_3_hold' , 'button_4_hold'] }}
          - condition: numeric_state
            entity_id: counter.philips_hue_dial_switch_button_counter
            above: 1
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ 'button_1_press_release' == trigger.payload }}"
                    alias: Double press button 1
                sequence:
                  - service: light.toggle
                    target:
                      entity_id: light.hue_go_1
                    data: {}
              - conditions:
                  - condition: template
                    value_template: "{{ 'button_2_press_release' == trigger.payload }}"
                    alias: Double press button 2
                sequence:
                  - service: light.toggle
                    target:
                      entity_id: light.hue_go_2
                    data: {}
              - conditions:
                  - condition: template
                    value_template: "{{ 'button_3_press_release' == trigger.payload }}"
                    alias: Double press button 3
                sequence:
                  - service: light.toggle
                    target:
                      entity_id: light.buffet
                    data: {}
              - conditions:
                  - condition: template
                    value_template: "{{ 'button_4_press_release' == trigger.payload }}"
                    alias: Double press button 4
                sequence:
                  - service: light.toggle
                    target:
                      entity_id: light.hue_derriere_ampli_salon
                    data: {}
      - conditions:
          - condition: template
            value_template: "{{ 'button_1_press_release' == trigger.payload }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.allcentris
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ 'button_2_press_release' == trigger.payload }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.hue_color_lamp_1
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ 'button_3_press_release' == trigger.payload }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.table
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ 'button_4_press_release' == trigger.payload }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.allhue
            data: {}
  - service: counter.reset
    target:
      entity_id: counter.philips_hue_dial_switch_button_counter
    data: {}
  - service: input_text.set_value
    data: {}
mode: parallel
max: 10

This morning, I went shopping and bought a Home Assistant SkyConnect and installed Zigbee2MQTT aside Phoscon specifically to rewrite this automation for all you Z2M users. I’ve also updated the blog post on smarthomegeeks.io. Enjoy:

alias: Philips Hue Dial Switch (Zigbee2MQTT)
description: ""
trigger:
  - alias: Button
    platform: event
    event_data:
      entity_id: sensor.hue_tap_dial_switch_action
    event_type: state_changed
    id: button
condition:
  - condition: template
    value_template: "{{ trigger.event.data.new_state.state is match('^(dial_rotate_|button_[1-4]_(press|hold))') and trigger.event.data.new_state.state != '' }}"
action:
  - choose:
      - conditions:
          - alias: Update Last Pressed
            condition: template
            value_template: "{{ trigger.event.data.new_state.state is match('^button_[1-4]_press$') }}"
        sequence:
          - alias: Prevent different buttons to be registered as double press
            if:
              - condition: template
                value_template: "{{ trigger.event.data.new_state.state | regex_replace(find='[^1-4]', replace='') != states('input_text.philips_hue_dial_switch_last_pressed') }}"
            then:
              - service: counter.reset
                data: {}
                target:
                  entity_id: counter.philips_hue_dial_switch_button_counter
                enabled: true
            enabled: true
          - service: input_text.set_value
            data:
              value: "{{ trigger.event.data.new_state.state | regex_replace(find='[^1-4]', replace='') }}"
            target:
              entity_id: input_text.philips_hue_dial_switch_last_pressed
            alias: Update the input text helper with the last pressed button number
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.philips_hue_dial_switch_button_counter
            alias: Increase the counter helper with 1
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: counter.reset
            data: {}
            target:
              entity_id: counter.philips_hue_dial_switch_button_counter
            alias: Reset the counter helper
            enabled: true
      - conditions:
          - alias: Double xxx2 event
            condition: template
            value_template: "{{ trigger.event.data.new_state.state is match('button_[1-4]_press_release') }}"
          - condition: numeric_state
            entity_id: counter.philips_hue_dial_switch_button_counter
            above: 1
        sequence:
          - choose:
              - conditions:
                  - alias: Double press button 1
                    condition: template
                    value_template: "{{ trigger.event.data.new_state.state == 'button_1_press_release' }}"
                sequence: []
              - conditions:
                  - alias: Double press button 2
                    condition: template
                    value_template: "{{ trigger.event.data.new_state.state == 'button_2_press_release' }}"
                sequence: []
              - conditions:
                  - alias: Double press button 3
                    condition: template
                    value_template: "{{ trigger.event.data.new_state.state == 'button_3_press_release' }}"
                sequence: []
              - conditions:
                  - alias: Double press button 4
                    condition: template
                    value_template: "{{ trigger.event.data.new_state.state == 'button_4_press_release' }}"
                sequence: []
    default:
      - alias: Single xxx2 event
        if:
          - condition: template
            value_template: "{{ trigger.event.data.new_state.state is match('button_[1-4]_press_release') }}"
        then:
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 250
          - if:
              - condition: numeric_state
                entity_id: counter.philips_hue_dial_switch_button_counter
                above: 1
            then:
              - stop: Double tap detected
      - service: counter.reset
        data: {}
        target:
          entity_id: counter.philips_hue_dial_switch_button_counter
        enabled: true
      - choose:
          - conditions:
              - condition: state
                entity_id: input_text.philips_hue_dial_switch_last_pressed
                state: "1"
              - condition: template
                value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_') }}"
            sequence:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_left') }}"
                    sequence: []
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_right') }}"
                    sequence: []
          - conditions:
              - condition: state
                entity_id: input_text.philips_hue_dial_switch_last_pressed
                state: "2"
              - condition: template
                value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_') }}"
            sequence:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_left') }}"
                    sequence: []
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_right') }}"
                    sequence: []
          - conditions:
              - condition: state
                entity_id: input_text.philips_hue_dial_switch_last_pressed
                state: "3"
              - condition: template
                value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_') }}"
            sequence:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_left') }}"
                    sequence: []
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_right') }}"
                    sequence: []
          - conditions:
              - condition: state
                entity_id: input_text.philips_hue_dial_switch_last_pressed
                state: "4"
              - condition: template
                value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_') }}"
            sequence:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_left') }}"
                    sequence: []
                  - conditions:
                      - condition: template
                        value_template: "{{ trigger.event.data.new_state.state is match('^dial_rotate_right') }}"
                    sequence: []
          - conditions:
              - alias: Button 1 Single Click
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_1_press_release' }}"
            sequence: []
          - conditions:
              - alias: Button 1 Hold
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_1_hold' }}"
            sequence: []
          - conditions:
              - alias: Button 2 Single Click
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_2_press_release' }}"
            sequence: []
          - conditions:
              - alias: Button 2 Hold
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_2_hold' }}"
            sequence: []
          - conditions:
              - alias: Button 3 Single Click
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_3_press_release' }}"
            sequence: []
          - conditions:
              - alias: Button 3 Hold
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_3_hold' }}"
            sequence: []
          - conditions:
              - alias: Button 4 Single Click
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_4_press_release' }}"
            sequence: []
          - conditions:
              - alias: Button 4 Hold
                condition: template
                value_template: "{{ trigger.event.data.new_state.state == 'button_4_hold' }}"
            sequence: []
        enabled: true
mode: parallel
max: 10
3 Likes

Thank you very much. I had an issue with my direct MQTT trigger, but it works better when passing through the Home Assistant sensor. In any case, thank you very much. However, I think there might be an issue with the “hold” functionality because it seems to filter it out and only lets the “release” events pass through, if I’m not mistaken. The double click works great, though. Thanks again, you’re amazing!

I think you need to make this small correction to the trigger. With this, everything works perfectly for me

    value_template: >-
      {{ trigger.event.data.new_state.state is match('^(dial_rotate_|button_[1-4]_(press|hold))') and
      trigger.event.data.new_state.state != '' }}
1 Like

Thanks for the feedback, I’ve corrected the automation.

1 Like

Thank you to you especially.

For the light adjustment, what parameters did you set to make it smooth? I have Hue lights controlled by the Hue Bridge, and it works fine. I kept my three speed settings in my dial code, but I might switch to just one speed if I find a value that suits me

Within the Phoscon automation, I do it like this:

              - service: light.turn_on
                data:
                  brightness_step: >
                    {% set adjustment = trigger.event.data.rotation / 2 | round() %} {% set current = state_attr('light.lamp','brightness') %} {% if current + adjustment < 1 -%}
                      {{ 1 - current }}
                    {%- else -%}
                      {{  adjustment }}
                    {%- endif %}

I haven’t looked at the Z2M event. If it has a rotation value, you could use it to do the same.

Looks like you can use “Action time”:
image

1 Like

Thank you, I’ll test this during the day

1 Like

@ohthehugemanatee ohthehugemanatee Your post is almost a month old but I wanted to reply because I’m currently implementing ZHA automations for the Tap Dial Switch. There are ZHA blueprints available for this device and those work fine. My issue right now is that ZHA support for this device is limited. For example long press buttons are not available right now (see below). I also wanted to provide some feedback on your questions.

That is correct.

No.

Correct.

That is also correct. There is currently only 1 long press trigger which is the same for all buttons. This seems to be a ZHA problem. I have create a bug report for it here:
https://github.com/home-assistant/core/issues/104491

@starob thank you for replying! I had a busy month and couldn’t get back to it until now, so your post was timely even a month after my OP. :slight_smile:

I gather we have better working blueprints for Z2M. But all my other devices are already working through ZHA and AFAIK I can only use one or the other… and I don’t think I have it in me to completely redo all my devices just for the sake of the tap dial switch haha. Please correct me if I’m wrong!

Anyway it turned out to be pretty simple to take care of the different signals from the device. I added a step to map the values to a human-readable “button_pressed” local variable:

  - variables:
      map_buttons:
        "0": 2
        "1": 1
        "4": 4
        "5": 3
      pushed_button: "{{ map_buttons.get( trigger.event.data.params.scene_id | string, 0) }}"

Great: now I can refer to the pushed_button variable for an integer which is directly comparable to the number variable I have stored.

So now I have the capabilities I need for single and double press, at least. But the logic is confusing to me. How SHOULD this work? Here’s my faux code understanding… but this does not map to what I see in the example.

if (input_number.button_last_pressed == pushed_button && counter.button_counter > 0) {
  // This is a double press. 
  counter.button_counter++
  // Switch on pushed_button value for action.
  // stop execution
}
if (counter.button_counter == 0) {
  // This is a single press. 
  sleep 1
  if (counter.button_counter > 1) {
    // A second press happened in a parallel thread. Let the action happen there.
    // stop execution
  } 
  if (counter.button_counter == 1) {
    // no double press happened in a parallel thread.
    // Switch on pushed_button value for action.
    // stop execution
  } 

Thanks for the continued help!

You can run ZHA and Zigbee2MQTT in parallel if you have a second coordinator (e.g. Zigbee USB stick). Since I had a spare Zigbee stick available I did this to check the support of Z2M for this device and it is far better than ZHA. It supports every possible short & long press etc. Also the implementation to update the firmware of zigbee devices is much better in my opinion.

Since I have ZHA and Z2M running in parallel I might migrate to Z2M over time or just keep it running until ZHA improves the support for this device and then remove Z2M again.

I highly recommend transitioning to Z2M as it offers compatibility with a broader range of devices and more attributes per device. In my own setup, I’m using two coordinators to gradually migrate from deconz to Z2M. This approach allows me to switch one device at a time, ensuring my smart home remains functional during the transition. Investing in an additional Zigbee stick is worth the expense for a smoother changeover.

1 Like

That’s interesting advice… I have read elsewhere that ZHA is usually recommended because it has the weight of homeassistant’s community behind it and is easier to work with in the GUI. I’ve really appreciated how all my lights “just worked” so far. My only complaint is sometimes messages aren’t received by all devices… which I assume is a limitation of the zigbee protocol .

I sat down to think this through more in fake code, and came up with a simpler and more flexible version.

This version

  • only needs one global variable, a string that records the whole sequence
  • is (I think) easier for users to add custom behaviors, because there’s just one place for all your actions. New actions are as easy as e.g. if button_sequence == "222"
  • lets you respond to any combination of buttons and rotations. Want to respond to “1224, then fast left turn, then 321, then slow right turn”? You can do that.
// mock code only

GLOBAL button_sequence string = ""

function button_is_pushed(button_pushed string) {
  // No matter what, add to the sequence string

  // Separate rotation codes with a space.
  if (button_pushed == "R" || button_pushed == "L") {
    rotation = true;
  }
  if (rotation) {
    button_sequence = button_sequence + " ";
  }
  button_sequence = button_sequence + button_pushed;
  // Separate rotation codes with a space.
  if (rotation) {
    button_sequence = button_sequence + " ";
  }
  // Track the state of the button sequence locally to this run.
  local_button_sequence = button_sequence;

  
  // Wait 1 second and see if any further pushes have modified the sequence.
  sleep 1
  if (local_button_sequence != button_sequence) {
    // Another parallel run added to the button sequence. Let execution happen there.
    exit 0;
  }
  // Parse the string into an array for convenience.
  sequence_array = string_split(local_button_sequence, " ");

  /**
  * All your actions go here. 
  * You can use either the string version of the sequence (e.g. "1224 R34"),
  * or the array is easier when rotations are involved. (e.g. [ "1224", "R34"] )
  */
  // Example single tap.
  if (local_button_sequence == "1") {
    scene_trigger("living_room_overhead_light_on");
  } 
  // Example double tap.
  if (local_button_sequence == "11") {
    scene_trigger("living_room_all_lights_on");
  }
  // Example combination taps and rotation.
  if (sequence_array[0] == "1224" && substr(sequence_array[1], 0, 1) == "R" && sequence_array[2] = "4221") {
    text_to_speech("Access granted");
    automation_trigger("secret_lair_mode_activate");
  }
  
  // reset the button sequence.
  button_sequence = ""
}

I implemented it because I couldn’t resist. There’s only one example action at the moment. Maybe later I’ll update with some rotation examples and mixed buttons / rotations. But it’s all there… you just have to parse the array of inputs.

alias: My Philips button
description: |
  My version of the Philips button automation
trigger:
  - alias: Button
    platform: event
    event_data:
      device_id: f1d484eecfd7ae66406d537f38c66ebf
      cluster_id: 5
    event_type: zha_event
    id: button
  - alias: Rotation
    platform: event
    event_data:
      device_id: f1d484eecfd7ae66406d537f38c66ebf
      cluster_id: 8
    event_type: zha_event
    id: rotation
condition: []
action:
  - variables:
      map_buttons:
        "0": 2
        "1": 1
        "4": 4
        "5": 3
      map_rotation:
        "0": R
        "1": L
      pushed_button: "{{ map_buttons.get( trigger.event.data.params.scene_id | string, 0) }}"
      rotation_dir: "{{ map_rotation.get( trigger.event.data.params.step_mode | string) }}"
      rotation_dist: "{{ map_rotation.get( trigger.event.data.params.step_size | string) }}"
  - alias: Add pressed button to the sequence
    if:
      - condition: trigger
        id:
          - button
    then:
      - service: input_text.set_value
        data:
          value: >-
            {{ states('input_text.button_sequence') }}{{ pushed_button | string
            }}
        target:
          entity_id: input_text.button_sequence
  - alias: Add rotation to the sequence
    if:
      - condition: trigger
        id:
          - rotation
    then:
      - service: input_text.set_value
        data:
          value: >-
            {{ states('input_text.button_sequence') }} {{ rotation_dir }}{{
            rotation_dist }} 
        target:
          entity_id: input_text.button_sequence
  - variables:
      sequence_this_run: "{{ states('input_text.button_sequence') | string }}"
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - alias: Stop if global sequence has changed
    if:
      - alias: If global sequence has changed
        condition: template
        value_template: >-
          {{ states('input_text.button_sequence') | string != sequence_this_run
          | string }}
    then:
      - stop: >-
          Further button presses or rotations detected. Execution will continue
          in their thread.
    else:
      - service: input_text.set_value
        data:
          value: "{{ states('input_text.button_sequence') }} END"
        target:
          entity_id: input_text.button_sequence
        alias: End the sequence
  - variables:
      sequence_array: "{{ states('input_text.button_sequence').split(' ') }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ states('input_text.button_sequence') == '14421 END' }}"
        sequence:
          - service: media_player.play_media
            target:
              entity_id: media_player.living_room
            data:
              media_content_id: >-
                media-source://tts/tts.google_en_com?message=You+entered+the+secret+code%21&language=en
              media_content_type: provider
            metadata:
              title: You entered the secret code!
              thumbnail: https://brands.home-assistant.io/_/tts/logo.png
              media_class: app
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://tts
                - media_content_type: provider
                  media_content_id: >-
                    media-source://tts/tts.google_en_com?message=You+entered+the+secret+code%21&language=en
  - alias: Empty the global sequence
    service: input_text.set_value
    data:
      value: " "
    target:
      entity_id: input_text.button_sequence
mode: parallel
max: 10

Hi there,

I’m new to Home Assistant, but i Buoght a Philips Tap Dail switch.
Problem is i’m not able to add the switch to Home Assistant.

I’m using ZHA.
I tried to put the switch in pairing mode, and i got it to find a Signify Netherlands device. I know this must be the switch.
But all i can see is battery status and identify.
image

All other switches i added, show the different buttons.

Can you help in what i’m doing wrong?

Thanks in advance.
Dennis

1 Like

You need to create an automation that triggers on ZHA Events with the device id of your tap dial switch and then find out which button was pressed. Read this thread from the beginning.

1 Like

Zigbee2MQTT: 2417 devices (90%)
ZHA: 1187 devices (45%)
deCONZ: 979 devices (37%)

Source: https://zigbee.blakadder.com (13-12-2023)

I’ve observed that devices supported by Zigbee2MQTT offer a wider range of attributes compared to those supported by ZHA and deCONZ. Therefore, I definitely recommend considering a switch to Zigbee2MQTT.

Hello fleeman,
First of all, Thanks for your post and help for this automation with Mqtt.
Well, i’m a very very newsbie… Only 3 week i discover Home Assistant, the word Zigbee, Device, Entities, etc etc.
I try to use your code In HA but don’t arrive to execute a simple light on lol. Don’t know where to complete this in the yaml file…
1.My device Hue Philips is rename in “HueSwitch” - Model 8719514440937/8719514440999 ( Philips Hue Tap )
2.this one is “connected” with mqtt
3. I create your two Helper files “Philips Hue Dial Switch Last Pressed” and “Philips Hue Dial Switch button counter”
4. I create an automation and under the id i paste your code:

  • id: ‘1703697669883’
    alias: Philips Hue Dial Switch (Zigbee2MQTT)
    description: Teest
    trigger:…

Now, where i can add for this device “Zig” Zigbeemodel TS0505B ( TS0505B ) (controler for a led Strip Cool and White Led (Not RGB))
a/If press 1 time button 1 → Device “Zig” → Action “Toggle Col” (Toggle Switch)
b/If i Double Press Button 1 just after press 1–> And rotate Left (Down White Temperature - coolest). If i Rotate right(Up Warmest White temperature - Warmest ) on device Device “Zig”
c/If i Triple Press Button 1 just after press 1–> And rotate Left (Down Intensity). If i Rotate right(Increase Intensity) on device Device “Zig”

If you want, i also have a Sonoff Zbmini2 ( [ZBMINIL2]) which switch on/off a simple Bulb. May be we could start with this device with Button 2?

Sorry for my bad english and hope someone could help me.

Best regards

Also a newbie trying to follow this. I can create the helpers and copy and paste the automation code into a fresh automation. But now need a bit of direction as to what next.

Should i try and switch back to the UI interface or do i need to get my head round the YAML code and figure out how to edit to add my lights?

Guessing no way to spoon feed me with a blueprint I can import for this?

Maybe its out of my current expertise to get this working for me…

Thanks very much

1 Like

Update - found a blueprint. Not as cool as the routine in this thread but useable for a novice like me lol. Would be nice to combine / update this blueprint with the automation here (make it work with helpers). Then it would be more accessible / doable for newbies or people that are not comfortable with editing raw YAML code.