Philips Hue dimmer switch + Zigbee2MQTT custom actions

USE the BLUEPRINT from 2nd POST

leaving this up for whomever might prefer the legacy version


This blueprint is for Hue Dimmer Switch (Philips 324131092621 control via MQTT | Zigbee2MQTT) and Zigbee2MQTT. I found other blueprints that control just lights, but I wanted one that allows you to choose your own action (which can also be a control of light) for each of the following events: on-press, on-hold, up-press, up-hold, down-press, down-hold, off-press, off-hold.

My personal setup uses the button presses/holds to do amongst others the following: Ceiling lamp On/Off, All lights On/Off, Projector/Media Player play/pause, Some lamp toggle on hold etc.

github gist here & import button: Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Zigbee2Mqtt Hue Dimmer Switch control
  description: ''
  domain: automation
  input:
    dimmer_action:
      name: Dimmer Switch Action sensor
      description: 'Select your "sensor.dimmer_action" entity that will control this automation.'
      selector:
        entity:
          domain: sensor
          integration: mqtt
    action_on_press:
      name: on-press
      description: select action to run when you press I
      selector:
        action:
    action_off_press:
      name: off-press
      description: select action to run when you press O
      selector:
        action:
    action_up_press:
      name: up-press
      description: select action to run when you press UP
      selector:
        action:
    action_down_press:
      name: down-press
      description: select action to run when you press DOWN
      selector:
        action:
    action_on_hold:
      name: on-hold
      description: select action to run when you hold I
      selector:
        action:
    action_off_hold:
      name: off-hold
      description: select action to run when you hold O
      selector:
        action:
    action_up_hold:
      name: up-hold
      description: select action to run when you hold UP
      selector:
        action:
    action_down_hold:
      name: down-hold
      description: select action to run when you hold DOWN
      selector:
        action:

trigger:
  - platform: state
    entity_id: !input dimmer_action
    attribute: action
    to: on-press
  - platform: state
    entity_id: !input dimmer_action
    attribute: action
    to: off-press
  - platform: state
    entity_id: !input dimmer_action
    attribute: action
    to: up-press
  - platform: state
    entity_id: !input dimmer_action
    attribute: action
    to: down-press
  - platform: state
    entity_id: !input dimmer_action
    to: up-hold
    attribute: action
  - platform: state
    entity_id: !input dimmer_action
    to: down-hold
    attribute: action
  - platform: state
    entity_id: !input dimmer_action
    to: on-hold
    attribute: action
  - platform: state
    entity_id: !input dimmer_action
    attribute: action
    to: off-hold
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: on-press
            attribute: action
        sequence:
          !input action_on_press
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: off-press
            attribute: action
        sequence:
          !input action_off_press
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: up-press
            attribute: action
        sequence:
          !input action_up_press
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: down-press
            attribute: action
        sequence:
          !input action_down_press
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: on-hold
            attribute: action
        sequence:
          !input action_on_hold
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: off-hold
            attribute: action
        sequence:
          !input action_off_hold
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: up-hold
            attribute: action
        sequence:
          !input action_up_hold
      - conditions:
          - condition: state
            entity_id: !input dimmer_action
            state: down-hold
            attribute: action
        sequence:
          !input action_down_hold
    default: []
mode: restart

You have to pick action for each event.If you don’t want to react to an event choose Delay of 0sec.

This is my very 1st blueprint, let me know how/if it does/doesn’t work for you :slight_smile:

I’ve updated the blueprint to utilize the new trigger id’s from HA 2021.7 + changed the way it reads the input.

If you disable Home Assistant legacy triggers in Z2M options this makes the sensor.dimmer_action disappear. The new version of the blueprint queries the Z2M mqtt topic directly and utilizes the new HA feature of trigger id’s to toggle actions.

Instead of sensor.dimmer_action entity the blueprint now asks for your MQTT Dimmer topic, which you can find here: Ha / configuration / devices / Your Dimmer MQTT device and click on the MQTT Info -

gist here & import button: Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.(requires at least HA 2021.7)

