joff
June 19, 2020, 10:30am
1
Hi.
I am trying to give a sensor a friendly name where the string includes a variable from the state of another sensor as below:
friendly_name: "Smart Plug Week "+hass.states.get(sensor.iso_week_number).state+" Usage:"
with the intention of having the current iso week number given as part of the name e.g.:
Smart Plug Week 25 Usage:
This gave the following error:
“…expected block end>, but found ‘scalar>’…”
I then tried the following with similar result:
friendly_name: "Smart Plug Week "+sensor.iso_week_number.state+" Usage:"
Is this a simple syntax error or is it not possible?
Thanks in advance.
As long as i know it’s only possible in Template sensors .
joff
June 19, 2020, 10:56am
3
Thanks for the quick response.
Ok, are there examples of this in the documentation? (haven’t found any - and better add I’m still quite new to configuration in yaml )
joff
June 19, 2020, 12:10pm
5
Great, got it working. Many thanks.
For others interested, here is my final config:
# Sensor to read weekly power consumption of smart plug
- platform: template
sensors:
nodon_smart_plug_weekly_total:
friendly_name_template: >-
{% if states('sensor.iso_week_number')|float > 0 %}
Smart Plug Week {{ states('sensor.iso_week_number') }} Usage:
{% else %}
Smart Plug Week Usage:
{% endif %}
value_template: "{{ (states.input_number.current_week_total) | float | round(2) }}"
unit_of_measurement: kWh
1 Like