Here is a good method for dimming lights in Deconz

I made an update of my original post above showing how to do the same function using the new HA version 0.113 automation features. Now you can do is all with one automation which makes it simpler to overview and maintain.

Since I posted my original post I have put all HA config on github. You can find more examples there using the dimming method with deconz

4 Likes

I was given this little simplification which I added to my original post

The stop condition can be

      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event in ( 2003, 3003 ) }}"

A little more simple.

Thanks for sharing @KennethLavrsen , thatā€™s really cool and just want I needed! Reduced 5 individual scripts down to one and I had got stuck on the stop dimming bit! Thanks againā€¦

Iā€™ve changed this to ā€œā€¦ not in ( 2001, 3001 )ā€¦ā€ this seems a bit more reliable. Some times I had that the automation kept dimming even after i stopped turning.

Thank you.
Your updated method is a showcase example to achieve a much sort after automation -it should be stickied somewhere.

I just want to say thank you!

This works perfect for the application i wanted.

I use ESPhome device to directly call the deconz.configure service calls.
Now my wifi wall switches can dim my zigbee lights.

@KennethLavrsen Can you help me figure out why this isnā€™t working:

alias: Test deConz Event from IKEA button_switch
description: ''
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: tradfri_on_off_switch
      event: template
      value_template: "{{ trigger.event.data.event in ( 1002, 1001 ) }}"
condition: []
action:
  - service: homeassistant.turn_on
    data: {}
    entity_id: light.pg_living_room
mode: single

If I just use event: 1002 and remove the templating, it works perfect.
But I want it to perform the same action whether its an on button press or off button press.
I know I could just make an additional trigger, but Iā€™m pursuing this in order to learn.

Move the template to the condition, you canā€™t template the event like this.

trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: tradfri_on_off_switch
condition:
  condition: template
  value_template: "{{ trigger.event.data.event in [1002, 1001] }}"

or shorter:

condition:
  - "{{ trigger.event.data.event in [1002, 1001] }}"

Fantastic! Thank you so much.
But did you mean; ā€œYou canā€™t template an event like thisā€ or did you mean; ā€œYou canā€™t template an event at allā€ ?

@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?