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)
Your code looks awesome - and I would test it - if the energy settings hadn’t disappeared from my control panel in Home Assistant with the latest updates…
I think you have the magic code that will handle propane energy from things like Tank Utility and others!
In case anyone is following this thread for directions, the latest 2022 update had a breaking change to the location of the “Energy” feature. Its now underneath Configuration → Dashboards → Energy.
Error while executing automation automation.percent_propane_today_input_automation: extra keys not allowed @ data[‘value_template’]
Percent Propane Yesterday Input Automation: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘value_template’]
Yes seems to be working. Not sure about day to day sum. May need to change the settings to not reset everyday because it is a consumption sensor (goes positive one day and when nothing is used goes negative amt)