I’ve recently put together a wonky, but so-far-stable, integration that scrapes tank level in gallons from my provider’s website. The integration also calculates daily usage also in gallons based on any differences between the last reading and the current reading.
I created a template sensor to convert the tank level to cubic feet:
- sensor:
- unique_id: sensor.lp_gas_tank_level
name: LP Gas Tank Level
icon: mdi:storage-tank-outline
state: >
{{ (states('sensor.tank_2_lp_gas_retail_gallons')|int*35.97) }}
device_class: gas
state_class: total
unit_of_measurement: ft³
Then I put this in configuration.yaml:
propane_consumption_total:
name: Propane Consumption Total
source: sensor.lp_gas_tank_level
cycle: yearly
However… the sensor value decreases with consumption, and so (if I understand correctly), the utility meter entity ignores any changes. I realized this morning that’s the opposite of what I want.
Now… I could create a sensor that subtracts tank level from some arbitrary number, like, 10,000,000, and that might give me what I want as the basis for the utility meter entity… but that seems like a poorly-thought-out workaround. Would the daily consumption sensor be what I need instead? And, would the utility meter entity reliably increment that if (for instance) my daily consumption stays a “3 gallons” for several days in a row?
I’ve dug through the documentation and I’m not sure how to approach this. I think I have the elements I need to get there (like making sure I have the right units and device_class), but I’m not sure how to put the pieces together. Thanks for any help.
Yes, I suppose so! Current tank level will never exceed the tank capacity.
I guess my hangup with that was how my integration calculates capacity: it uses the current level in gallons and extrapolates based on the percentage level, both of which are provided by the website. Because of rounding errors (?), the capacity sensor has floated between 326.8 and and 325 over the last few weeks. Not a huge error, but not one I want to repeatedly and randomly introduce into the calc.
If I just use a hard-coded number for the sensor, like this:
- sensor:
- unique_id: sensor.lp_gas_consumed
name: LP Gas Consumed
icon: mdi:storage-tank-outline
state: >
{{ (326-states('sensor.tank_2_lp_gas_retail_gallons')|int)*35.97 }}
device_class: gas
state_class: total
unit_of_measurement: ft³
…that ought to do it. I’ll give it a try. Thanks for the suggestion.
And I forced the state of my utility meter entity, propane_consumption_total, to 0. The only trouble is, I still have some artifacts from its earlier states in my dashboard:
I guess the only way to get rid of these would be to delete that utility meter entity and start using a new one with a different name…
And, I’m guessing that when my template sensor goes negative (i.e., tank level > 140), that won’t matter as the utility meter will only log net increases?
EDIT: I’ve just used Dev Tools → Statistics for the first time… I’ve never had reason to check that out. I was able to clear out old states of that utility meter entity.