alias: deCONZ Tap Dial Switch Automation
description: deCONZ - Philips Hue Tap Dial Switch by SmartHomeGeeks.io.
trigger:
- platform: event
  event_type: deconz_event
  event_data:
    id: hue_tap_dial_switch # Change to correct value
  id: button
- platform: event
  event_type: deconz_relative_rotary_event
  event_data:
    id: hue_tap_dial_switch # Change to correct value
  id: rotation
action:
- variables:
    input_text_var: input_text.philips_hue_dial_switch_last_pressed # Change to correct value
    counter_var: counter.philips_hue_dial_switch_button_counter # Change to correct value
  alias: Variables for input and counter helpers
- choose:
    - conditions:
        - condition: template
          value_template: "{% set s = trigger.event.data.event | string %} {{ s[-1] == '0' }}"
          alias: Update Last Pressed
      sequence:
        - if:
            - condition: template
              value_template: "{% set s = trigger.event.data.event | string %} {{ s[0] != states(input_text_var) }}"
          then:
            - service: counter.reset
              target:
                entity_id: "{{ counter_var }}"
          alias: Prevent different buttons to be registered as double press
        - service: input_text.set_value
          data:
            value: "{% set s = trigger.event.data.event | string %} {{ s[0] }}"
          target:
            entity_id: "{{ input_text_var }}"
          alias: Update the input text helper with the last pressed button number
        - service: counter.increment
          target:
            entity_id: "{{ counter_var }}"
          alias: Increase the counter helper with 1
        - delay:
            seconds: 1
        - service: counter.reset
          target:
            entity_id: "{{ counter_var }}"
          alias: Reset the counter helper
    - conditions:
        - condition: template
          value_template: "{% set s = trigger.event.data.event | string %} {{ s[-1] == '2' }}"
          alias: Double xxx2 event
        - condition: template
          value_template: "{{ states(counter_var) > '1' }}"
      sequence:
        - choose:
            - conditions:
                - condition: template
                  value_template: "{{ trigger.event.data.event | int(0) == 1002 }}"
                  alias: Double press button 1
              sequence: []
            - conditions:
                - condition: template
                  value_template: "{{ trigger.event.data.event | int(0) == 2002 }}"
                  alias: Double press button 2
              sequence: []
            - conditions:
                - condition: template
                  value_template: "{{ trigger.event.data.event | int(0) == 3002 }}"
                  alias: Double press button 3
              sequence: []
            - conditions:
                - condition: template
                  value_template: "{{ trigger.event.data.event | int(0) == 4002 }}"
                  alias: Double press button 4
              sequence: []
  default:
    - if:
        - condition: template
          value_template: "{% set s = trigger.event.data.event | string %} {{ s[-1] == '2' }}"
      then:
        - delay:
            milliseconds: 250
        - if:
            - condition: template
              value_template: "{{ states(counter_var) > '1' }}"
          then:
            - stop: Double tap detected
      alias: Single xxx2 event
    - choose:
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation clockwise after button 1 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '1' and trigger.event.data.rotation > 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation counter-clockwise after button 1 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '1' and trigger.event.data.rotation < 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation clockwise after button 2 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '2' and trigger.event.data.rotation > 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation counter-clockwise after button 2 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '2' and trigger.event.data.rotation < 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation clockwise after button 3 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '3' and trigger.event.data.rotation > 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation counter-clockwise after button 3 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '3' and trigger.event.data.rotation < 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation clockwise after button 4 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '4' and trigger.event.data.rotation > 0 }}"
          sequence: []
        - conditions:
            - condition: trigger
              id:
                - rotation
              alias: Rotation counter-clockwise after button 4 was pressed
            - condition: template
              value_template: "{{ states(input_text_var) == '4' and trigger.event.data.rotation < 0 }}"
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 1002 }}"
              alias: Button 1 Single Click
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 1001 }}"
              alias: Button 1 Hold
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 2002 }}"
              alias: Button 2 Single Click
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 2001 }}"
              alias: Button 2 Hold
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 3002 }}"
              alias: Button 3 Single Click
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 3001 }}"
              alias: Button 3 Hold
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 4002 }}"
              alias: Button 4 Single Click
          sequence: []
        - conditions:
            - condition: template
              value_template: "{{ trigger.event.data.event == 4001 }}"
              alias: Button 4 Hold
          sequence: []
mode: parallel
max: 10
max_exceeded: silent
