Here is a good method for dimming lights in Deconz

@Burningstone in my updated example in the original post someone kindly suggested the syntax

{{ trigger.event.data.event in ( 2003, 3003 ) }}

And you now show

{{ trigger.event.data.event in [ 2003, 3003 ] }}

Both seem to work.

What is most correct? and why does the round () instead of the square [] work?

As far as I know you can’t template the event at all.

() defines a set and [] defines list. The main difference is that sets can’t have duplicate items and are unordered. For this application (x in y) a set is more efficient, but it doesn’t matter at all for this kind of use cases.

These things that we talk about here (templates do’s ond don’ts, parenthesis, square brackets etc). How on earth can I learn these things? What is generic yaml syntax rules and what is HA-specific custom rules? To me, it’s a mystery how people manage to learn this. Especially templating stand out as a syntaxic chaos :open_mouth:
In my days we learned Fortran, Pascal and Cobol, and everything was based on simple distinct rules (building blocks) that never changed. The logic was based on a bottom-up abstraction. The HA docs appear to me as a top-down structure. My only hope is to find an example that somehow resembles as closely as possible, something that looks like what I’m trying to accomplish.
I then have to try to break it down to manageable pieces and trial’n’error along until it works (or until I give up - whatever comes first).

From the docs and using HA for 3+ years :slight_smile:

For your example, you can check the event trigger docs and see that there is nothing mentioned about a template for any field.

The difference between () and [], is basic python knowledge and Jinja is a subset of python.

This is a very good doc in regards to automations/scripts, with many examples:

Thank you :blush::+1:

Thanks for the explanation. Learned one more thing

The thing with searching for syntax symbols like a [ or ( is that you get too many hits.

Burningstones good answer helped me searching the documentation. So let me wrap it up for those that come by and read the thread.

So it seems in Jinja you can have lists like [alpha, bravo, zulu] and tuples like (alpha, bravo, zulu). So tuples, not sets. I cannot see that you can use Python syntax for sets which would be in {}. I tried and get an error and I cannot see it in the documentation either. It seems that tuplets may have a speed advantage over lists with the in but that would only be noticeable if the number of values was large. So for this specific use both will work.

The Jinja documentation reference for lists and tuples is here

https://jinja.palletsprojects.com/en/master/templates/#literals

The use of in is described here

https://jinja.palletsprojects.com/en/master/templates/#other-operators

2 Likes

Did you try to create a blueprint out of this?

I did it for myself you can see it here in case you are interested.

Thanks for your hint.
What I’m loking for
Basically what I’m focusing is to find a way to use the knx switch.
The best would be to be able to use directly the KNX address as input(trigger) to control a hue light.

Additional question hue
Using the hue zigbee accessories, do you have a better response time than using them via the hue bridge?

Swisscom
I see that you are a swisscom user, do you have a swisscomTV ? If yes did you manage to make it working via the Ubiquiti security gateway?

I had this in my AppDaemon app in the past, I wrote if for someone else as I’m not using KNX.

I use a ConBee II for ZigBee and everything is instant, because the changes are pushed to HA instead of pulled fron the Hue Bridge.

Yes, I use a Swisscom TV box, but I didn’tbother to put it behind the USG router, I just left it in the same subnet as the swisscom router, It’s the only device not behind the USG.

@daniwebCH have a look here :wink:
KNX - relative dimming for lights

1 Like

Can you still cast to the swisscomTV from your phone?

I don’t know, never used this, when I cast something from my phone I cast it to my Kodi player, but tbh I never use this.

Is it also possible to use this setup with a Shelly 1L as a switch? This device doesn’t support hold and release. What I want to do is start the dimming after a long press and stop the dimming after long pressing again. It’s that possible?

UPDATE: I think I figured out how the automation works; single transition (transition time being in tenths of a second) and is “cancelled” by the release of the button. However I am still looking for a way to have a lower threshold. My guess would be something along the lines of a calculation which passes “the current brightness level minus the minimum threshold” as the bri_inc value in the “dim down” option. But my scripting skills are not good enough to get it right just yet. Can anyone help out? My dimmers also have a physical button for setting the minimum level, but preferably I would like it to be part of the automation to avoid being dependent on physical access to the device (which are typically in the wall/ceiling in my house).

UPDATE2: I figured out how to set the minimum level by using a template in the “dim down” option. Something along these lines:

bri_inc: >
  {{ 50 - state_attr('light.light_source', 'brightness') | int }}

where 50 is my minimum level.

Original comment
This is great! Thanks for sharing. I have it working nicely with an IKEA Tradfri on/off switch.

However, I do have one wish, which I don’t have enough experience with automations/scripting to accomplish: When dimming down the lights, I would like it not to completely turn off my light, but have a configurable lower boundary which the automation will not go below, even if I keep the button pressed.

I have tried playing with the bri_inc value in the “dim down” option, but cannot seem to get it right. I might also need a bit of clarification about how this actually works.

As I understand it, the “dim down” condition is only hit once (when I press the switch down and hold it). And as such, I assumed that would start a brightness decrease with value -254 (as per the OP) with a transition time of 50 (ms?). Since the dimming definitely happens a lot slower than 50ms, I assumed it works by initializing a dimming process which dims in steps of -254 every 50ms thus resulting in a (relatively) smooth dim down operation. However, when I inspect the state of the light, I can see that it has a brightness value of 254 when brightest, and 0 when dimmed all the way down (i.e. to “off”).

So I cannot really understand how the automation works. Can someone please explain to me how it works?

Regarding having a lower limit, I can add a condition to the “dim down” option to only execute if the current brightness level is above a specific value, however, this only prevents the “dim down” option from executing if the brightness is below the condition value when the button is pressed (i.e. nothing happens), but if the brightness is above the condition value, then it dims all the way down. So I would love some guidance on how to achieve a lower boundary on the “dim down” option.

As mentioned I am using the IKEA Tradfri on/off switch, and therefore long-pressing the switch only produces one event when long press is detected, and another event when the switch is released (as opposed to continuous events while keeping it pressed).

Sorry, I got another noob question.

I tried adding the option to change the hue to Kenneth’s yaml. However, I failed miserably.

Here is my addition:

      # Hue Increase
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 5001 }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.badezimmer
              field: "/action"
              data: {"hue":10, "transitiontime":100}
      # Hue Decrease
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event == 4001 }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.badezimmer
              field: "/action"
              data: {"hue":-10, "transitiontime":100}
      # Stop hue increase/decrease 
      - conditions:
          - condition: template
            value_template:  "{{ trigger.event.data.event in ( 4003, 5003 ) }}"
        sequence:
          - service: deconz.configure
            data:
              entity: light.badezimmer
              field: "/action"
              data: {"hue":0}

