I do apologize. I did a poor job of the title/subject.
Please let me try again.
I have a sensor named: sensor.propane_tank_neevo_630_gallons_rest
This sensor is created by this code:
rest:
- resource: https://ws.otodatanetwork.com/neevoapp/v1/DataService.svc/GetAllDisplayPropaneDevices
authentication: basic
username: "<user>@<domain>.com"
password: "<password>"
scan_interval: 720000000
headers:
Content-Type: application/json
sensor:
- name: "Propane Tank Neevo 630 Gallons Rest"
unique_id: propane_tank_630_gallons_rest
value_template: "{{ value_json[2].Level|float(0) * 1.2 if value_json[2].Level is defined else this.state }}"
state_class: measurement
unit_of_measurement: "gal"
Because the data provider updates the data at random times, and I wanted to get the value as of a set time each day, I set the scan_interval too high to be of any useful value and use the following authomation to update this sensor:
alias: Neevo update 5min past midnight
description: ""
triggers:
- trigger: time
at: "00:05:00"
conditions: []
actions:
- action: homeassistant.update_entity
metadata: {}
data:
entity_id:
- sensor.propane_tank_neevo_630_gallons_rest
mode: single
I would like to have two sensors, as follows:
-
A sensor that shows the difference in value between the latest (or current) reading and the value 10 days earlier – in other words, the total amount of propane used over the past 10 days
-
A sensor that shows the prior 10 day’s moving average of the sensor above (that is, the avergae usage over the past 10 days)
A challenge is that there might be refills of the propane tank, leading to some days showing a higher reading that the prior day. Currently, I use the following code to calculate each day’s difference (hopefully, by taking into account refills, it actually calculates usage, but there is no way (that I know of) to separate figure out any specific day’s usage where there is also a refill of the tank. (To be clear: If the tank starts with 100 gallons in it, and I use 10 gallons of propane that day, and 50 new gallons is delivered, the next reading will show 140 gallons and I will have no way to know if 10 galllons were used and 50 delivered, or (for example) 20 gallons used and 60 delivered.
- name: "Daily Propane Usage 630 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_630_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_630_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_630_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% else %}
{{ 0 }}
{% endif %}
state_class: measurement
device_class: volume_storage
And:
# Input numbers used to store daily propane level 630
midnight_propane_level_630_claude:
name: "Propane Level at Midnight 630 Claude"
min: 0
max: 1000
step: 0.01
propane_refill_amount_630_claude:
name: "Propane Refill Amount Today 630 Claude"
min: 0
max: 1000
step: 0.01
Along with the following automation:
alias: Store Midnight Propane Level and Reset Refill Counter ALL Claude
triggers:
- at: "23:55:00"
trigger: time
actions:
- target:
entity_id: input_number.midnight_propane_level_630_claude
data:
value: "{{ states('sensor.propane_tank_neevo_630_gallons_rest') | float }}"
action: input_number.set_value
- target:
entity_id: input_number.propane_refill_amount_630_claude
data:
value: 0
action: input_number.set_value
I have been working on this for quite a few weeks but because I’m not a programmer and not well versed in any of the required skills, I’m stuck.