No.
You can not add a state_class to a legacy format sensor. You need to use the new format as I said:
No.
You can not add a state_class to a legacy format sensor. You need to use the new format as I said:
got it! then it should be like this:
template:
- sensor:
- name: "Energia prodotta consumata in casa"
unique_id: tesla_card_produzione_solare_immessa_in_casa
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
device_class: energy
state_class: total_increasing
unit_of_measurement: kW
is now correct?
However, what is not really clear to me is why i have the log for the sensor tesla_card_produzione_solare_immessa_in_casa and not for tesla_card_consumo_totale_casa…
- platform: template
scan_interval: 60
sensors:
#
tesla_card_consumo_totale_casa:
friendly_name: "Consumo totale casa"
value_template: "{{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa') | float(2)) | round(2) }}"
device_class: power
unit_of_measurement: kW
If it is an energy sensor, you need units of kWh
Actually I missed this:
Energy is measured in kWh, not kW.
Edit: beaten to it by Rick.
I have fixed kWh instead with kW but I still have this message using “state_class: total_increasing” or “state_class: total”…
Entity sensor.giorno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.mese_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.anno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Go to Developer Tools → Statistics and fix all the issues listed there.
There is any issues here…
could be related only when I restart because the sensor is not yet ready and i can solve it with availability?
template:
- sensor:
- name: "Energia prodotta consumata in casa"
unique_id: tesla_card_produzione_solare_immessa_in_casa
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
availability: >
{{ has_value('sensor.tesla_card_produzione_solare_immessa_in_casa')}}
device_class: energy
state_class: total
unit_of_measurement: kWh
No that is not how you use the availability template. You need to list both the source sensors, like this:
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
availability: >
{{ has_value('sensor.giorno_produzione_fotovoltaico') and has_value('sensor.giorno_immissione_in_rete') }}
However hat is not your issue. The error shown above has nothing to do with this template sensor. Can you please show the configuration for this entity
sensor.giorno_produzione_solare_immessa_in_casa
here the code:
utility_meter:
giorno_produzione_solare_immessa_in_casa:
source: sensor.tesla_card_produzione_solare_immessa_in_casa
cycle: daily
template:
- sensor:
- name: "Energia prodotta consumata in casa"
unique_id: tesla_card_produzione_solare_immessa_in_casa
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
And you are 100% sure there are no FIX ISSUE buttons for sensor.giorno_produzione_solare_immessa_in_casa
in Developer Tools → Statistics now?
If so, try commenting out the utility meter:
utility_meter:
# giorno_produzione_solare_immessa_in_casa:
# source: sensor.tesla_card_produzione_solare_immessa_in_casa
# cycle: daily
Restart Home assistant.
Then recreate the utility meter by deleting the comments
utility_meter:
giorno_produzione_solare_immessa_in_casa:
source: sensor.tesla_card_produzione_solare_immessa_in_casa
cycle: daily
and restart again.
If that does not fix it try renaming the utility meter,
utility_meter:
giorno_produzione_solare_immessa_in_casa_2:
source: sensor.tesla_card_produzione_solare_immessa_in_casa
cycle: daily
nothing happen… however i guess we have to do a step back because I just recognized that with the new format nothing working anymore
status before:
below folder “custom_sensor” I used following code which was working
- platform: template
scan_interval: 60
sensors:
#
tesla_card_consumo_totale_casa:
friendly_name: "Consumo totale casa"
value_template: "{{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa') | float(2)) | round(2) }}"
device_class: power
unit_of_measurement: kW
tesla_card_produzione_solare_immessa_in_casa:
friendly_name: "Energia prodotta consumata in casa"
value_template: "{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}"
device_class: power
unit_of_measurement: kW
then I replace it with the new format as below in the folder “custom_packages”
template:
- sensor:
- name: "Consumo totale casa"
unique_id: tesla_card_consumo_totale_casa
state: >-
{{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa') | float(2)) | round(2) }}
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
- name: "Energia prodotta consumata in casa"
unique_id: tesla_card_produzione_solare_immessa_in_casa
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
and this is what I see in the console… something is not clear and I guess here we need to solve something…
Someone else will have to help you. I don’t use packages.
I tried to move the code from packages to configuration.yaml but same result
Did you restart after moving it?
Errors in your logs?
yes I restart it!
warning:
Registratore: homeassistant.components.sensor
Fonte: components/sensor/init.py:575
Integrazione: Sensore (documentazione, problemi)
Prima occorrenza: 11:04:58 (3 occorrenze)
Ultima registrazione: 11:04:58
Entity sensor.giorno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.mese_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
Entity sensor.anno_produzione_solare_immessa_in_casa (<class ‘homeassistant.components.utility_meter.sensor.UtilityMeterSensor’>) is using state class ‘total_increasing’ which is impossible considering device class (‘power’) it is using; expected None or one of ‘measurement’; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues · home-assistant/core · GitHub
warning 2
Registratore: homeassistant.components.sensor.recorder
Fonte: components/sensor/recorder.py:325
Integrazione: Sensore (documentazione, problemi)
Prima occorrenza: 11:05:37 (1 occorrenze)
Ultima registrazione: 11:05:37
Entity sensor.consumo_altro from integration template has state class total_increasing, but its state is negative. Triggered by state -3.07 with last_updated set to 2024-04-09T08:59:59.999999+00:00. Please create a bug report at Issues · home-assistant/core · GitHub
There is something wrong with your template sensor. I suspect it is because you removed the availability template. When one or both of the sensors was unavailable (e.g. during a restart) it was substituted with the your default value of 2, where you used |float(2)
this caused the value to go backwards.
i confirm that I wrote this and for mistake i restat the hassio.
can I solve it with following code?
- name: "Energia prodotta consumata in casa"
unique_id: tesla_card_produzione_solare_immessa_in_casa
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
availability: >
{{ has_value('sensor.giorno_produzione_fotovoltaico') and has_value('sensor.giorno_immissione_in_rete')}}
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
No. We are going around in circles here. As I said before: Issues with utility meter - #11 by tom_l
I tried to create new sensor (just to avoid any discrepancy of older data)
new format:
template:
- sensor:
- name: "Consumo totale casa2"
unique_id: tesla_card_consumo_totale_casa2
state: >-
{{ (states('sensor.giorno_consumo_casa') | float(2) + states('sensor.tesla_card_produzione_solare_immessa_in_casa2') | float(2)) | round(2) }}
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
- name: "Energia prodotta consumata in casa2"
unique_id: tesla_card_produzione_solare_immessa_in_casa2
state: >-
{{ (states('sensor.giorno_produzione_fotovoltaico') | float(2) - states('sensor.giorno_immissione_in_rete') | float(2)) | round(2) }}
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
and result con console:
1- {{states('sensor.tesla_card_consumo_totale_casa2')}}
2- {{states('sensor.giorno_consumo_casa')}}
3- {{states('sensor.tesla_card_produzione_solare_immessa_in_casa2')}}
4- {{states('sensor.giorno_produzione_fotovoltaico')}}
5- {{states('sensor.giorno_immissione_in_rete')}}
1- unknown
2- 2.3161
3- unknown
4- 20.5697
5- 13.9797
something is not working with the sum between sensor…
after a whole restart of my NAS (because my hassio is on docker) i was able to comment, correct the stats (deliting them) and comment out the utility…
the problem is still present. after this i try to create the same sensor using the new format but same result…of this reply.