Here is a good method for dimming lights in Deconz

Hi
I have been migrating all my lights from Philips Hue hub and over to Deconz (with Conbee II stick)
One of the things that puzzled me was how to get the same press and hold dimming of the lights.
In the Deconz documention there is an example of a method where you step up and down in brightness. That works but it is not as elegant as holding in the increase or decrease buttons and let go when you think the light is right.
But it is actually possible to implement this in Deconz. I have been finding bits and pieces of documentation here and there but not a full example. So here are TWO examples.

Before you start you need to define groups in the Deconz app. We are working with deconz.configure messages and they work on deconz objects.
So in Phoscon you create the groups. One for each room or function that you want to control with a dimmer switch. And then you put the lights in each group.
If you have a mix of dimmable lights and switches it is not a problem. The system is smart enough to ignore the brightness changes for switches but you can still turn the whole group on and off. So put all the lights in the group.
And Deconz allows that the same light is in multiple groups.

Then you either restart home assistant or go to the Developer Tools -> Services and run a deconz.device_refresh (no service data needed). This imports the new groups into Home Assistant where they will be created as for example light.bedroom

We also assume you have a dimmer switch like the 4-button Philips Hue switch paired and available in Home Assistant. Remember that dimmers are event devices. They create events when you press the buttons. You can see the event device id and event values in Developer Tools -> Events where you type in deconz_event and click Start Listening. And then just press the buttons and watch the events below

Now we need to create an Automation. I have my configuration.yaml a line that says

automation: !include_dir_merge_list automation

And I have created a directory called automation in which I have one file for each set of related automation. So I have one file for each dimmer that controls a group of lights.

The first example is a 4-button Philips Hue dimmer that controls the lights in my bedroom.
Short press on the ON button turns on the light at 50%. Long press 100%. And the OFF buttons turns all light off.
The increase and decrease buttons turn the light up and down.
The way it works it that pressing and holding the increase/decrease buttons actually turn the light up or down 254 steps relative to current brightness with a long transition time. When you release the button a stop signal is sent to the lights (increase with the value 0). If you want the light to change faster you just change the value 50 to something smaller. I experimented with the increment/decrement value and 255 does nothing. 254 is max.

- alias: 'Turn On Bedroom from dimmer normal'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bedroom_switch
      event: 1002
  action:
    - service: light.turn_on
      data:
        entity_id:
          - light.bedroom
        brightness_pct: 50


- alias: 'Turn On Bedroom from dimmer bright'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bedroom_switch
      event: 1001
  action:
    - service: light.turn_on
      data:
        entity_id:
          - light.bedroom
        brightness_pct: 100

- alias: 'Increase brightness Bedroom from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bedroom_switch
      event: 2001
  action:
    - service: deconz.configure
      data:
        entity: light.bedroom
        field: "/action"
        data: {"bri_inc":254, "transitiontime":50}

- alias: 'Decrease brightness Bedroom from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bedroom_switch
      event: 3001
  action:
    - service: deconz.configure
      data:
        entity: light.bedroom
        field: "/action"
        data: {"bri_inc":-254, "transitiontime":50}

- alias: 'Stop brightness Bedroom from dimmer'
  initial_state: 'on'
  trigger:
    - platform: event
      event_type: deconz_event
      event_data:
        id: bedroom_switch
        event: 2003
    - platform: event
      event_type: deconz_event
      event_data:
        id: bedroom_switch
        event: 3003
  action:
    - service: deconz.configure
      data:
        entity: light.bedroom
        field: "/action"
        data: {"bri_inc":0}
          
- alias: 'Turn Off Bedroom from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bedroom_switch
      event: 4002
  action:
    - service: light.turn_off
      entity_id:
          - light.bedroom

Next example is a Closet with only one lamp so I did not bother creating a group. When you use the deconz.configure on a light instead of a group the field has to be ‘state’ and not ‘action’!!

Here is the example

- alias: 'Turn On Closet from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: closet_switch
      event: 1002
  action:
    - service: light.turn_on
      data:
        entity_id:
          - light.closet
        brightness_pct: 100

