Very Easy Custom Philips Hue Dimmer Switch for Z2M(Zigbee2MQTT)

Hi :slight_smile:

I made a very easy customizable Blueprint for the Philips Hue 4 Button Dimmer Switch.

Requirements:

  • Running MQTT Broker & MQTT Integration in Home Assistant
  • Running Zigbee2MQTT
  • Philips Hue Dimmer Switch

The Blueprint is using MQTT instead of HA Entity Attributes because it is faster.

You can give every button custom commands.

It is also possible to still use the dimmer function.
just giving the ‘hold’ action, the service ‘Light: Turn on’, choose your light entity & set ‘Brightness step’ to 20 and it will make it brighter the longer you hold.
You can also set it to ‘-20’ to dim the lights.

Have fun with it and be creative!

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

blueprint:
  name: Easy Customizable Controller Automation Blueprint for Hue Dimmer Switch in Zigbee2MQTT
  description:
    Controller automation for easy customizable Buttons with Philips Hue Dimmer Switch.



    ----------------------------------------------------------------------

    __-------->  !!!!!!!!! FRUSTRATION CAUTION !!!!!!!!!   <--------__

    ----------------------------------------------------------------------

    _______________________________██████

    _______________________________██████

    _______________________________██████

    ___________________________███████████

    ______________________________███████

    __________________________________██


    __Only define the 'Pressed' action when you need to!__

    __Use the 'Released' action instead!!!__

    __The 'pressed' action will also activate on 'Held'__

  domain: automation

  # Input from MQTT
  input:
    controller:
      name: (Zigbee2MQTT) Controller Name
      description: The name of the controller/Dimmer-Switch in Zigbee2MQTT (Not the name of your Home-Assistent Entity)
      default: ""
    base_topic:
      name: Root/Base mqtt topic from Zigbee2MQTT
      description: The Root/base topic as configured in Zigbee2MQTT (If you dont configured it you can leave the default --> "zigbee2mqtt")
      default: zigbee2mqtt

    # Define Actions to the Buttons
    on_press:
      name: Button On Pressed
      description: Action set to run, when the Button On is pressed even when hold.
      default: []
      selector:
        action: {}
    on_held:
      name: Button On Held
      description: Action set to run, when the Button On is held.
      default: []
      selector:
        action: {}
    on_released:
      name: Button On released
      description: Action set to run, when the Button On is released.
      default: []
      selector:
        action: {}
    on_hold_released:
      name: Button On Hold released
      description: Action set to run, when the Button On is pressed and is released after long press.
      default: []
      selector:
        action: {}
    up_pressed:
      name: Up Pressed
      description: Action set to run, when the Up pressed even when hold.
      default: []
      selector:
        action: {}
    up_held:
      name: Up Held
      description: Action set to run, when the Up is held.
      default: []
      selector:
        action: {}
    up_released:
      name: Up released
      description: Action set to run, when the Up is released.
      default: []
      selector:
        action: {}
    up_hold_released:
      name: Button Up Hold released
      description: Action set to run, when the Button Up is pressed and is released after long press.
      default: []
      selector:
        action: {}
    down_pressed:
      name: Down Pressed
      description: Action set to run, when the Down is pressed even when hold.
      default: []
      selector:
        action: {}
    down_held:
      name: Down Held
      description: Action set to run, when the Down is held.
      default: []
      selector:
        action: {}
    down_released:
      name: Down released
      description: Action set to run, when the Down is released.
      default: []
      selector:
        action: {}
    down_hold_released:
      name: Button Down Hold released
      description: Action set to run, when the Button Down is pressed and is released after long press.
      default: []
      selector:
        action: {}
    off_pressed:
      name: Off Pressed
      description: Action set to run, when the Off is pressed even when hold. (Off is also the "hue" button)
      default: []
      selector:
        action: {}
    off_held:
      name: Off Held
      description: Action set to run, when the Off is held. (Off is also the "hue" button)
      default: []
      selector:
        action: {}
    off_released:
      name: Off released
      description: Action set to run, when the Off is released. (Off is also the "hue" button)
      default: []
      selector:
        action: {}
    off_hold_released:
      name: Button Off Hold released
      description: Action set to run, when the Button Off is pressed and is released after long press. (Off is also the "hue" button)
      default: []
      selector:
        action: {}

# Link the Defined Action to the Buttons
mode: parallel
max: 6
trigger_variables:
  base_topic: !input base_topic
  controller: !input controller
