I have this sensor and this template.
The documentation says this:
If your template uses an entity_id that begins with a number (example: states.device_tracker.2008_gmc) you must use a bracket syntax to avoid errors caused by rendering the entity_id improperly. In the example given, the correct syntax for the device tracker would be: states.device_tracker[‘2008_gmc’]
I did as in the example, but it doesn’t work and I get these error Message:
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘,’, got ‘integer’) for dictionary value @ data[‘sensors’][‘template_433_mhz_hub_doorbell_buzzer’][‘icon_template’]. Got “{% if is_state(‘sensor[‘433_mhz_hub_doorbell_buzzer’]’, ‘buzz’) %}\n mdi:volume-high\n{% else %}\n mdi:volume-off\n{% endif %}”. (See ?, line ?). Please check the docs at Template - Home Assistant
I can’t find my mistake, can someone help?
Thank you.
In general it is suggested that you avoid using a number as the first character in any object name. It will cause problems with ANY code base, because they all do not allow it. TBH your best option is to rename the device to start with a letter.
Anways, on to your problem…
To get this working with a number, you should use the following code:
The reason behind this is that in order to avoid the ‘number starting variable issue’, you need to grab the state from the object, you cannot use the method is_state with a nested key grab. you have to use one or the other. Your other option is to use is_state properly, but you may run into issues with the variable starting with a number. Anyways, here is that solution: