Z2M - Philips Hue Tap Switch

I took the Blueprint that @harbri created for the Dimmer Switch and created a Hue Tap version out of it.

This blueprint will let you configure each button of a Philips Hue Tap Switch which is paired with Zigbee2MQTT.

Blueprint

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or import this Blueprint by using the forum topic URL:

blueprint:
  name: Z2M - Hue Tap Switch 4 buttons
  description: 'Use the individual buttons of the Hue Tap switch to control an action by a tap.'
  domain: automation
  input:
    dimmer:
      name: Hue Tap switch
      description: Hue Tap Switch to use (Zigbee2mqtt Action Sensor)
      selector:
        entity:
          domain: sensor
    button_1:
      name: Button Single Dot
      description: Action to run on click of single dot button
      default: []
      selector:
        action: null
    button_2:
      name: Button Two Dots
      description: Action to run on click of two dot button
      default: []
      selector:
        action: null
    button_3:
      name: Button Three Dots
      description: Action to run on click of three dot button
      default: []
      selector:
        action: null
    button_4:
      name: Button Four Dots
      description: Action to run on click of four dot button
      default: []
      selector:
        action: null
mode: restart
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input 'dimmer'
  attribute: action
action:
- variables:
    command: '{{ trigger.to_state.state }}'
- choose:
  - conditions:
    - '{{ command == ''press_1'' }}'
    sequence: !input button_1
  - conditions:
    - '{{ command == ''press_2'' }}'
    sequence: !input button_2
  - conditions:
    - '{{ command == ''press_3'' }}'
    sequence: !input button_3
  - conditions:
    - '{{ command == ''press_4'' }}'
    sequence: !input button_4
2 Likes

Hi :slight_smile:

Recently your blueprint doesn’t work anymore, so while searching I found this issue on the Z2M Github.

We need to change this :

  • toggle → press_1
  • recall_scene_0 → press_2
  • recall_scene_1 → press_3
  • recall_scene_2 → press_4
1 Like

Thanks for the heads-up. I just adjusted the code to match the change in z2m.

Let me know if you run into any other issues.

1 Like

I tried using this blueprint and it looks like it should work, but in the debug section I get the following:

Executed: May 21, 2022, 10:18:39 AM

Error: UndefinedError: 'dict object' has no attribute 'to_state'

Found the issue - Had to comment out the “attribute: action”

trigger:
- platform: state
  entity_id: !input 'dimmer'
  # attribute: action
2 Likes

Had to do the same after moving from Conbee stick to Sonoff Zigbee 3.0

Found the issue - Had to comment out the “attribute: action”

trigger:
- platform: state
  entity_id: !input 'dimmer'
  # attribute: action
2 Likes

Thank you for this! This fixed my problem with the blue print - I hope the OP can update it.

If anyone is having issues using this template with scenes or multiple lights since the last update.
Change mode: restart, to mode: queued.
Before I updated that value, I used to receive alot of “Stopped because of unknown reason “null”” errors.

This is what my blueprint looks like now:

blueprint:
  name: Z2M - Hue Tap Switch 4 buttons
  description: Use the individual buttons of the Hue Tap switch to control an action
    by a tap.
  domain: automation
  input:
    dimmer:
      name: Hue Tap switch
      description: Hue Tap Switch to use (Zigbee2mqtt Action Sensor)
      selector:
        entity:
          domain: sensor
          multiple: false
    button_1:
      name: Button Single Dot
      description: Action to run on click of single dot button
      default: []
      selector:
        action: {}
    button_2:
      name: Button Two Dots
      description: Action to run on click of two dot button
      default: []
      selector:
        action: {}
    button_3:
      name: Button Three Dots
      description: Action to run on click of three dot button
      default: []
      selector:
        action: {}
    button_4:
      name: Button Four Dots
      description: Action to run on click of four dot button
      default: []
      selector:
        action: {}
  source_url: https://community.home-assistant.io/t/z2m-philips-hue-tap-switch/329686
mode: queued
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input dimmer
#  attribute: action
action:
- variables:
    command: '{{ trigger.to_state.state }}'
- choose:
  - conditions:
    - '{{ command == ''press_1'' }}'
    sequence: !input button_1
  - conditions:
    - '{{ command == ''press_2'' }}'
    sequence: !input button_2
  - conditions:
    - '{{ command == ''press_3'' }}'
    sequence: !input button_3
  - conditions:
    - '{{ command == ''press_4'' }}'
    sequence: !input button_4

Hello,
I am very new here with zigbee2mqtt. As a stick I use the Sonof. I currently do not understand how I can connect the Hue Tap with zigbee2mqtt. Can you help me there?

How did you pair Phillips hue tap switch at first place? I am trying to pair the switch with my HA Yellow but with no luck. I know its green device, I have Hue lights in the same room, so if translation is needed, it should be performed fine.
What am I missing?
Thank you for help.

Thanks, this helped me also with the sonoff zigbee 3.0 stick

With the latest update for Z2M, actions (legacy) are no longer supported.
I have updated this blueprint to support the new trigger based events.

blueprint:
  name: Hue Tap Button Actions
  description: |
    This blueprint triggers a user-specified action when a button on a Hue Tap is pressed.
  domain: automation
  input:
    hue_tap:
      name: Hue Tap
      description: "The Hue Tap that triggers actions"
      selector:
        device: {}

    button_1_action:
      name: First Button Action
      description: "The action to execute when the first button is pressed."
      default: []
      selector:
        action: {}

    button_2_action:
      name: Second Button Action
      description: "The action to execute when the second button is pressed."
      default: []
      selector:
        action: {}

    button_3_action:
      name: Third Button Action
      description: "The action to execute when the third button is pressed."
      default: []
      selector:
        action: {}

    button_4_action:
      name: Fourth Button Action
      description: "The action to execute when the fourth button is pressed."
      default: []
      selector:
        action: {}