- alias: 'Increase brightness Closet from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: closet_switch
      event: 2001
  action:
    - service: deconz.configure
      data:
        entity: light.closet
        field: "/state"
        data: {"bri_inc":254, "transitiontime":50}

- alias: 'Decrease brightness Closet from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: closet_switch
      event: 3001
  action:
    - service: deconz.configure
      data:
        entity: light.closet
        field: "/state"
        data: {"bri_inc":-254, "transitiontime":50}

- alias: 'Stop brightness Closet from dimmer'
  initial_state: 'on'
  trigger:
    - platform: event
      event_type: deconz_event
      event_data:
        id: closet_switch
        event: 2003
    - platform: event
      event_type: deconz_event
      event_data:
        id: closet_switch
        event: 3003
  action:
    - service: deconz.configure
      data:
        entity: light.closet
        field: "/state"
        data: {"bri_inc":0}
          
- alias: 'Turn Off Closet from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: closet_switch
      event: 4002
  action:
    - service: light.turn_off
      entity_id:
          - light.closet

Update showing how to do the same with the new automation features introduced with Home Assistant 0.113. It is same principle but now we can do all the functions with a single automation.

- alias: 'Bedroom Dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bedroom_switch
  action:
    - choose:
      # Normal ON dimmed
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 1002 }}"
        sequence:
          - service: light.turn_on
            data:
              entity_id:
                - light.bedroom
              brightness_pct: 50
      # Long press full brightness
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 1001 }}"
        sequence:
            - service: light.turn_on
              data:
                entity_id:
                  - light.bedroom
                brightness_pct: 100
      # Increase
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 2001 }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.bedroom
              field: "/action"
              data: {"bri_inc":254, "transitiontime":50}
      # Decrease
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 3001 }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.bedroom
              field: "/action"
              data: {"bri_inc":-254, "transitiontime":50}
      # Stop increase/decrease 
      - conditions:
          - condition: template
            value_template:  "{{ trigger.event.data.event in ( 2003, 3003 ) }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.bedroom
              field: "/action"
              data: {"bri_inc":0}
      # Off
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 4002 }}"
        sequence:
          - service: light.turn_off
            data:
              entity_id:
                - light.bedroom

      #default:

I hope this topic will be a good help to new and maybe also old Deconz users. Enjoy

Kenneth

36 Likes

With hass 0.99 you can select events as triggers in the automation gui. This will simplify how you select your different remote control triggers

Thank you Kenneth, works well. :+1:

Thanks, after a little trying and failing I got this to work perfect :slight_smile:

Using 254/-254 on both “bri_inc” and “transitiontime” got me the smoothest results.

Now, can I use my arrows like a color-wheel or somthing? :stuck_out_tongue:
image

kind of found a way, even if I don’t realy understand the values yet.

{
  "data": {
    "hue": 10,
    "transitiontime": 100
  },
  "entity": "light.zigbee_soverom",
  "field": "/action"
}

https://dresden-elektronik.github.io/deconz-rest-doc/lights/

1 Like

@KennethLavrsen thanks for sharing! What is the reason you create a group in Deconz instead of a light group in HA?

You’re using the same event (1002) for both ‘Turn On Bedroom from dimmer normal’ and ‘Turn On Bedroom from dimmer bright’, is that correct ?

The reason for using a Deconz group is that the deconz.configure service only works on either deconz lights or deconz groups.

1 Like

No it is not correct. I made a mistake which I later had to correct. The dimmer bright event code should be 1001 and not 1002. I will correct my posting

Looks good!

I didn’t have the patience to figure this out when I set up our dimmer this spring so I just used the Deconz/Phoscon GUI. Might give this a try though. Thanks for sharing!

I created an AppDaemon app that uses the Philips Hue Dimmer switch and applies this method for smooth dimming of the lights. It also adds the possibility to turn on/off other devices or make a service call when a button is pressed. In case someone is interested:

3 Likes

I´ve an Ikea Dimmer Switch Type E1743. On/Off works fine after I followed this tutorial. But how to dimm with this one? I already figured out the events for dimming an stop signals but cant get it to work.

