MQTT - Philips Hue Dimmer

Inspired by ZHA - Philips Hue Dimmer Switch, but implemented for zigbee2mqtt

Control lights with a Philips Hue Dimmer Switch.

The top “on” button will turn the lights on to the last set
brightness.

Dim up/down buttons will change the brightness using predefined
step and can be pressed and hold until the brightness is
satisfactory.

The bottom “off” button will turn the lights off.

Long Off or On press will set brightness to the maximum or to the
minimum.

blueprint:
  name: MQTT - Philips Hue Dimmer
  description: 'Control lights with a Philips Hue Dimmer Switch.


    The top "on" button will turn the lights on to the last set
    brightness.


    Dim up/down buttons will change the brightness using predefined
    step and can be pressed and hold until the brightness is
    satisfactory.


    The bottom "off" button will turn the lights off.


    Long Off or On press will set brightness to the maximum or to the
    minimum.
    '
  domain: automation
  input:
    dimmer:
      name: Philips Hue dimmer action sensor
      description:
        'This must be an "action" sensor provided by zigbee2mqtt. For
        example "sensors.living_dimmer_action"
        '
      selector:
        entity:
          domain: sensor
    light:
      name: Target light
      selector:
        entity:
          domain: light
    step:
      name: Dimming step in percent
      default: 25
      selector:
        number:
          min: 0.0
          max: 50.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
    lowest_brightness:
      name: Lowest brightness level
      description: 'Set this brightness level on long "Off" button press'
      default: 3
      selector:
        number:
          min: 1.0
          max: 50.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
trigger:
  platform: state
  entity_id: !input dimmer
action:
  - variables:
      command: "{{ trigger.to_state.attributes.action }}"
      step: !input step
      negative_step: "{{ -1 * (step | int) }}"
  - choose:
    - conditions: "{{ command == 'on-press' }}"
      sequence:
        - service: light.turn_on
          data_template:
            entity_id: !input light
    - conditions: "{{ command == 'off-press' }}"
      sequence:
        - service: light.turn_off
          data_template:
            entity_id: !input light
    - conditions: "{{ command == 'down-press' or command == 'down-hold' }}"
      sequence:
        - service: light.turn_on
          data_template:
            entity_id: !input light
            brightness_step_pct: "{{ negative_step }}"
            transition: 1
    - conditions: "{{ command == 'up-press' or command == 'up-hold' }}"
      sequence:
        - service: light.turn_on
          data_template:
            entity_id: !input light
            brightness_step_pct: "{{ step }}"
            transition: 1
    - conditions: "{{ command == 'on-hold' }}"
      sequence:
        - service: light.turn_on
          data_template:
            entity_id: !input light
            brightness: 255
            transition: 1
    - conditions: "{{ command == 'off-hold' }}"
      sequence:
        - service: light.turn_on
          data_template:
            entity_id: !input light
            brightness_pct: !input lowest_brightness
            transition: 1
4 Likes

Thanks a lot for the template, is that possible to control more than 1 light by the same remote? I have now create 2 same automation to achieve this. If it could be combined into one blueprint that will be perfect

Glad to hear my it is useful.
Yes it is possible, just add 2 or more lamps into a group.

I think you mean a Light Group and not a standard Group.

Lights in a standard group can only be turned on/off (you can’t control their brightness). In addition, the blueprint uses an Entity Selector filtered for light entities only, so it won’t display a Group for selection.

    light:
      name: Target light
      selector:
        entity:
          domain: light <------ Entity Selector for lights only.

Aaah, that’s why Alexa refuses to change brightness of my group. Other then that everything works (weird enough). I mean I can change brightness from Lovelace, and use the group in my blueprint. But (thanks to shitty Yeelight) I need to use this group via template

light: '{% if is_state(''binary_sensor.table_light_nightlight'', ''on'') %}
  group.living_nightlight {%- else %} group.living_light {% endif %}

  '

But template probably has nothing to do with the fact that it is working

Thank you, Yuri! I love these blueprints. Is there any chance you can add the possibility to change the color temperature with the Dimmer Switch like the default behavior of the Switch?

That is, if you continue to press the “On” button, you circulate between 4 different color temperatures.

