Hi
I have created an energy water sensor with a correct configuration. I feed this sensor with water index values I take from the web page of my water supplier .
The daily values are always 2 days late .
So I enter the value with a date 2 days prior to day
Everything is fine and I find the daily consumption in the energy dashboard
The issue is that HA seems and recalculate the index every hour and produce a negative value equal to the last know index
How is it possible to prevent HA to behave like that
Thanks
Philippe
#How to prevent HA to recalculate bad water energy value ?
1 messages · Page 1 of 1 (latest)
Can you share more of what you've done.
How do you "feed the sensor"?
Hi
I have an mqtt sensor :
ˋ`ˋ
- name: "Index Eau Historique"
state_topic: "eau/consommation"
unit_of_measurement: "L"
value_template: "{{ value_json.index }}"
state_class: total_increasing
device_class: water
ˋˋ A program that sends mqtt frame as following : ˋˋ
eau
consommation = {"date": "2025-05-08", "litres": 0.0, "index": 563483}
ˋ`ˋ
So the date is 2 dates prior today
And an automatism like that :
ˋ`ˋ
alias: Importer donnée eau (index fixe)
description: Met à jour l’index de consommation d’eau à la date reçue
triggers:
- topic: eau/consommation
trigger: mqtt
conditions: []
actions: - alias: Enregistrer l’index reçu dans les statistiques
data:
statistic_id: sensor.index_eau_historique
unit_of_measurement: L
has_mean: false
has_sum: true
stats:
- start: >-
{{
as_datetime(trigger.payload_json.date).strftime('%Y-%m-%dT00:00:00+02:00')
}}
sum: "{{ trigger.payload_json.index | int }}"
source: recorder
action: recorder.import_statistics
mode: single
ˋ`ˋ
It works fine and I have the net consumption at each date in the energy tab but after an hour ( at hour) it produces a negative consumption equal to the last gross index
Change state class from total_inceasing to total
I think you should be importing statistics probably into a new external statistic, not importing it to the same statistic_id that you're creating with your (mqtt?) template sensor.
Because the sensor with the value_template is going to be doing its own weird thing and recording its own statistics, and then if you're importing historical statistics into the same entity, that could get weird.
Ok but in this case, the sensor will not be anymore energy compatible ?
Total_increasing and total are both fine for energy, but I don't really agree that that is the correct answer.
This was also my idea but I need to find a way to attach the good value to the good date .
Everything should be more easy with real time data’s but I can get from my water supplier the data’s 2 days old