trigger:
  - platform: mqtt
    topic: "{{ base_topic ~ '/' ~ controller }}"
action:
  - variables:
      controller: !input controller
  - choose:
      - conditions: "{{('hold' in trigger.payload_json.action) or ('release' in trigger.payload_json.action) or 'press' in trigger.payload_json.action}}"
        sequence:
          - choose:
              - conditions: '{{ trigger.payload_json.action == "on_press" or trigger.payload_json.action == "on-press" }}'
                sequence: !input on_press
              - conditions: '{{ trigger.payload_json.action == "up_press" or trigger.payload_json.action == "up-press" }}'
                sequence: !input up_pressed
              - conditions: '{{ trigger.payload_json.action == "down_press" or trigger.payload_json.action == "down-press" }}'
                sequence: !input down_pressed
              - conditions: '{{ trigger.payload_json.action == "off_press" or trigger.payload_json.action == "off-press" }}'
                sequence: !input off_pressed

              - conditions: '{{ trigger.payload_json.action == "on_hold" or trigger.payload_json.action == "on-hold" }}'
                sequence: !input on_held
              - conditions: '{{ trigger.payload_json.action == "up_hold" or trigger.payload_json.action == "up-hold" }}'
                sequence: !input up_held
              - conditions: '{{ trigger.payload_json.action == "down_hold" or trigger.payload_json.action == "down-hold" }}'
                sequence: !input down_held
              - conditions: '{{ trigger.payload_json.action == "off_hold" or trigger.payload_json.action == "off-hold" }}'
                sequence: !input off_held

              - conditions: '{{ trigger.payload_json.action == "on_press_release" or trigger.payload_json.action == "on-press-release" }}'
                sequence: !input on_released
              - conditions: '{{ trigger.payload_json.action == "up_press_release" or trigger.payload_json.action == "up-press-release" }}'
                sequence: !input up_released
              - conditions: '{{ trigger.payload_json.action == "down_press_release" or trigger.payload_json.action == "down-press-release" }}'
                sequence: !input down_released
              - conditions: '{{ trigger.payload_json.action == "off_press_release" or trigger.payload_json.action == "off-press-release" }}'
                sequence: !input off_released

              - conditions: '{{ trigger.payload_json.action == "on_hold_release" or trigger.payload_json.action == "on-hold-release" }}'
                sequence: !input on_hold_released
              - conditions: '{{ trigger.payload_json.action == "up_hold_release" or trigger.payload_json.action == "up-hold-release" }}'
                sequence: !input up_hold_released
              - conditions: '{{ trigger.payload_json.action == "down_hold_release" or trigger.payload_json.action == "down-hold-release" }}'
                sequence: !input down_hold_released
              - conditions: '{{ trigger.payload_json.action == "off_hold_release" or trigger.payload_json.action == "off-hold-release" }}'
                sequence: !input off_hold_released


4 Likes

Hi which version of the Hue switches does this work with?

Hi :slight_smile:
It should definitely work for these 2 remotes:

grafik
Model Number: 9290023986

grafik
Model Number: 324131137411

I don’t know if there are more model numbers for the “same” remote out there.

Just give it a try and let me know :wink:

Love the blueprint. Making setting up my Hue dimmer switch very straight forward.

Not sure if you already had a solution for cycling through predefined colors or temperatures. Here is another post I found helpful: Cycling between available colors - #5 by dbrunt

        sequence:
          - service: light.turn_on
            target:
              entity_id: light.bedroom_lamps
            data_template:
              color_temp: >
                {% if state_attr("light.bedroom_lamps","color_temp")|int > 350 %}
                333
                {% elif state_attr("light.bedroom_lamps","color_temp")|int > 332 %}
                285
                {% elif state_attr("light.bedroom_lamps","color_temp")|int > 284 %}
                244
                {% elif state_attr("light.bedroom_lamps","color_temp")|int > 243 %}
                165
                {% else %}
                370
                {% endif %}

Here is my automation for my Hue remote. Short press toggles bedroom lamps. Color & brightness controls bedroom lamps. Long press of on/off toggles ensuite bathroom lights.