1 Like

@yvolchkov is it possible to update the description with a button from this integration ? it’s about something like that Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled. because I don’t know how to implement it

Did we figure out how to make the dimmer buttons work with light groups?

Guys. Got a question here.
I have the new Dimmer switch, the round one.
My actions are not told with an ‘-’ but with an ‘_’.

So ‘on-press’ is ‘on_press’ and this blueprint does not work anymore.

Is it nessessary to update the blueprint? Or can the action be renamed?

Please Help here :hugs:

Hi @yvolchkov,

I absolutely love this blueprint. However, after using it a couple times I noticed that sometimes lights would not go on in the right color or the right brightness and I was also missing an option to set transition times. So I just dove straight into your code and added some stuff and it seems to work fine ;-).

Things I have added/ changed:

  • Set default brightness (to switch on from off-value) in % of maximum brightness (100%)
  • Set color_temperature in Mired for switching on from an off-state
  • Selector for transition time for off > on transitions (also used for the dimming transitions)
  • Selector for on > off transition time

Below is the blueprint you wrote with the changes I made to it included, so if you like you can incorporate them into the official one and call it a version 2.0 ;-). (Ain’t opensource great?)

blueprint:
  name: MQTT - Philips Hue Dimmer
  description: 'Control lights with a Philips Hue Dimmer Switch.


    The top "on" button will turn the lights on to the last set brightness.


    Dim up/down buttons will change the brightness using predefined step and can be
    pressed and hold until the brightness is satisfactory.


    The bottom "off" button will turn the lights off.


    Long Off or On press will set brightness to the maximum or to the minimum. '
  domain: automation
  input:
    dimmer:
      name: Philips Hue dimmer action sensor
      description:
        'This must be an "action" sensor provided by zigbee2mqtt. For example
        "sensors.living_dimmer_action" '
      selector:
        entity:
          domain: sensor
    light:
      name: Target light
      selector:
        entity:
          domain: light
    step:
      name: Dimming step in percent
      default: 25
      selector:
        number:
          min: 0.0
          max: 50.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
    default_brightness:
      name: Default brightness level
      description: Set this brightness level for switching on from off state
      default: 80
      selector:
        number:
          min: 1.0
          max: 100.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
    lowest_brightness:
      name: Lowest brightness level
      description: Set this brightness level on long "Off" button press
      default: 3
      selector:
        number:
          min: 1.0
          max: 50.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
    color_tmp:
      name: Color temp (in Mired)
      default: 320
      selector:
        number:
          min: 150.0
          max: 500.0
          mode: slider
          step: 1.0
          unit_of_measurement: "Mired"
    trans-on:
      name: transition for switching on as well as dimming
      default: 0
      selector:
        number:
          min: 0.0
          max: 5.0
          mode: slider
          step: 0.5
          unit_of_measurement: "s"
    trans-off:
      name: transition for switching off
      default: 1
      selector:
        number:
          min: 0.0
          max: 5.0
          mode: slider
          step: 0.5
          unit_of_measurement: "s"
  source_url: https://community.home-assistant.io/t/mqtt-philips-hue-dimmer/257551
trigger:
  platform: state
  entity_id: !input "dimmer"
action:
  - variables:
      command: "{{ trigger.to_state.attributes.action }}"
      step: !input "step"
      negative_step: "{{ -1 * (step | int) }}"
  - choose:
      - conditions: "{{ command == 'on-press' }}"
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: !input "light"
              transition: !input "trans-on"
              color_temp: !input "color_tmp"
              brightness_pct: !input default_brightness
      - conditions: "{{ command == 'off-press' }}"
        sequence:
          - service: light.turn_off
            data_template:
              entity_id: !input "light"
              transition: !input "trans-off"
      - conditions: "{{ command == 'down-press' or command == 'down-hold' }}"
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: !input "light"
              brightness_step_pct: "{{ negative_step }}"
              transition: !input "trans-on"
      - conditions: "{{ command == 'up-press' or command == 'up-hold' }}"
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: !input "light"
              brightness_step_pct: "{{ step }}"
              transition: !input "trans-on"
      - conditions: "{{ command == 'on-hold' }}"
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: !input "light"
              brightness: 255
              transition: !input "trans-on"
      - conditions: "{{ command == 'off-hold' }}"
        sequence:
          - service: light.turn_on
            data_template:
              entity_id: !input "light"
              brightness_pct: !input "lowest_brightness"
              transition: !input "trans-on"

