How would one write a function/template for propane gas and energy monitoring?

I have the Tank Utility integration working, and it is great.

I would like to use the data from that integration to add it into my Energy Use, as Propane is a gas, and it is something we consume.

The Tank Utility only updates every 24 hours, so I could only update on that schedule.

However, I am at a loss as to how to write a function to track the energy usage with this gauge:

  • I have a 500 gallon tank
  • Tank Utility gives me a pressure reading every 24 hrs, like 45.6%
  • I can measure the change in a period, probably get square meters from that
  • Periodically, the tank is refilled, meaning the reading will suddenly shoot up
  • I don’t want the tank filling to count as energy “coming back” into the system

I have spent a lot of time googling this, but I can’t seem to find a similar situation or use case. If I could figure it out it would be nice to have Tank Utility track energy usage.

Same situation here! Have been struggling to figure out how to include propane energy usage. Also tank utility integration doesn’t show up in long term statistics. That would be nice too!

I am waiting for my next fill up to find out how much gas was added. From that, I should be able to get a rough calculation of how much the meter percentage calculates for the amount of gas used.

What I don’t know how to do is to handle when gas is added back into the system, as that will be seen as “Giving back to the grid”

Will probably be something like:

 - platform: template
    sensors:
      propane_use:
        value_template: >-
          {% set some rules here%}
        friendly_name: Propane Use
        unit_of_measurement: m3

So, I have a bit more info that I can probably start to figure out some calculations with:

499.0 Gallons Total tank volume
251.3 Gallons delivered
88.0% after fill up
37.2% before fill
50.8% fill for 251.3 gallons is 4.9468 Gallons per percentage point

Thus, I should be able to use that figure as a calculation to judge gallons used, though it will be an estimate.
$2.71/Gallon is the estimated spot price per gallon (there are other charges)

So I think this can be worked with. I don’t know how to handle when the volume suddenly goes up though.

So, I believe that there are 2 components needed, first is something like this in configuration.yaml

utility_meter:
  daily_energy_propane:
  source: sensor.tank_utility_0000000001112223333a444455556666
    cycle: daily

Then, a sensor (I have my sensors in their own sensor.yaml file)

  - sensor:
    - name: 'Daily Propane'
      device_class: energy
      unit_of_measurement: m3
      state: >. # jinja2 logic here

I am trying to figure out the jinja2 logic.

The Tank Utility integration reads propane in US gallons. 1 US gallon is 0.00379 cubic meters So, this is our conversion rate that we need in the template.

The next bit of logic I need in the jinja2 template is, something like “If value today is higher than value yesterday, then today’s consumption is zero.” Reason being, if the propane is filled up, we can’t actually calculate how much was used as we have to wait a full 24 cycle for valid results.

I believe that this is possible with jinja2, but I need to get better with it.

I am thinking that the sensor math is going to look something like this:


sensor:
  - platform: template
    sensors:
      propane_consumed:
        friendly_name: "propane value in mÂł" 
        unit_of_measurement: "mÂł"
        value_template: "{{ ( states('sensor.tank_utility_0000111122223333')* 0.00379 }}"

You have 453,577 BTU/%

Vaporized propane is 91,690 btu/gallon.

I checked and the % is linear for the tank size base on calculations

So for daily energy % consumed daily * 453577 will give you your daily energy in btu’s. This will be within 1-3%

If you want in KWh

1 BTU = 0.00029307107017 kWh

1 Like

Oh, thats brilliant, this is great!

Can you post your sensor yaml calculation for me to look at. I have a sensor that tells me the gallons present in the tank. I want to use your formula to create a new sensor that tells me daily gallon usage and the calculate energy usage. Similar to you my tank will get filled and the value will be greater for that do so no usage…

Thanks in advance.

I am still trying to hash this out myself, so far all my changes keep breaking my regular energy usage - I am not yet skilled enough with Jinja2 to be able to get this sorted… yet.

Ok thx. I have never used jinja2 but will take a look and see if I can provide any help

Are you getting the percent as a sensor or does it report total every day?

template:
  - trigger:
      - platform: time
        at: '00:00:00'  <-- set to the time you get your reading
      - platform: event
        event_type: event_template_reloaded
      - platform: homeassistant
        event: start
    sensor:
      - name: "Gas kwh"
        state: >-
         {% set todaygas = (states('sensor.percent_today")) | float(0) %}
         {{ todaygas * 453577 * 0.00029307107017 }}

Your daily gas will be in a sensor named sensor.gas_kwh and it will be calculated at midnight each day. You can multiply the two constants together and only have it do one multiplication.

If you get total tank volume then you will need a trigger template to save yesterdays reading and then you can subtract.

Hope this helps you along.

EDIT: took comma out of 453,577 -

Oh, this helps quite a lot, I didn’t consider that I could use platform time in that manner!

I have the following configuration.yaml and customize.yaml but still cannot get things to show up in the Energy panel. tank_percentage is obtained by multiscrape from a website. Any help as to what I am doing wrong?

configuration.yaml

template:
  - trigger:
      - platform: time
        at: '23:59:59'  
      - platform: event
        event_type: event_template_reloaded
      - platform: homeassistant
        event: start
    sensor:
      - name: "Propane Used"
        unit_of_measurement: "kWh"
        unique_id: "propane_used"
        state: >-
         {% set todaygas = (states('sensor.tank_percentage')) | float(0) %}
         {{ todaygas * 453,577 * 0.00029307107017 }}
         
utility_meter:
  daily_energy_propane:
    source: sensor.propane_used
    cycle: daily         

customize.yaml

sensor.propane_used:
  last_reset: '1970-01-01T00:00:00+00:00'
1 Like

Take the comma out of 453,577. Mea Culpa -

Also is the sensor.tank_percentage the daily usage? If not you will have to create a sensor that is.

This is from developer tools

This is great - it seems to be correct. How does this handle refills? That is, when the propane truck comes by and fills up? Not sure if this will come back as a negative value?

It will depend if the percentage is propane used or total percentage in the tank.

Sensor.tank_percentage is not the daily amount used. It is the percent in the tank remaining. I guess I misunderstood utility meter function. I thought that it calculated the daily usage from the sensor valve. I also think I need to set net consumption to true in the utility meter section so I can have negative values from day to day.

Sorry for the noob question but sincesensor.tank_percentage is the percentage in the tank is there a function that easily calculates the daily usage such that

sensor.daily_propane_used = function of (sensor.tank_percentage)?

Current it is the percentage in the tank so I should come back negative when the tank is refilled…

I am guessing it is going to be something like

        state: >-
         {% set todaygas = (states('sensor.tank_percentage')) | float(0) %}
         {% if todaygas < 0 %} {% set todaygas = 0%}
         {% else %}  
         {{ todaygas * 453,577 * 0.00029307107017 }}
         {% endif %}

I am sure that this logic is incorrect. But hopefully I have the right idea - unless the way the float is calculated already above handles negative values.