{% set yesterday_percent = 37.6 %}
{% set today_percent = 80.2 %}
{% set filled_percent = 44.11 %}
{{ (yesterday_percent + filled_percent - today_percent) | round(2) }}
So one place to hold yesterdays reading, one sensor to hold today reading and one to hole today’s filled percentage. And a sensor to get todays percentage used as shown above (this is what you need to calculate daily percentage). An automation to zero out the filled percentage for the next day.
This makes sense. I will have to do a bit more logic though, as the set percentages are not consistent, so I will have to read and calculate each one, but this is closer to working for filling.
But it isn’t writing any data. So that is what I need to work through first, is to get the sensor to actually provide updates. Once I have that, I need to figure out the way Jinja2 really wants me to define the 3 sensors to handle that.
This is what I have currently… I am not getting my sensor to show up in the energy panel??
How did you get that done?
This is the logic I am working on. I can query yesterdays_propane_percent then subtract from todays_propane_percent.
Not sure if the formatting is correct?
- platform: template
sensors:
tank_gallons:
value_template: "{{(((states.sensor.tank_percentage.state) | int)*4) }}"
#get value of tank percentage from prior day at 11:59 pm
yesterdays_propane_percent:
value_template: >-
{% if now().hour == 23 and now().minute == 59 -%}
{{ states('sensor.tank.percentage') }}
{%- endif %}
# calculate propane BTUs - my tank each percentage change is 4 gals, thus 453577/% for 5 gallons = therefore 0.8 for 4 gal
# 1 BTU = 0.00029307107017 kWh = 106.344237436
todays_propane_kwh:
value_template: "{{(((states.propane_used_percent.state) | int)*106.344237436) }}"
unit_of_measurement: kWh
# last_reset: '1970-01-01T00:00:00+00:00'
# trigger template daily propane usage
# sensor.tank.percentage is the current tank percent full from website
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: "%"
unique_id: "propane_used_percent"
state: >-
{% set todays_propane_percent = (states('sensor.tank_percentage')) | float(0) %}
{% if todays_propane_percent < 0 %}
{% set propane_used_percent = 0 %}
{% set propane_filled_percent = (todays_propane_percent - yesterdays_propane_percent) %}
{% else %}
{{ (todays_propane_percent - yesterdays_propane_percent) }}
{% endif %}
utility_meter:
energy:
source: sensor.todays_propane_kwh
cycle: daily
net_consumption: true
Note, that error “Entity Not Defined” error you seen in the screenshot went away after my system first went past the 24 hour count cycle. It has since reappeared as I have been testing various permutations and editing my configs.
Thanks! let me know if your sensors start working, the fact that mine are buggered in recorder seems to be the root cause of why mine isn’t working yet.
I think this is working for the most part. I will know more tonight to see if it calculates correctly. The main issue I am having is that "yesterdays_propane_percent " value does not stay persistent after a restart. So if the system restarts then it will not calculate the usage for the day. I am not sure how to program it to do another way. Open to suggestions…
sensors:
tank_gallons:
value_template: "{{(((states('sensor.tank_percentage')) | int)*4) }}"
unit_of_measurement: "gal"
todays_propane_percent:
value_template: "{{((states('sensor.tank_percentage')) | int) }} "
unit_of_measurement: "%"
######
temporary_propane_used_today:
value_template: >-
{% set y = states('sensor.yesterdays_propane_percent') | float %}
{% set t = states('sensor.todays_propane_percent') | float %}
{{ (y-t)}}
unit_of_measurement: "%"
# calculate propane BTUs - my tank each percentage change is 4 gals, thus 453577/% for 5 gallons = therefore 0.8 for 4 gal
# 1 BTU = 0.00029307107017 kWh = 106.344237436
todays_propane_kwh:
value_template: "{{ (((states('sensor.propane_used_percent') | int) * 106.344237436)) }}"
unit_of_measurement: kWh
# trigger template daily propane usage
# sensor.tank.percentage is the current tank percent full from website
template:
- trigger:
- platform: time
at: "23:59:50"
- platform: event
event_type: event_template_reloaded
- platform: homeassistant
event: start
sensor:
- name: "Propane Used Percent"
unit_of_measurement: "%"
unique_id: "propane_used_percent"
state: >-
{% if (states('sensor.temporary_propane_used_today') | float) < 0 %}
0
{% set propane_filled_percent = states('sensor.temporary_propane_used') | float %}
{% else %}
{{ states('sensor.temporary_propane_percent_used') | float }}
{% endif %}
# reset yesterdays propanne percent
- trigger:
- platform: time
at: "23:59:59"
- platform: event
event_type: event_template_reloaded
- platform: homeassistant
event: start
sensor:
- name: "Yesterdays Propane Percent"
unit_of_measurement: "%"
unique_id: "yesterdays_propane_percent"
state: >-
{{ (states('sensor.tank_percentage')) }}
utility_meter:
daily_energy_propane:
source: sensor.todays_propane_kwh
name: 'Propane Used Last 24h'
cycle: daily
net_consumption: true
The code does not seen to work for the template trigger (at 23:59:50) to get the values into propane_used_percent - not sure why. I do not see an issue with the yaml??
Petro - thanks for your help. I have done some reading on input_number…but still have questions
I need the propane_used_percent in a sensor so that I can calculate usage - Correct???
I therefore assume you mean to not use the temporary_propane_used_today sensor and store the difference of yesterdays_propane_percent -todays_propane_percent in the input.daily_propane_percent_used…
Therefore
Goto Helpers and create new helper called input.number.daily_propane_percent_used (as a number type)
Go to automations
new automation with trigger time of 23:59:50.
Action: Choose Call service-inout.number.set_value
Target: Choose input.number.daily_propane_percent_used
Question #1:
Not sure how to get the value from the temporary sensor into the input.number? It will only let me enter a number into the value field. instead of the states (‘temporary_propane_Percent_used’)???
I even tried to edit the yaml but it will not save??? (see below)
Question #2: After the #1 is fixed how do I get the input.number.daily_propane_percent_used into my propane_percent_used_today location so I can used it to calculate consumption? Do I use the same yaml code but evaluate the state of the input.number??..If <0 the set propane_used to 0 else set to …states(‘input.number.daily_propane_percent_used’) | float)?
OK. I think I got it all working. This is what I did. The values appear to be preserved for restarts. The only thing that it lacks is that on the day the tank is filled … it will not calculate any usage and it does not tell you how much was filled in the tank. This can be added into the calculations if you want once you get it working.
ONE QUESTION
From the research I have done it appears the it is about 27kWh for each gallon of LPG. On cold days my tank uses about 1% which is 5 gallons. That correlates to 135 kWh…that seems like a lot ???
Does that make sense for usage kWh usage? I only use 5 kWh for electricity…???
Programming Info:
I get my value for the propane tank filled percentage (tank_percentage) from a website (you may get yours from a sensor.)
Created three sensors - gallons in tank, today’s propane_percentage, and todays_propane_kWh - energy consumption
Create daily and hourly utility_meters for propane (see below)
I then created two helpers and two automations.
a. Helpers: yesterdays_propane_percent input number, and daily_propane_percent input number
b. Automations -
a. Automation 1 runs at 23:59:00: Set todays propane usage… (It gets the max of the value therefore if negative (ie the tank was filled it will report 0)