When I press the “>” button on the Tradfri remote, this will change the hue until it reaches red. From then on, nothing will change. The “<” button does not seem to have any effect at all.

Similar to the bri_inc example in the original post, I also tried switching “hue” for “hue_inc”, e.g. data: {"hue_inc":10, "transitiontime":100}, to no avail.

Help would be highly appreciated.

Hi, the approach of Kenneth works perfectly! Thank you for this.
I think we can make it even more efficient:
The long-press event (1001) is generating its event every second until the release of the button is happening (1003) (i’m using the internal wall module). This means that the trigger to dim up is also fired every second in Home Assistant. One time should be enough, until the release-event is happening.

Is it possible to add a condition that makes sure that the long-press event (1001) is ignored if another long-press event (1001) was already observered in the last second? This would make zigbee network signalling even more efficient.

Hi,

I’ve solved this with two input booleans. See below the implemented optimization.

alias: alias of the automation
description: ""
trigger:
  - device_id: 5421144978f28dd04b59bb87a23843ad
    domain: deconz
    platform: device
    type: remote_button_long_press
    subtype: button_2
    id: dimmer
  - device_id: 5421144978f28dd04b59bb87a23843ad
    domain: deconz
    platform: device
    type: remote_button_long_release
    subtype: button_2
    id: dimmer stop
  - device_id: 5421144978f28dd04b59bb87a23843ad
    domain: deconz
    platform: device
    type: remote_button_long_press
    subtype: button_1
    id: brighter
  - device_id: 5421144978f28dd04b59bb87a23843ad
    domain: deconz
    platform: device
    type: remote_button_long_release
    subtype: button_1
    id: brighter stop
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: dimmer
          - condition: state
            entity_id: input_boolean.living_room_dimstatus
            state: "off"
        sequence:
          - parallel:
              - service: deconz.configure
                data:
                  entity: light.living_room_deconz
                  field: /action
                  data:
                    bri: 0
                    transitiontime: 50
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: input_boolean.living_room_dimstatus
      - conditions:
          - condition: trigger
            id: dimmer stop
        sequence:
          - parallel:
              - service: deconz.configure
                data:
                  entity: light.living_room_deconz
                  field: /action
                  data:
                    bri_inc: 0
              - service: input_boolean.turn_off
                data: {}
                target:
                  entity_id: input_boolean.living_room_dimstatus
      - conditions:
          - condition: trigger
            id: brighter
          - condition: state
            entity_id: input_boolean.living_room_dimstatus
            state: "off"
        sequence:
          - parallel:
              - service: deconz.configure
                data:
                  entity: light.living_room_deconz
                  field: /action
                  data:
                    bri: 254
                    transitiontime: 50
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: input_boolean.living_room_dimstatus
      - conditions:
          - condition: trigger
            id: brighter stop
        sequence:
          - parallel:
              - service: deconz.configure
                data:
                  entity: light.living_room_deconz
                  field: /action
                  data:
                    bri_inc: 0
              - service: input_boolean.turn_off
                data: {}
                target:
                  entity_id: input_boolean.living_room_dimstatus
    default: []
mode: queued
max: 10