Zigbee2MQTT entity used in automation

Hello,

i am using the zigbee2mqtt bridge to control some tradfri lights and getting values from xiaomi sensors. Today i wanted to make an automation to increase the brightness of a tradfri bulb.
But homeassistant seems to have a problem with the auto generated ids from zigbee2mqtt

I have this in my automation:

  • service: light.turn_on
    entity_id: light.0x000b57fffe305f71_light
    data_template:
    brightness: ‘{{states.light.0x000b57fffe305f71_light.attributes.brightness -50}}’

and homeassistant says:
Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘x000b57fffe305f71_light’) for dictionary value @ data[‘action’][6][‘data_template’][‘brightness’]. Got None. (See /config/configuration.yaml, line 148). Please check the docs at https://home-assistant.io/components/automation/

Any suggestions?

the problem is the entity_id starts with a number.

see here:

https://www.home-assistant.io/docs/configuration/templating/#some-more-things-to-keep-in-mind

I think this should work:

- service: light.turn_on 
  entity_id: light.0x000b57fffe305f71_light 
  data_template:
    brightness: "{{states.light['0x000b57fffe305f71_light'].attributes.brightness -50}}"
1 Like

Wow, five months later.

You don’t get on here too often do you?

:smile:

Yes, i only saw your solution in the mail. Tried it out few weeks later but then forgot to mark it as the solution. Thank you so much, you really helped me with this. :slight_smile:

1 Like