Sensor template error

Hi guys

I recently wanted to create entities starting from some attributes coming from my Tuya plug. I created a template using forums and suggestion on here but when i try to restart HA, i get this error:

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘,’, got ‘current’) for dictionary value @ data[‘sensors’][‘scrivania_curr’][‘value_template’]. Got “{{ state_attr('switch.scrivaniatest’,‘current’) }}” invalid template (TemplateSyntaxError: expected token ‘,’, got ‘current_consumption’) for dictionary value @ data[‘sensors’][‘scrivania_cons’][‘value_template’]. Got “{{ state_attr('switch.scrivaniatest’,‘current_consumption’) }}” invalid template (TemplateSyntaxError: expected token ‘,’, got ‘voltage’) for dictionary value @ data[‘sensors’][‘scrivania_volt’][‘value_template’]. Got “{{ state_attr('switch.scrivaniatest’,‘voltage’) }}”. (See ?, line ?).

I did for sure some mistake writing the code and i’m stuck because i can’t figure out what it is.
This is my code:

sensor:

  • platform: template
    sensors:
    scrivania_cons:
    unique_id: “scrivania_cons”
    friendly_name: “Consumo scrivania"
    unit_of_measurement: “W”
    value_template: “{{ state_attr('switch.scrivaniatest’,‘current_consumption’) }}”
    scrivania_curr:
    unique_id: “scrivania_curr”
    friendly_name: “Corrente scrivania”
    unit_of_measurement: “mA”
    value_template: “{{ state_attr('switch.scrivaniatest’,‘current’) }}”
    scrivania_volt:
    unique_id: “scrivania_volt”
    friendly_name: “Voltaggio scrivania”
    unit_of_measurement: “V”
    value_template: “{{ state_attr('switch.scrivaniatest’,‘voltage’) }}”

It basically takes the attributes values (which i can see in the developer tap so they are working) but i can’t understand the problem.

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Please format your code correctly: it could be hiding all sorts of errors.

If you’ve copy/pasted it, you might have “smart quotes” in your template (my best guess), but we can’t tell unless you format it properly. You’ll probably need to re-paste it rather than try to correct what’s already there.

For example:

value_template: “{{ state_attr('switch.scrivaniatest’,‘current_consumption’) }}”

with invalid “smart” quotes and:

value_template: "{{ state_attr('switch.scrivaniatest','current_consumption') }}"

with correct, “plain” quotes. Both render the same in this forum if you don’t format as code in your post.

Now it works perfectly. I just replaced every quotes and everything is working good. Thank you very much Troon and thanks to tom_I for the forums tips (this was my first post)