Service_template fails on entity name

Hello,

I found this strange behavior I can’t find a way to solve.
Consider this service_template that will work:

service_template: >
  {% if states.light.lampe_christine.state == 'on' %}
    light.turn_off
  {% else %}
    light.turn_on 
  {% endif %}

now if I replace the entity by this one

service_template: >
  {% if states.light.6001949557bd_1921681149.state == 'on' %}
    light.turn_off
  {% else %}
    light.turn_on 
  {% endif %}

it will fail during check_config
Failed config
automation:
- Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'bd_1921681149') for dictionary value @ data['action'][0]['service_template']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 39). Please check the docs at https://home-assistant.io/components/automation/

I’m not sure how to address this problem.

Edit: this entity exist

light.6001949557bd_1921681149 on brightness: 255
effect_list: random,gb_cross_fade,white_fade,green_fade,white_strobe,yellow_fade,colorjump,cyan_strobe,blue_fade,yellow_strobe,rb_cross_fade,blue_strobe,purple_fade,colorstrobe,purple_strobe,colorloop,green_strobe,cyan_fade,red_strobe,red_fade,rg_cross_fade
rgb_color: 255,64,0
friendly_name: RGB-Strip-JP-Desk
supported_features: 21
icon: mdi:led-strip

No, it doesn’t exist, although you see it :slight_smile:

Try (the problem is that the ID begins with a number):

light['6001949557bd_1921681149']

Thank you. this is a tricky one, correct syntax is:

service_template: >
  {% if states.light['6001949557bd_1921681149'].state == 'on' %}
    light.turn_off
  {% else %}
    light.turn_on 
  {% endif %}

note the brackets and the missing “.” between light and the entity name.

You’re welcome