alias: Philips Hue Switch
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: on_press_release
    discovery_id: 0x001788010926fed5 action_on_press_release
    id: on_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: up_press_release
    discovery_id: 0x001788010926fed5 action_up_press_release
    id: up_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: down_press_release
    discovery_id: 0x001788010926fed5 action_down_press_release
    id: down_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: off_press_release
    discovery_id: 0x001788010926fed5 action_off_press_release
    id: hue
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: on_hold_release
    discovery_id: 0x001788010926fed5 action_on_hold_release
    id: on_hold_release
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: on_press_release
        sequence:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: light.bedroom_lamps
                    state: "off"
                sequence:
                  - service: input_boolean.turn_off
                    target:
                      entity_id:
                        - input_boolean.circadian_lighting_bedroom
                        - input_boolean.circadian_lighting_brightness_bedroom
                        - input_boolean.circadian_lighting_color_bedroom
                        - input_boolean.bedroom_automatic_lights
                    data: {}
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 0
                      milliseconds: 300
                  - service: light.turn_on
                    data:
                      brightness: "{{ states(\"sensor.circadian_brightness\")|int(none) }}"
                      color_temp: "{{ states(\"sensor.circadian_color_temp\")|int(none) }}"
                    target:
                      entity_id: light.bedroom_lamps
              - conditions:
                  - condition: state
                    entity_id: light.bedroom_lamps
                    state: "on"
                sequence:
                  - service: light.turn_off
                    entity_id: light.bedroom_lamps
                    data: {}
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 1
                      milliseconds: 0
                  - service: input_boolean.turn_on
                    target:
                      entity_id:
                        - input_boolean.circadian_lighting_bedroom
                        - input_boolean.circadian_lighting_brightness_bedroom
                        - input_boolean.circadian_lighting_color_bedroom
                        - input_boolean.bedroom_automatic_lights
                    data: {}
      - conditions:
          - condition: trigger
            id: up_press_release
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id:
                - input_boolean.circadian_lighting_brightness_bedroom
            data: {}
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 200
          - service: light.turn_on
            data:
              brightness_step_pct: 10
            target:
              entity_id: light.bedroom_lamps
      - conditions:
          - condition: trigger
            id: down_press_release
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.circadian_lighting_brightness_bedroom
            data: {}
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 200
          - service: light.turn_on
            data:
              brightness_step: -10
            target:
              entity_id: light.bedroom_lamps
      - conditions:
          - condition: trigger
            id: hue
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.bedroom_lamps
            data:
              color_temp: >
                {% if state_attr("light.bedroom_lamps","color_temp")|
                int(default=0) > 350 %}333 {% elif
                state_attr("light.bedroom_lamps","color_temp")| int(default=0) >
                332 %}285 {% elif
                state_attr("light.bedroom_lamps","color_temp")| int(default=0) >
                284 %}244 {% elif
                state_attr("light.bedroom_lamps","color_temp")| int(default=0) >
                243 %}165 {% else %}370 {% endif %}
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.circadian_lighting_color_bedroom
      - conditions:
          - condition: trigger
            id: on_hold_release
        sequence:
          - choose:
              - conditions:
                  - condition: device
                    type: is_off
                    device_id: 9ffc5618d5df2d3a408bae4f98c2d2c4
                    entity_id: light.bathroom_light
                    domain: light
                sequence:
                  - service: input_boolean.turn_off
                    target:
                      entity_id: input_boolean.circadian_lighting_bathroom
                    data: {}
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 0
                      milliseconds: 200
                  - type: turn_on
                    device_id: 9ffc5618d5df2d3a408bae4f98c2d2c4
                    entity_id: light.bathroom_light
                    domain: light
              - conditions:
                  - condition: device
                    type: is_on
                    device_id: 9ffc5618d5df2d3a408bae4f98c2d2c4
                    entity_id: light.bathroom_light
                    domain: light
                sequence:
                  - type: turn_off
                    device_id: 9ffc5618d5df2d3a408bae4f98c2d2c4
                    entity_id: light.bathroom_light
                    domain: light
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 0
                      milliseconds: 200
                  - service: input_boolean.turn_on
                    target:
                      entity_id:
                        - input_boolean.circadian_lighting_bathroom
                        - input_boolean.circadian_lighting_brightness_bathroom
                        - input_boolean.circadian_lighting_color_bathroom
                    data: {}
            default: []
      - conditions:
          - condition: trigger
            id: hue_hold
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.circadian_lighting_brightness_bathroom
            data: {}
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 200
          - choose:
              - conditions:
                  - condition: sun
                    before: sunset
                    after: sunrise
                sequence:
                  - service: light.turn_on
                    target:
                      entity_id: light.bathroom_light
                    data:
                      brightness_step: -20
            default:
              - service: light.turn_on
                target:
                  entity_id: light.bathroom_light
                data:
                  brightness_step: 20
      - conditions:
          - condition: trigger
            id: up_hold
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.circadian_lighting_brightness_bathroom
            data: {}
          - device_id: 9ffc5618d5df2d3a408bae4f98c2d2c4
            domain: light
            entity_id: light.bathroom_light
            type: brightness_increase
      - conditions:
          - condition: trigger
            id: down-hold
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.circadian_lighting_brightness_bathroom
            data: {}
          - device_id: 9ffc5618d5df2d3a408bae4f98c2d2c4
            domain: light
            entity_id: light.bathroom_light
            type: brightness_decrease
    default: []