blueprint:
  name: Zigbee2Mqtt Hue Dimmer Switch control v2
  description: ''
  domain: automation
  input:
    dimmer_action:
      name: Dimmer MQTT topic
      description: 'type in your Dimmer MQTT topic (i.e. zigbee2mqtt/Dimmer/action)'
      selector:
        text:
    action_on_press:
      name: on-press
      description: select action to run when you press I
      selector:
        action:
    action_off_press:
      name: off-press
      description: select action to run when you press O
      selector:
        action:
    action_up_press:
      name: up-press
      description: select action to run when you press UP
      selector:
        action:
    action_down_press:
      name: down-press
      description: select action to run when you press DOWN
      selector:
        action:
    action_on_hold:
      name: on-hold
      description: select action to run when you hold I
      selector:
        action:
    action_off_hold:
      name: off-hold
      description: select action to run when you hold O
      selector:
        action:
    action_up_hold:
      name: up-hold
      description: select action to run when you hold UP
      selector:
        action:
    action_down_hold:
      name: down-hold
      description: select action to run when you hold DOWN
      selector:
        action:

trigger:
  - platform: mqtt
    topic: !input dimmer_action
    payload: on-press
    id: dimmer_on
  - platform: mqtt
    topic: !input dimmer_action
    id: dimmer_off
    payload: off-press
  - platform: mqtt
    topic: !input dimmer_action
    id: dimmer_up
    payload: up-press
  - platform: mqtt
    topic: !input dimmer_action
    id: dimmer_down
    payload: down-press
  - platform: mqtt
    topic: !input dimmer_action
    id: dimmer_on_hold
    payload: on-hold
  - platform: mqtt
    topic: !input dimmer_action
    payload: off-hold
    id: dimmer_off_hold
  - platform: mqtt
    topic: !input dimmer_action
    id: dimmer_up_hold
    payload: up-hold
  - platform: mqtt
    topic: !input dimmer_action
    payload: down-hold
    id: dimmer_down_hold

action:
  - choose:
      - conditions:
          - condition: trigger
            id: dimmer_on
        sequence:
          !input action_on_press
      - conditions:
          - condition: trigger
            id: dimmer_off
        sequence:
          !input action_off_press
      - conditions:
          - condition: trigger
            id: dimmer_up
        sequence:
          !input action_up_press
      - conditions:
          - condition: trigger
            id: dimmer_down          
        sequence:
          !input action_down_press
      - conditions:
          - condition: trigger
            id: dimmer_on_hold
        sequence:
          !input action_on_hold
      - conditions:
          - condition: trigger
            id: dimmer_off_hold
        sequence:
          !input action_off_hold
      - conditions:
          - condition: trigger
            id: dimmer_up_hold
        sequence:
          !input action_up_hold
      - conditions:
          - condition: trigger
            id: dimmer_down_hold
        sequence:
          !input action_down_hold
    default: []
mode: restart

Hi. I configured it and it does not work. I click any button and it does not do anything. I see that it is not even triggered.



Any idea why?

@lukasberan dimmer_action is obsolete and the blueprint in 1st post is no longer supported. Use the one from 2nd post and configure it with your dimmer mqtt topic instead of dimmer_action

1 Like

I have been trying to get this blueprint to work so I can use 1 automation isntead of one for each button of my dimmer switches.

Though nothing happens when i push the buttons

this is the start of the automation. I found the topic as descriped in the post.

Is there anything else I need to do?

Have a look into logs, it shouldn’t just fail silently. One thing to keep in mind, you have to define an action for EVERY press. For the ones you want to ignore choose Delay of 0 sec as an action. The action on the screenshot looks good, but I can’t see if you defined all the rest.

Thank you so very much for your fast answer!

Yes I have defined something for all presses. I cant save without that :slight_smile:

As for the logs. I am unsure what and where to look? I am very new with home assistant and trying to figure it all out as best I can.

I know there is a logbook
Im guessing that this is not what you are talking about since it seems to be more…top level if that makes any sense.

You can find the log in Configuration, then at bottom Settings, then at top Logs. Press some buttons on the dimmer and then refresh the log and see if anything pops up.

Also another thing I completely forgot about is you can see the trace of how the automation went and why it might have failed in Configuration / Automations, then click the little button here:

Nothing happens in logs, Nothing happens in automations.

