Value_template error

hi there.
im going nuts!
I have a onewire sensor entity_id: (sensor.2804146ce26aff_temperature) but that sensor is outside my watertank and is always 20 degrees C below the correct temperaturw. Therefor i want to make a template sensor adjusting this.

what i understand i cant use entity_id starting with numbers therfore the [’’] but i cant get it to work. when i try a different sensor that do not start with number it works.

im going crazy here :stuck_out_tongue:
Can someone please tell me whats wrong in this template sensor?

  - platform: template
        friendly_name: "pannan temp adj"
        value_template: '{{ states.sensor['2804146ce26aff_temperature']state | float + 20 }}'

You are missing the dot after your brackets, and you are using single quotes in single quotes. Single quotes in single quotes need a \ in front of them, or use double quotes with single inside. Otherwise, the software sees this as a string: '{{ states.sensor[', this as a variable: 2804146ce26aff_temperature, and this as a string: '].state | float + 20 }}'.

value_template: '{{ states.sensor[\'2804146ce26aff_temperature\'].state | float + 20 }}'


value_template: "{{ states.sensor['2804146ce26aff_temperature'].state | float + 20 }}"

You can also use this method:

value_template: "{{ state('sensor.2804146ce26aff_temperature') | float + 20 }}"
1 Like

This made my day :slight_smile: thank you m8!