I have an energy monitor, plug in type. I want to display the cost of energy in a Lovelace card.
My problem is that if the “cost” has a trailing zero i.e 1.70 the zero is not displayed. Obviously mathematically that is correct.
Presently I am using a template…
sm112_02_cost_today:
unit_of_measurement: '£'
icon_template: mdi:currency-gbp
value_template: "{{ ((states('sensor.sm112_02_energy_today') | float) * 0.1352 ) | round(2) }}"
As an example, if the result is 1.70
Displaying this in Lovelace is shown as 1.7 £
I would like it shown as £1.70
Hope that makes sense.
Thank you
Chris
petro
(Petro)
April 20, 2020, 2:42pm
2
value_template: "{{ '{:.2f}'.format(states('sensor.sm112_02_energy_today') | float * 0.1352) }}"
Thank you for that Petro, that really helps. Lovelace still shows the £ sign at the end put I think I can work with that. Thank you very much.
petro
(Petro)
April 20, 2020, 3:05pm
4
It always puts the unit_of_measurement at the end. You can make custom UI stuff that moves it around.
value_template: "{{ '{:.2f}'.format(states('sensor.sm112_02_energy_today') | float * 0.1352) }}"
I used this code, but when i add this sensor to gauge card. it display Entity is non-numeric.
How to gauge card display with format currency.
Thank so much!
petro
(Petro)
August 27, 2020, 11:44am
6
and a unit_of_measurement.
petro
(Petro)
August 28, 2020, 9:58am
8
It’s in OPs original configuration.
- platform: template
sensors:
sensor_name:
friendly_name: "sensor_name"
unit_of_measurement: 'vnd'
value_template: >
{% set watt = states('sensor.sensorname')|float %}
{%- if(watt >= 400) -%}
{% set money = 83900 + 86700 + 201400 + 253600 + 283400 + (watt-400)*2927 %}
{%- elif(watt >= 300) -%}
{% set money = 83900 + 86700 + 201400 + 253600 + (watt-300)*2834 %}
{%- elif(watt >= 200) -%}
{% set money = 83900 + 86700 + 201400 + (watt-200)*2536 %}
{%- elif(watt >= 100) -%}
{% set money = 83900 + 86700 + (watt-100)*2014 %}
{%- elif(watt >= 50) -%}
{% set money = 83900 + (watt-50)*1734 %}
{%- else -%}
{% set money = watt*1678 %}
{%- endif-%}
{% set money = money*1.1 %}
{{ "{:.0f}".format(money) }}
this is current config.
if i change to
- platform: template
sensors:
sensor_name:
friendly_name: "sensor_name"
unit_of_measurement: 'vnd'
value_template: >
{% set watt = states('sensor.sensorname')|float %}
{%- if(watt >= 400) -%}
{% set money = 83900 + 86700 + 201400 + 253600 + 283400 + (watt-400)*2927 %}
{%- elif(watt >= 300) -%}
{% set money = 83900 + 86700 + 201400 + 253600 + (watt-300)*2834 %}
{%- elif(watt >= 200) -%}
{% set money = 83900 + 86700 + 201400 + (watt-200)*2536 %}
{%- elif(watt >= 100) -%}
{% set money = 83900 + 86700 + (watt-100)*2014 %}
{%- elif(watt >= 50) -%}
{% set money = 83900 + (watt-50)*1734 %}
{%- else -%}
{% set money = watt*1678 %}
{%- endif-%}
{% set money = money*1.1 %}
{{ "{:,.0f}".format(money) }}
gauge card show error “Entity is non-numeric”
petro
(Petro)
August 28, 2020, 11:27am
10
yeah, remove the comma. Comma’s in numbers aren’t supported.