I am trying to learn how to create templates for the first time so please be patient!
I am trying to create a new entity Electricity Unit Cost from the most recent days electricity usage and days cost. The new variable Cost and Kwh are just being set to the default value of 1. Any ideas why please?
template:
- sensor:
- name: "Electricity Unit Cost"
unit_of_measurement: "£"
state:
"{% set Cost = float (states( 'sensor.ovo_last_energy_cost'), 1) %}"
"{% set Kwh = float (states('sensor.last_electricity_reading'),1) %}"
"{{ Cost / Kwh }}"
Result type: string
template:
- sensor:
- name: "Electricity Unit Cost"
unit_of_measurement: "£"
state:
""
""
"1.0"
I am now trying to use some attributes in a picture-elements card. This card can only use entities not attributes, so I have created entities from attributes in Templates. I have created the following in Developers → Template
template:
- sensor:
- name: "Kitchen Temperature"
unit_of_measurement: "°C"
unique_id: kitchen_temperature
state: >
{% set kitchen_temperature = float( state_attr('climate.wiser_kitchen', 'current_temperature'),1) %}
{{ kitchen_temperature }}
template:
- sensor:
- name: "Kitchen Setpoint"
unit_of_measurement: "°C"
unique_id: kitchen_setpoint
state: >
{% set kitchen_setpoint = float( state_attr('climate.wiser_kitchen', 'temperature'),1) %}
{{ kitchen_setpoint }}
{% if kitchen_temperature > kitchen_setpoint %}
It is warm!
{% else %}
It is cold
{% endif %}
I get exactly the result I want and expect. But when I put this into my yaml.config file, save and restart, these new entities always have a value of zero. Any ideas what I have done wrong please?