mode: queued

trigger:
- platform: device
  device_id: !input hue_tap
  domain: mqtt
  type: action
  subtype: press_1
- platform: device
  device_id: !input hue_tap
  domain: mqtt
  type: action
  subtype: press_2
- platform: device
  device_id: !input hue_tap
  domain: mqtt
  type: action
  subtype: press_3
- platform: device
  device_id: !input hue_tap
  domain: mqtt
  type: action
  subtype: press_4

condition: []

action:
  - choose:
      - conditions: "{{ trigger.payload == 'press_1' }}"
        sequence: !input button_1_action
      - conditions: "{{ trigger.payload == 'press_2' }}"
        sequence: !input button_2_action
      - conditions: "{{ trigger.payload == 'press_3' }}"
        sequence: !input button_3_action
      - conditions: "{{ trigger.payload == 'press_4' }}"
        sequence: !input button_4_action

I also had a play with this since the update to Zibee2MQTT v2.0.0 broke the original blueprint. Inspired by the Philips Hue Tap Dial Switch, I added double click. My solution is a little clunky and can probably be simplified and double click is not super easy to execute on the Philips Hue Tap Switch because of the long and heavy travel. But if you need more actions here is my blueprint:

blueprint:
  name: Zigbee2MQTT-v2-Philips-Hue-Tap-Switch
  author: LSchweickert
  description: Integrate Philips Hue Tap Switch into Home Assistant to create
    a powerful remote control, supporting single tap and double tap.
  domain: automation
  input:
    mqtt_topic:
      name: MQTT Topic
      description: Topic of the Philips Hue Tap Switch
      default: zigbee2mqtt/<device name>
    tap_counter:
      name: Counter Helper
      description: Create a counter helper within Home Assistant to monitor the number
        of button presses on the switch, distinguishing between single and multiple
        clicks. This helper can be used for various switches, provided that they are
        not pressed at the same time
      selector:
        entity:
          domain:
          - counter
          multiple: false
    last_pressed:
      name: Last Pressed Input Text Helper
      description: Create an input text helper within Home Assistant to keep track
        of the last button pressed. This will avoid double clicks with different buttons. **Each switch requires a unique
        helper!**
      selector:
        entity:
          domain:
          - input_text
          multiple: false
    button_1_single_press:
      name: Button 1 Single Press
      default: []
      selector:
        action: {}
    button_1_double_press:
      name: Button 1 Double Press
      default: []
      selector:
        action: {}
    button_2_single_press:
      name: Button 2 Single Press
      default: []
      selector:
        action: {}
    button_2_double_press:
      name: Button 2 Double Press
      default: []
      selector:
        action: {}
    button_3_single_press:
      name: Button 3 Single Press
      default: []
      selector:
        action: {}
    button_3_double_press:
      name: Button 3 Double Press
      default: []
      selector:
        action: {}
    button_4_single_press:
      name: Button 4 Single Press
      default: []
      selector:
        action: {}
    button_4_double_press:
      name: Button 4 Double Press
      default: []
      selector:
        action: {}
mode: parallel
max: 10
max_exceeded: silent
trigger:
- platform: mqtt
  topic: !input mqtt_topic
condition:
  - condition: template
    value_template: '{{ trigger.payload_json.action is match(''press_[1-4]'')}}'
action:
- variables:
    input_text_var: !input last_pressed
    counter_var: !input tap_counter
- sequence:
  - if:
    - condition: template
      value_template: '{{ trigger.payload_json.action | regex_replace(find=''[^1-4]'',
        replace='''') != states(input_text_var) }}'
    then:
    - service: counter.reset
      target:
        entity_id: '{{ counter_var }}'
  - service: input_text.set_value
    data:
      value: '{{ trigger.payload_json.action | regex_replace(find=''[^1-4]'', replace='''')
        }}'
    target:
      entity_id: '{{ input_text_var }}'
  - service: counter.increment
    target:
      entity_id: '{{ counter_var }}'
  - delay:
      milliseconds: 250
  - if:
    - condition: template
      value_template: '{{ states(counter_var) > ''1'' }}'
    then:
    - sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_1''
              }}'
          sequence: !input button_1_double_press
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_2''
              }}'
          sequence: !input button_2_double_press
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_3''
              }}'
          sequence: !input button_3_double_press
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_4''
              }}'
          sequence: !input button_4_double_press
      - service: counter.reset
        target:
          entity_id: '{{ counter_var }}'
      - stop: Double tap detected
  - if:
    - condition: template
      value_template: '{{ states(counter_var) != ''0'' }}'
    then:
    - sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_1''
              }}'
          sequence: !input button_1_single_press
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_2''
              }}'
          sequence: !input button_2_single_press
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_3''
              }}'
          sequence: !input button_3_single_press
        - conditions:
          - condition: template
            value_template: '{{ trigger.payload_json.action == ''press_4''
              }}'
          sequence: !input button_4_single_press
      - service: counter.reset
        target:
          entity_id: '{{ counter_var }}'

I’m so happy that you updated this blueprint! Thank you!! Both of you!!

I have been looking into rebuilding the buttons into these “normal” lights-switches that one can make “spring back”. The day I manage this blueprint will be gold!

More specifically looking into this video: https://www.youtube.com/watch?v=7yWqv_pn_Lc