I have a mqtt sensor getting data from a tasmota device. I have the sensor setup as follows
- platform: mqtt
name: "3dPrinter Switch"
state_topic: "tele/arlec-switch-1/STATE"
value_template: '{{ value_json.POWER }}'
json_attributes_topic: "tele/arlec-switch-1/STATE"
json_attributes_template: "{{ value_json | tojson }}"
This works fine.
When I try and use the template platform to extract some attributes for display I get the error.
expected token 'end of print statement', got 'dprinter_switch') for dictionary value @ data['sensors']['3dprinter_switch_power']['value_template']. Got '{{ states.sensor.3dprinter_switch.attributes.POWER }}'
invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'dprinter_switch') for dictionary value @ data['sensors']['3dprinter_switch_uptime_seconds']['value_template']. Got '{{ states.sensor.3dprinter_switch.attributes.UptimeSec }}'
invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'dprinter_switch') for dictionary value @ data['sensors']['3dprinter_switch_wifi']['value_template']. Got '{{ states.sensor.3dprinter_switch.attributes.Wifi.Signal }}'. (See ?, line ?).
- platform: template
sensors:
3dprinter_switch_wifi:
value_template: '{{ states.sensor.3dprinter_switch.attributes.Wifi.Signal }}'
unit_of_measurement: "dB"
friendly_name: 3d Printer Switch Wifi
3dprinter_switch_uptime_seconds:
value_template: '{{ states.sensor.3dprinter_switch.attributes.UptimeSec }}'
unit_of_measurement: "sec"
friendly_name: 3d Printer Switch Uptime
3dprinter_switch_power:
value_template: '{{ states.sensor.3dprinter_switch.attributes.POWER }}'
friendly_name: 3d Printer Switch
icon_template: mdi:flash
When I use the template section of developer tools and only try and display the value of one of the attributes
{{ states.sensor.3dprinter_switch.attributes.POWER }}
I get the error
invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'dprinter_switch') for dictionary value @ data['template']. Got '\n{{ states.sensor.3dprinter_switch.attributes.POWER }}'
I suspect it is the .3 in the template name is possibly causing some issues.
Any way of getting around this without changing the name?