mode: queued
max: 10

Hi. Just bought this switch and I’m loving it. Deployed this blueprint and it works fantastic! I’m very new to HA so apologies if this question is a bit on the basic side.

I’ve programmed holding the the brightness buttons to increase and decrease the brightness accordingly. I was wondering if it was possible to decrease the time it would take in between brightness changes. Currently if I hold the brightness up button, the brightness increases in noticeable steps (about every 1 second or so) until max brightness. What I would like is for this brightness jump to be less noticeable for every time it fires but for the service/action (brightness change) to happen more rapidly.

I hope I’m making sense. This is the yaml for this automation in case it would help:

alias: Bathroom Dimmer Switch
description: ""
use_blueprint:
  path: patpac9/Hue_Dimmer_Switch_Easy_Custom_Buttons.yaml
  input:
    controller: Bathroom Dimmer Switch
    on_released:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.bathroom_lights
    off_hold_released:
      - service: scene.turn_on
        target:
          entity_id: scene.close_blinds
        metadata: {}
    up_held:
      - service: light.turn_on
        data:
          brightness_step: 20
        target:
          entity_id: light.bathroom_lights
    down_held:
      - service: light.turn_on
        data:
          brightness_step: -20
        target:
          entity_id: light.bathroom_lights
    off_released:
      - choose:
          - conditions:
              - condition: state
                entity_id: light.bathroom_lights
                attribute: color_temp
                state: 153
            sequence:
              - service: scene.turn_on
                target:
                  entity_id: scene.bathroom_lights_warm_white
                metadata: {}
          - conditions:
              - condition: state
                entity_id: light.bathroom_lights
                attribute: color_temp
                state: 370
            sequence:
              - service: scene.turn_on
                target:
                  entity_id: scene.bathroom_lights_cool_white
                metadata: {}

Hi :slight_smile:
I think this setting is best set in Zigbee2Mqtt direct.

Go to your device → specific settings and in there you can control the interval.
Never tried it but hope it works :wink:

Hi PatpaC! Thanks for the blueprint!

I tried fooling around on that specific setting page that you sent but it’s not working. Does a blueprint override the Settings of a specific z2m device? It seems like the case for this one. I’ve set it to the lowest interval and a different delta from the brightness change in the blueprint, but it seems like its following the blueprint.

Is there anything I’m missing?

Hmm hard to tell. I think it is more related to how often mqtt is sending. If you only want to bind this dimmer Switch to one zogbee light or
one zigbee group you can do this with z2m too.

I think you habe 2 options.

  1. Setting the interval not shorter but on larger steps.
  2. Use zigbee2mqtts bind function.
1 Like

@PatpaC Thanks for your blueprint.
I think HA is throwing a warning when using it.
Here’s my yaml:

alias: Vorraum Dimmerschalter Klingel (RingToOpen)
description: ""
use_blueprint:
  path: patpac9/Hue_Dimmer_Switch_Easy_Custom_Buttons.yaml
  input:
    controller: Vorraum Dimmerschalter Klingel
    on_held:
      - service: script.vorraum_klingel_gedruckt_ringtoopen
        data: {}
        enabled: false

and here is the log, with the warning at the end:

2023-09-08 22:03:33.301 INFO (MainThread) [homeassistant.components.automation.vorraum_klingel_gedruckt_ringtoopen] Vorraum Dimmerschalter Klingel (RingToOpen): Running automation actions

2023-09-08 22:03:33.302 INFO (MainThread) [homeassistant.components.automation.vorraum_klingel_gedruckt_ringtoopen] Vorraum Dimmerschalter Klingel (RingToOpen): Executing step setting variables

2023-09-08 22:03:33.302 WARNING (MainThread) [homeassistant.helpers.script] Error in 'choose[0]' evaluation: In 'template' condition: TypeError: argument of type 'NoneType' is not iterable

