Of that I am aware… but how to make sensor from template so that “sensor.trenutni_nivo_vode” will be used when consumption from tank is made…
So tank max level is 3400L and when water is used (negative value from current level; lets say that it goes from 3400L to 3300L) the template sensor must add consumption (100L). And when tank refill (let say from 3300L to 3400L) this value is not used and consumption is not changed…
With that setting every hour you will get consumption under Energy dashboard for your water tank on which you use only level measurement on which you have consumption with L unit measurement.
I used your solution to get the water consumption using my ultrasonic sensor in my water tank.
Initially it worked, but now I’m getting a message in the log, that something is wrong with the sensor:
Invalid config for [template]: expected dictionary for dictionary value @ data['sensors']. Got [OrderedDict([('name', 'Wasserverbrauch Zisterne'), ('unit_of_measurement', 'm³'), ('device_class', 'water'), ('state_class', 'total_increasing'), ('friendly_name', 'Wasserverbrauch Zisterne'), ('state', "{% if states('sensor.gesamtverbrauch_zisterne') == 'unknown' %}\n {{ int(0) }}\n{% else %}\n {{ states('sensor.gesamtverbrauch_zisterne') | float * 0.001 }}\n{% endif %}\n")])]. (See /config/configuration.yaml, line 274).
This is how I implemented the solution - I use the “emptyness” of my water tank to always generate a new entry, when the water level sinks.
Since the upgrade to home assistant 2023.2.5 I had to remove the state class measurement from the sensor “Zisterne Füllstand” and “Zisterne Leerstand”, as I get an error message that this is not supported for device class water.
Just adding a note here to thank you @kslb as I used your guide to measure the outflow from a sump pump and report it as a grid dashboard “water consumption” element so I can track variations over time.
Measurements are based on a Qidian ADC Water level sensor connected to a Shelly Uni and uses the sump tank dimensions to estimate the liters in the tank as the water level changes.
I did not run into any specific issue other than my customize configuration not being split in the same files as yours, but all in all it worked well.
i also use your code to record the water consumption from my water tank. Thank you for sharing it.
But when i reload the yaml configuration the value of “Wasserverbrauch Zisterne” is added to the energy-dashboard.
Does anybody have the same problem or an idea how this can be prevented?
Many thanks in advance.