Data template automation

Hi All,

Does anybody know how to get " states.[trigger.payload_json.entity_id].attributes.brightness " working?
entity_id is send as JSON in the payload so you can dim multiple lights with one automation

- alias: Dim light
  trigger:
  - platform: mqtt
    topic: /dimlight
  action:
  - service: light.turn_on
    data_template:
     entity_id: '{{ trigger.payload_json.entity_id }}'
     brightness_pct: '{{ states.[trigger.payload_json.entity_id].attributes.brightness + 5 }}'

Is entity_id inside your payload? If not…

- alias: Dim light
  trigger:
  - platform: mqtt
    topic: /dimlight
  action:
  - service: light.turn_on
    data_template:
     entity_id: '{{ trigger.entity_id }}'
     brightness_pct: '{{ states.[trigger.entity_id].attributes.brightness_pct + 5 }}'

That is also not going to work, I just used the [] to make clear what I needed to replace but that does not work and gives a invalid template error

Ah, nevermind i see the issue:

- alias: Dim light
  trigger:
  - platform: mqtt
    topic: /dimlight
  action:
  - service: light.turn_on
    data_template:
     entity_id: '{{ trigger.entity_id }}'
     brightness_pct: > 
       {% set domain, device = trigger.entity_id.split('.') %}
       {{ states[domain][device].attributes.brightness_pct + 5 }}

or

- alias: Dim light
  trigger:
  - platform: mqtt
    topic: /dimlight
  action:
  - service: light.turn_on
    data_template:
     entity_id: '{{ trigger.entity_id }}'
     brightness_pct: "{{ state_attr(trigger.entity_id,'brightness_pct') | int + 5 }}"

Thanks a lot, I got it working now with:

 - alias: Dim light
  trigger:
  - platform: mqtt
    topic: /dim
  action:
  - service: light.turn_on
    data_template:
     entity_id: '{{ trigger.payload_json.entity_id }}'
     brightness: >
       {% set domain, device = trigger.payload_json.entity_id.split('.')  %}
       {% set step = trigger.payload_json.step %}
       {% set value = states[domain][device].attributes.brightness + step %}
       {{ value }}