Its like the call for the mqtt does not work at all.

I have mqtt and zigb2mqtt installed in docker. It works when I run it as 7 different automations where I call device and then up_press action etc.

I have no clue what I could be doing wrong. I tried restarting home assistant but with no luck at all :frowning:
Again 1 automation with your blueprint instead of 7 as I have now for each dimmer switch would have been soooo much better :slight_smile:

Hmm, strange that nothing is in the logs. Is there nothing at all in the automation trace? I.e. not even the first circle lit up?

Do you maybe have legacy triggers enabled in Zigbee2MQTT? You could try the older version of the blueprint from the 1st post (which requires the legacy trigger). The automation from 2nd post I made after I disabled all the legacy stuff in Z2M configuration.yaml like so:

  homeassistant_legacy_entity_attributes: false
  homeassistant_legacy_triggers: false
  legacy_api: false

Can you check if the payload is passed to the action topic with something like MQTT Explorer while pressing the dimmer buttons?

The automations that you made and are working, are they reacting to the same mqtt topic or what do you use as triggers for them?

Sorry for all the questions and not many solutions, but I’ll admit I’m sort of grasping at straws here, the blueprint automation is fairly simple and it should “just work”.

First of all there is no need to be sorry about anything! you are trying to help me with the information I am supplying you! And since I have no idea where to start, its very helpful with your questions to try and circle in on the issue.

I am so grateful for you wasting you’re time trying to help me out! :slight_smile:

  1. No Nothing shows up in automation. I dont think the topic thing is working correctly for me but I have no idea why.

  2. all those settings in my zigbee2mqtt configuration.yaml is set to false, still I can try out the old blueprint later and see if that does anything different :slight_smile: Not impossible something is setup wrongly there.

  3. I will try installing the mqtt explorer and look into it and let you know results.

4.The ones I made is working yes. for triggers i use “device and “on_press action” in trigger for instance.

Again thank you so much for wasting your time on me and grasping at straws. I will test the suggestions and come back to you later!

I have been messing around a bit with explorer, I dont really know what to look for.

BUT
I think I got working.
I made 1 automation using mqtt topic instead of device, and it worked. So I looked in the yaml and into your script yaml and found that where mine under payload said : on_press your script says on-press

buy changing that in your script it seems to work.

Glad you’re making progress. For me the “on_press action” trigger disappeared when I put all the legacy on false in Z2M config, which is why I made the 2nd blueprint. If you still have the action trigger from the dimmer the older blueprint from 1st post should work.
Not really sure why the payload has underscore instead of dash for you, but if that works, it should be as easy as changing the dash to underscore for every action.

Maybe you have slightly different model of dimmer? You can see here it’s dash for me:

and this is the back of the dimmer I have:

Good luck in getting it working!

I did get it all working now, by changing your blueprint to _ instead of - on the payloads.

Mine does have the same model# as you. Might be a firmware thing? They dont look the same on the back.

Anyway thank you so much for all your brilliant help! It is very very much appriciated! :smiley:

also how my explorer looks :slight_smile:

1 Like

Yeah, probably a firmware / model thing. But as long as you got it working all is well :wink:

Out of curiosity, what firmware does it show in Z2M OTA section for the dimmer? Mine shows:

I know there are 2 models of the same dimmer too, I think the newer one has round corners, the other one (like mine) have square corners.

Just can’t stop wondering why of all the people who clicked (and presumably successfully used) the blueprint, only your device sends the payload with underscore instead of dash.

Maybe because I’m in Europe ?

Looks identical to me, guess we’ll never know why. I though I’m in Europe too, but since I’m in UK I don’t even know where I am nowadays :laughing:

Edit: So far I only have 2 out of 3 dimmer switches in z2m, but they both use the _ instead of -

Ahh sorry
To me you are European :stuck_out_tongue_closed_eyes:

also my dimmer has other stickers then yours on back but same
Model number so no idea then
I thought it might have been because of different part of world :flushed:

I think I figured out the difference between your setup and mine.

I was running my mqtt in docker and my z2m in docker.
Now I got a new pi dedicated for home assistant and I installed the OS.

And would you look at that…the _ is now - :open_mouth: