wonder if anyone can help, I’m having an issue with a template sensor where the value appears to be generated, when I use the template editor, but then when put into the configuration.yaml file, restart template entries, its not available to choose as an entity to display on the lovelace dashboard:
When a template is on the same line as the option, the template must be wrapped in quotes. You’re already using single-quotes inside the template so the outer quotes should be double-quotes.
- platform: template
sensors:
current_power_usage_w:
friendly_name: current power usage w
unit_of_measurement: W
value_template: "{{ ((states('sensor.shellyem_a4e57cbaa014_channel_1_power')|float) + (states('sensor.shellyem_a4e57cbaa014_channel_2_power')|float) + (states('sensor.shellyem_c45bbe6c32ab_channel_1_power')|float)|int) }}"
As an alternative, you can add the > line-continuation character and move the entire template to the next line with additional indentation. If you do that then the template doesn’t need outer quotes.
- platform: template
sensors:
current_power_usage_w:
friendly_name: current power usage w
unit_of_measurement: W
value_template: >
{{ ((states('sensor.shellyem_a4e57cbaa014_channel_1_power')|float) + (states('sensor.shellyem_a4e57cbaa014_channel_2_power')|float) + (states('sensor.shellyem_c45bbe6c32ab_channel_1_power')|float)|int) }}
If you are interested, here’s another way to add the values of all three sensors.
- platform: template
sensors:
current_power_usage_w:
friendly_name: current power usage w
unit_of_measurement: W
value_template: >
{{ ['sensor.shellyem_a4e57cbaa014_channel_1_power',
'sensor.shellyem_a4e57cbaa014_channel_2_power',
'sensor.shellyem_c45bbe6c32ab_channel_1_power']
| map('states') | map('float', 0) | sum | int(0) }}
EDIT
Correction. Troon identified use of modern format in this legacy format Template Sensor. Replaced name with friendly_name and other things. See Troon’s post below.
The configuration.yaml file is still being checked, and no issues found - however, the dashboard is not providing the sensor template value. It has worked a few months ago, and since, nothing has changed. The entity is still not available when you connect to the dashboard, and try and add it as an entity.
After modifying the sensor’s configuration, using one of the three methods I described in my previous post, you must execute Developer Tools > YAML > Reload Template Entities to load the sensor’s new configuration.
After reloading, go to Developer Tools > States and confirm that sensor.current_power_usage_w appears in the list.
If it’s not appearing then it means there’s an error in the sensor’s configuration and Home Assistant has refused to load it. The error will be reported in Logs, so check it for errors.
Where exactly did you put the sensor’s configuration within the configuration.yaml file? It should be placed wherever you currently have other sensors configured. That’s typically under the sensor: key.