1 Like

Hi @Igor01-Tech,

As far as I understand it, I believe that would be easy to fix (famous last words). If you look into the code of the blueprint there are these snippets like

      - conditions: "{{ command == 'on-press' }}"
        sequence:
          - service: light.turn_on

I believe (said the fool) that the easiest way to make the blueprint work with both the old and the new dimmers would be to change that snippet (and others like it) into something like:

      - conditions: "{{ command == 'on-press' or command == 'on_press' }}"
        sequence:
          - service: light.turn_on

So basically testing for both possibilities. But I am sure that there are readers here with a lot more experience and knowledge that might know a smarter way to do it. (maybe with a wildcard?)

It should be simple to test though if it works or not.

If you wish, you can shorten the template to this:

      - conditions: "{{ command in ['on-press', 'on_press'] }}"

You can go a step further and use the recently introduced match function to reduce it to this:

      - conditions: "{{ command is match('on[-_]press') }}"
1 Like

Like I said; “I am sure that there are readers here with a lot more experience and knowledge that might know a smarter way to do it.”.

I like it and you have given me some ideas for cleaning up/ consolidating some automations I (for now) have done in nodered. Thanks!

1 Like

Done and working. Thank you so much!!

1 Like

Hm, i´m getting the error below - any idea why this happens?
Trace:

Triggered by the state of sensor.dimmerschlafzimmerbett_action at 16. November 2021, 10:33:45
Stopped because only a single execution is allowed at 16. November 2021, 10:33:45 (runtime: 0.00 seconds)
this:
  entity_id: automation.mqtt_philips_hue_dimmer
  state: 'on'
  attributes:
    last_triggered: '2021-11-16T09:33:45.424749+00:00'
    mode: single
    current: 1
    id: '1637054301374'
    friendly_name: MQTT - Philips Hue Dimmer
  last_changed: '2021-11-16T09:30:48.069179+00:00'
  last_updated: '2021-11-16T09:33:45.425052+00:00'
  context:
    id: d899165e8c420e367666e35884370a23
    parent_id: 4c2d4c6d4facf4c299b6972a6e897b7e
    user_id: null
trigger:
  id: '0'
  idx: '0'
  platform: state
  entity_id: sensor.dimmerschlafzimmerbett_action
  from_state:
    entity_id: sensor.dimmerschlafzimmerbett_action
    state: on_press_release
    attributes:
      action: ''
      battery: 54
      linkquality: 36
      update:
        state: idle
      update_available: false
      friendly_name: DimmerSchlafzimmerBett action
      icon: mdi:gesture-double-tap
    last_changed: '2021-11-16T09:33:45.409524+00:00'
    last_updated: '2021-11-16T09:33:45.410990+00:00'
    context:
      id: 7251c6d07327e2b8dc297f99ab72f56b
      parent_id: null
      user_id: null
  to_state:
    entity_id: sensor.dimmerschlafzimmerbett_action
    state: ''
    attributes:
      action: ''
      battery: 54
      linkquality: 36
      update:
        state: idle
      update_available: false
      friendly_name: DimmerSchlafzimmerBett action
      icon: mdi:gesture-double-tap
    last_changed: '2021-11-16T09:33:45.412102+00:00'
    last_updated: '2021-11-16T09:33:45.412102+00:00'
    context:
      id: 236416e02abab2feee37598ddb0afe67
      parent_id: null
      user_id: null
  for: null
  attribute: null
  description: state of sensor.dimmerschlafzimmerbett_action

Sorry - a restart of Z2M and HA did fix my issue.

Thank you so much for this blueprint! This worked perfectly for me.

1 Like

Does this blueprint require any updates since breaking-changes of 22.3?

@yvolchkov I think this is broke. I’m getting this message when trying to run an automation from the script, "Stopped because only a single execution is allowed ".
Can you confirm if it’s still working or not?