Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘d_drucker’) for dictionary value @ data[‘sensors’][‘power_usage_3ddrucker’][‘value_template’]. Got ‘{{ states.switch.3d_drucker.attributes.current_power_w }}’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
its likely because the entity_id starts with a number. here are the docs that explain what to do to make it work. see the note about half way down:
be aware tho that i was just trying to help someone else with one of their templates with an entity_id that started with a number following the rules in the referenced docs and i wasn’t successful. eventually i decided the easiest thing to do was change the entity_id to not start with a number and that solved their problem.
but @petro I’m honestly not sure that will work. I was working on trying to help another user last week or so with the same situation and I could never get the template to work.
here is the thread I started to see if anyone else had any better insight why it wouldn’t work but I never got any replies:
They may have made changes to make all numbers fail as an object_id. I’ve seen it work for some configurations. I personally avoid it so I’ve never had to deal with it.
Best place to play around would be inside the template editor.
I could fixt it by chaning the entity name to something which doesn’t start with a number, but I don’t get the point. I can name entities starting with a number,but the template doesn’t work…
The point is that code does not allow variables to start with a number. So when you try to access the state object, it screws up because a number is first.
So while you can make a object_id start with a number, as soon as you try to access that state object, it’s going to break because code doesn’t allow it.
Templates are code, the language is Jinja2. Jinja2 runs on python. Python does not allow numbers to start method or variable names. So this code will error in the template:
states.swtich.3d_drucker.attributes.current_power_w
^
|
Because this is wrong
So in order to get around these types of issues you have 1 of a few options:
Don’t name any object_id starting with a number. entity_id = domian.object_id. For example light.livingroom where light is the domain and livingroom is the object_id.
Use other ways to access state. Example: states('domain.object_id') or states('light.livingroom'). This may not work all the time because again, numbers starting object_id’s are a no-no.
hopefully that clears this up.
So, in summery: The template doesn’t work because you are using a number first as the object_id.
And just to drive this point home… read your error. It specifically tells you what it doesn’t understand:
What preceeds d_drucker? The number 3, which is the cause of your error and problem.