This works fine except that several times each day the curl command results in the entity’s value being 0 (I don’t know why).
So, I wanted to create some code that ignored any 0 value, and tried this:
template:
- sensor:
- name: "Propane 371 Gallons Test"
unit_of_measurement: "Gallons"
state_class: measurement
state: >
{% set s = states("sensor.propane_tank_neevo_371")|float(0) * 2.4 %}
{% if s = 0 %}
100
{% else %}
s
I just used “100” as a placeholder but even this code doesn’t work.
Can someone suggest a way to ignore any 0 percentage results from the curl command (better to ignore it at that stage than at the gallons entity creation stage?
Do I understand correctly that this tests for value_json[0].level being greater than 0 (in which case, the value of sensor.propane_tank_neevo_371 gets the value of json[0], otherwise (else) it gets the value of sensor.propane_tank_371?
If so, where does sensor.propane_tank_371 come from?
I have the last recorded value but in gallons (not in percentage, which sensor.propane_tank_371 uses) in sensor.propane_371_gallons
template:
-sensor:
- name: "630 Amerigas Tank Percentage Gallons"
state: >
{% set value = states('sensor.multiscrape_amerigas_tank_percentage_raw_3420398') * 1.2 if sensor.multiscrape_amerigas_tank_percentage_raw_3420398 is defined else this.state %}
{{ value | replace('%', '') | int }}
What is the value of the sensor after you restart HA? I’m using the same strategy to default to this.state but my sensor is set to unknown after restarting.