As noted above, you need to handle the issue of one or more of your entities’ being unavailable… but, since using a default value could cause inaccurate calculations if only one of the entities isn’t working correctly, it needs to be handled before you apply the float filters:
- sensor:
- name: "Daily Propane Usage 371 with test to more than 0"
unit_of_measurement: "gal"
state_class: measurement
device_class: volume_storage
state: >
{% set midnight = states('input_number.midnight_propane_level_371_claude') %}
{% set current = states('sensor.propane_tank_neevo_371_gallons') %}
{% set refill = states('input_number.propane_refill_amount_371_claude') %}
{% set n_list = [midnight, current, refill] %}
{% if n_list | count != n_list | reject('in', ['unknown','unavailable', none]) | list | count %}
{{ states('sensor.last_Daily_Propane_Usage_371_with_test_to_more_than_0') | default(0, 1) }}
{% else %}
{{ [((midnight | float - current | float) + refill | float) | round(2), 0] | max }}
{% endif %}
Thank you very much for explaining what is necessary and for editing the code.
Unfortunately, while I get the gist of what the code does, the specific mechanics of the code is way above my level (using the “|”, “count”, “reject”, “list”, and “default”, for example).