[HELP] Need some clarifications on Automations

Hi,

I have a IKEA Tradfri dimmer connected through deCONZ that is used to control a Z-Wave in-wall dimmer.

I have some automation rules to make it work but would like some input on how they behave.

Here are the entries in question:

- alias: 'Turn On dimmer_chambre_maitres from dimmer when state is off'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: tradfri1
      event: 2002
  condition: 
    - condition: state
      entity_id: light.dimmer_chambre_maitres
      state: 'off'
  action:
    - service: homeassistant.turn_on
      entity_id: light.dimmer_chambre_maitres
      data:
        brightness: 30
      
- alias: 'Increase brightness of dimmer_chambre_maitres from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: tradfri1
      event: 2002
  condition: 
    - condition: state
      entity_id: light.dimmer_chambre_maitres
      state: 'on'
  action:
    - service: light.turn_on
      entity_id: light.dimmer_chambre_maitres
      data_template:
        brightness: >
          {% set bri = states.light.dimmer_chambre_maitres.attributes.brightness | int %}
          {{ [bri+30, 249] | min }}

- alias: 'Decrease brightness of dimmer_chambre_maitres from dimmer'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: tradfri1
      event: 3002
  condition: 
    - condition: state
      entity_id: light.dimmer_chambre_maitres
      state: 'on'
  action:
    - service: light.turn_on
      entity_id: light.dimmer_chambre_maitres
      data_template:
        brightness: >
          {% set bri = states.light.dimmer_chambre_maitres.attributes.brightness | int %}
          {{ [bri-30, 0] | max }}

The first rule(Turn On dimmer_chambre_maitres from dimmer when state is off) is bugging me.
It’s there to turn ON the dimmer when it is initially OFF because while OFF, the attribute “brightness” does not exist.
Once the Z-Wave dimmer is ON, attribute “brightness” is exposed and then rule #2(Increase brightness of dimmer_chambre_maitres from dimmer) takes over.

  • I would really like to combine the 2 first rules in a single one. I think it’s possible but my knowledge of writing automations is stivery limited.

  • Can a single “event_data” entry in a trigger have 2 event values? On Tradfri dimmers, event 1002 and 2002 are basically the same (same for 3002 and 4002) in my case. I would like to avoid duplicating the entire “trigger” statement in all those automations just to trigger on 2 different event values.
    I tried to write it like that but it didn’t work

    trigger:
      platform: event
      event_type: deconz_event
      event_data:
        id: tradfri1
        event: 
          - 1002
          - 2002
    
  • Finally, what is the normal range of “brightness” attribute in Home Assistant? Looks like it ranges from 0 to 255 but I could not find a definitive answer. I want to make sure the Tradfri dimmer covers the entire range of the Z-Wave dimmer.

Thanks!