What are you missing, it’s all right there. Can you show your current code please?

My code is the same as in the example. I get it yesterday also working with the 5 Button remote. Only the Dimmer Switch does not work at dimming.
I guess he needs a little adjustment.

switch_work_light_decrease_brightness.yaml

---
# Reduces the brightness of the worktop lighting.
# Devices:
#   Type: "Ikea Tradfri"
#     - Dimmer Switch
#     - Transformer

alias: worklight_dimmer_lights_decrease_brightness
initial_state: "on"
trigger:
  platform: event
  event_type: deconz_event
  event_data:
    id: ku_switch_worklight
    event: 2001
action:
  - service: deconz.configure
    data:
      entity: group.ku_group_work_light
      field: "/state"
      data: { "bri_inc": -254, "transitiontime": 50 }

switch_work_light_increase_brightness.yaml

---
# Increases the brightness of the worktop lighting.
# Devices:
#   Type: "Ikea Tradfri"
#     - Dimmer Switch
#     - Transformer

alias: worklight_dimmer_lights_crease_brightness
initial_state: "on"
trigger:
  platform: event
  event_type: deconz_event
  event_data:
    id: ku_switch_worklight
    event: 1001
action:
  - service: deconz.configure
    data:
      entity: group.ku_group_work_light
      field: "/state"
      data: { "bri_inc": 254, "transitiontime": 50 }

switch_work_light_off.yaml

---
# Switches the worktop lighting off.
# Devices:
#   Type: "Ikea Tradfri"
#     - Dimmer Switch
#     - Transformer

alias: worklight_dimmer_lights_off
initial_state: "on"
trigger:
  platform: event
  event_type: deconz_event
  event_data:
    id: ku_switch_worklight
    event: 2002
action:
  - service: light.turn_off
    data:
      entity_id: group.ku_group_work_light

switch_work_light_on.yaml

---
# Switches on the worktop lighting.
# Devices:
#   Type: "Ikea Tradfri"
#     - Dimmer Switch
#     - Transformer

alias: worklight_dimmer_lights_on
initial_state: "on"
trigger:
  platform: event
  event_type: deconz_event
  event_data:
    id: ku_switch_worklight
    event: 1002
action:
  - service: light.turn_on
    data:
      entity_id: group.ku_group_work_light
      brightness_pct: 100

switch_work_light_stop_brightness.yaml

---
# Stops the dimming of the worktop lighting.
# Devices:
#   Type: "Ikea Tradfri"
#     - Dimmer Switch
#     - Transformer

alias: worklight_dimmer_lights_stop_brightness
initial_state: "on"
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: ku_switch_worklight
      event: 1003
  - platform: event
    event_type: deconz_event
    event_data:
      id: ku_switch_worklight
      event: 2003
action:
  - service: deconz.configure
    data:
      entity: group.ku_group_work_light
      field: "/state"
      data: { "bri_inc": 0 }

edit: I also tried "field: “/state” and "field: “/action”

The deconz.configure service works only with deconz lights or deconz light groups, it does not work with groups created in home assistant.
Also note “field” must be “/action” if it is a light group and “/state” if it is a single bulb.

If you did not already create groups in phoscon, do this and then use these groups instead of “group.ku_group_work_light”. Groups created in phoscon exposed to home assistant will start with “light.” and the attribute “is_deconz_group” is true.

1 Like

Thank you. Now it works!

Is there any way to do this with regular Home Assistant switch?

I have a Deconz switch but a EspHome light.

No. This works only with deconz lights as the service is only available for deconz. Check out this app from @xaviml, it should cover your needs.

Thank you so much @KennethLavrsen! This is great. Saved me a lot of time.

Do someone knows how to translate all these code in Node Red (if possible) ?

I use deconz and i didn’t even bother with all the automations. I just use the Phoscon app to allocate dimmers to the light groups and do it that way.
If you are using Deconz you might and just want to dim hue globes that is easier.
Obviously if you want your hue dimmer to control non-zigbee lights, then the automations are needed.