The warning is throwed directly after restarting HA and during the day.
When i disable the automation the issue is gone.

It seems an issue with the choose template.
Any hint’s i can solve it?

thx

Shouldnt the choose not be like:

  - choose:
      - conditions:
          - condition: template
            value_template: "{{ True }}"
          - condition: template
            value_template: "{{ True }}"
        sequence: ...

PS.: dont get me wrong i am not an yaml/template expert :slight_smile:
Just guessing what yould lead to the warning.

thx

i have the same problem and message in the log viewer.
@PatpaC can you help us here?

@pOpY @bt1v1
Hmmm… I think this is mainly caused by the sluggishness of the automation and the too fast reset of the payload from the device.
NoneType is maybe bc the payload is already vanished when it tries to compare the payload with the values in the automation.

Simplified ~~~> a timing issue.

In z2mqtt I think you have an option to retain a payload for longer.
Can you try it? I sadly can’t now cause the remotes are in the rooms where my people are already sleeping :sweat_smile:

Sorry, don’t using the blueprint anymore.
Had it just for one automation, which throwed the warning. Since I removed it, the warnings are gone.
Sadly can’t test it anymore.

But thanks for your efforts!!!

Found the option. I have set it like this now. Is that ok? Will observe it.

Looks good. Hope it works for you :wink:

First of all, thanks for this blueprint!
I’m all new to HA and still trying to figure my devices out. I just came from enOcean PTM 215Z switch configuration and when setting up that i had some “problems” with the dimming decrease and increase wasn’t too smooth. I found some code inside that topic which led me to a smoother dimming.

So when I found this blueprint I used the same code for the hold function, but here it’s stepping. Its like it decrease or increase brightness for 3 seconds, then hold a very short pause and then do it again for 3 seconds until light is either off or on full brightness. Can anyone maybe tell me what the problem could be and a possible solution?

Here is my code.

alias: Auto - Hue Dimmer Switch
description: ""
use_blueprint:
  path: patpac9/Hue_Dimmer_Switch_Easy_Custom_Buttons.yaml
  input:
    controller: Switch Dimmer Guestroom
    on_press:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.guestroom_ceiling
    up_held:
      - service: mqtt.publish
        data:
          topic: zigbee2mqtt/Guestroom Ceiling/set
          payload: "{\"brightness_move_onoff\": 51}"
          qos: 0
          retain: false
    up_hold_released:
      - service: mqtt.publish
        data:
          topic: zigbee2mqtt/Guestroom Ceiling/set
          payload: "{\"brightness_move\": \"stop\"}"
          qos: 0
          retain: false
    down_held:
      - service: mqtt.publish
        data:
          topic: zigbee2mqtt/Guestroom Ceiling/set
          payload: "{\"brightness_move_onoff\": -51}"
          qos: 0
          retain: false
    down_hold_released:
      - service: mqtt.publish
        data:
          topic: zigbee2mqtt/Guestroom Ceiling/set
          payload: "{\"brightness_move\": \"stop\"}"
          qos: 0
          retain: false

I’ve also tried another code but it is still stepping in the brightness not that much but does still occurs. I can get it smoother if i put a higher transition value, but stepping is never fully removed.

alias: Auto - Hue Dimmer Switch
description: ""
use_blueprint:
  path: patpac9/Hue_Dimmer_Switch_Easy_Custom_Buttons.yaml
  input:
    controller: Switch Dimmer Guestroom
    on_press:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.guestroom_ceiling
    up_held:
      - service: light.turn_on
        data:
          brightness_step: 35
          transition: 1
        target:
          entity_id: light.guestroom_ceiling
    down_held:
      - service: light.turn_on
        data:
          brightness_step: -35
          transition: 1
        target:
          entity_id: light.guestroom_ceiling

Last I want to ask @PatpaC as author a question.

What are your reasons for not using the press and the release insted?

Unfortunately it didn’t help. Put it even higher? 20 seconds?

“Error in ‘choose[0]’ evaluation: In ‘template’ condition: TypeError: argument of type ‘NoneType’ is not iterable”

Any idea on how double/triple/quadruple presses could be implemented?

1 Like

For some reason it is not working for me.

If I look at the topic settings (settings>> MQTT>> basic topic) it says zigbee2mqtt so that is default like the blueprint.
Then I entered the friendly name of the device (in this case, Dimmer livingroom)

And then in entered a very normal call service toggle light option in the “release” section. But nothing happens.

Am I doing something wrong here?