Is it possible to multiply by a sensor value in a template?
I am using a template sensor that takes power usage and multiplies by a energy unit cost to give total cost of running an appliance for a day. The energy cost is currently hard coded into the template, it I get real-time energy costs from my energy supplier in another sensor, so I’d like to use this sensor value for the multiplication - is this possible?
My current template
- platform: template
sensors:
washing_energy_today_cost:
friendly_name: Washing Energy Cost for Today
value_template: >-
{% if is_state('sensor.washing_machine_energy_today', 'unknown') %}
Unknown
{% else %}
{{ '{:.2f}'.format(states('sensor.washing_machine_energy_today') | multiply(1.74)) }}
{% endif %}
unit_of_measurement: "£"
icon_template: mdi:cash-multiple