geepie
(Gert-Jan)
November 20, 2024, 10:14am
1
I have 2 sensors who I wants to be a total:
sensor.kosten_airco_woonkamer + sensor.kosten_airco_boven = sensor. totale_kosten
sensor.kosten_airco_woonkamer and sensor.kosten_airco_boven are working correct, but Sensor.total_kosten is not available I tried a restart. I checked the configuration.yaml (no errors)
Can anyone help?
configuration yaml
#energie kosten airco
input_number:
prijs_per_kwh:
name: "Prijs per kWh"
initial: 0.33 # Stel de prijs in, bijvoorbeeld 0,22 EUR/kWh
min: 0
max: 1
step: 0.01
unit_of_measurement: "EUR/kWh"
sensor:
- platform: template
sensors:
kosten:
friendly_name: "kosten airco woonkamer"
unit_of_measurement: "EUR"
value_template: "{{ (states('sensor.dag_verbruik_woonkamer') | float) * (states('input_number.prijs_per_kwh') | float) }}"
kosten_boven:
friendly_name: "kosten airco boven"
unit_of_measurement: "EUR"
value_template: "{{ (states('sensor.dag_verbruik_boven') | float) * (states('input_number.prijs_per_kwh') | float) }}"
totale_kosten:
friendly_name: "totale kosten airco"
unit_of_measurement: "EUR"
value_template: "{{ (states('sensor.kosten_airco_woonkamer') | float) + (states('sensor.kosten_airco_boven') | float) }}""
tom_l
November 20, 2024, 11:19am
2
There are too many double quotes at the end of this template. Try:
value_template: "{{ states('sensor.kosten_airco_woonkamer') | float + states('sensor.kosten_airco_boven') | float }}"
petro
(Petro)
November 20, 2024, 11:49am
4
explain what didn’t work.
1 Like
geepie
(Gert-Jan)
November 20, 2024, 11:57am
5
I made screenshots to explain me further: There is a value total costs, but when I try to make a statistic there is no statistics available see screenshots:
petro
(Petro)
November 20, 2024, 12:33pm
6
for statistics to work, you need to swap to the new template configuration and make sure you use a device_class, state_class, and valid unit_of_measurement.
geepie
(Gert-Jan)
November 20, 2024, 1:30pm
7
Do you have a suggestion how I can do this?
geepie
(Gert-Jan)
November 20, 2024, 4:15pm
9
Ok I rebuild the yaml to the new template. But now I have new problem. De total is 0 so something went wrong with the calculations. I don’t understand why it’s giving 0. Because the other values are set.
# Energie kosten airco
input_number:
prijs_per_kwh:
name: "Prijs per kWh"
initial: 0.33 # Stel de prijs in, bijvoorbeeld 0,22 EUR/kWh
min: 0
max: 1
step: 0.01
unit_of_measurement: "EUR/kWh"
template:
sensor:
- name: "kosten airco woonkamer"
unit_of_measurement: "EUR"
value_template: "{{ (states('sensor.dag_verbruik_woonkamer') | float(0)) * (states('input_number.prijs_per_kwh') | float(0)) }}"
state_class: total_increasing
- name: "kosten airco boven"
unit_of_measurement: "EUR"
value_template: "{{ (states('sensor.dag_verbruik_boven') | float(0)) * (states('input_number.prijs_per_kwh') | float(0)) }}"
state_class: total_increasing
- name: "totale kosten airco"
unit_of_measurement: "EUR"
value_template: "{{ (states('sensor.kosten_airco_woonkamer') | float(0)) + (states('sensor.kosten_airco_boven') | float(0)) }}"
state_class: total_increasing
here de debug output
# Energie kosten airco
input_number:
prijs_per_kwh:
name: "Prijs per kWh"
initial: 0.33 # Stel de prijs in, bijvoorbeeld 0,22 EUR/kWh
min: 0
max: 1
step: 0.01
unit_of_measurement: "EUR/kWh"
template:
sensor:
- name: "kosten airco woonkamer"
unit_of_measurement: "EUR"
value_template: "1.8479999999999999"
state_class: total_increasing
- name: "kosten airco boven"
unit_of_measurement: "EUR"
value_template: "0.46199999999999997"
state_class: total_increasing
- name: "totale kosten airco"
unit_of_measurement: "EUR"
value_template: "0"
state_class: total_increasing
Edwin_D
(Edwin D.)
November 20, 2024, 5:04pm
10
I think you pasted the wrong thing in the debug output. It would be helpful to see the values from developer tools.
Troon
(Troon)
November 20, 2024, 5:35pm
11
You do know that pasting the YAML into the template editor doesn’t actually create the sensors in the system, don’t you?
Your final sensor template can’t reference the values from the sensors above. You must put this code into your configuration.yaml
.
geepie
(Gert-Jan)
November 20, 2024, 5:41pm
12
Yes I know that. Just pasting the same code as de configuration.yaml for debugging. Since the total is not working …
Troon
(Troon)
November 20, 2024, 6:13pm
13
Does sensor.kosten_airco_woonkamer
exist? You have to do a full restart when using a new integration like template
.