josephny
(Joseph)
January 8, 2025, 11:28am
1
Can someone please point out what I’m doing wrong?
I get the following error when this automation runs:
Thank you.
Error: Sensor sensor.daily_propane_usage_371_trigger has device class ‘volume_storage’, state class ‘measurement’ unit ‘gal’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘’ (<class ‘str’>)
alias: Propane Usage Daily Update 12 30am
description: ""
triggers:
- trigger: time
at: "00:30:00"
conditions: []
actions:
- action: homeassistant.update_entity
metadata: {}
data:
entity_id:
- sensor.daily_propane_usage_76_trigger
- sensor.daily_propane_usage_125_trigger
- sensor.daily_propane_usage_255_trigger
- sensor.daily_propane_usage_355_trigger
- sensor.daily_propane_usage_371_trigger
- sensor.daily_propane_usage_629_trigger
- sensor.tank_utility_003200223638383015473830
- sensor.daily_propane_usage_630_trigger
mode: single
This is the sensor creation code:
- trigger:
- platform: time
at: "00:40:00"
sensor:
- name: "Daily Propane Usage 371 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_371_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_371_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_371_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% endif %}
state_class: measurement
device_class: volume_storage
- 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) }}
{% endif %}
state_class: measurement
device_class: volume_storage
- name: "Daily Propane Usage 355 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_355_claude') | float %}
{% set current = states('sensor.tank_utility_003200223638383015473830') | float %}
{% set refill = states('input_number.propane_refill_amount_355_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) * 10 }}
{% endif %}
state_class: measurement
device_class: volume_storage
- name: "Daily Propane Usage 125 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_125_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_125_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_125_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% endif %}
state_class: measurement
device_class: volume_storage
- name: "Daily Propane Usage 76 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_76_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_76_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_76_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% endif %}
state_class: measurement
device_class: volume_storage
- name: "Daily Propane Usage 255 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_255_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_255_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_255_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% endif %}
state_class: measurement
device_class: volume_storage
- name: "Daily Propane Usage 629 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_629_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_629_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_629_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% endif %}
state_class: measurement
device_class: volume_storage
Troon
(Troon)
January 8, 2025, 11:32am
2
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) }}
{% endif %}
What if it’s not greater than zero? You need an else
.
Alternatively, just use:
{{ max(((midnight - current) + refill)|round(2), 0) }}
2 Likes
tom_l
January 8, 2025, 11:33am
3
Where is your else
case for when the if
is not true?
This is not optional. All are mandatory:
If
Else
Endif.
1 Like
josephny
(Joseph)
January 8, 2025, 11:56am
5
Thank you.
I made each sensor the following:
- trigger:
- platform: time
at: "00:40:00"
sensor:
- name: "Daily Propane Usage 371 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_371_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_371_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_371_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
Reloaded YAML.
Ran the automation and the same error occurs.
Troon
(Troon)
January 8, 2025, 12:04pm
6
Let’s get directly to where the problem is coming from. Please paste the following into Developer Tools / Template and post the result here:
{% set midnight = states('input_number.midnight_propane_level_371_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_371_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_371_claude') | float(0) %}
midnight: {{ midnight }}
current: {{ current }}
refill: {{ refill }}
sum: {{ ((midnight - current) + refill) | round(2) }}
1 Like
josephny
(Joseph)
January 8, 2025, 12:08pm
8
Sorry, this is complete result:
Result
Result type: string
midnight: 117.6 current: 110.39999999999999 refill: 0.0 sum: 7.2
This template listens for the following state changed events:
Entity : input_number.midnight_propane_level_371_claude
Entity : input_number.propane_refill_amount_371_claude
Entity : sensor.propane_tank_neevo_371_gallons_rest
Troon
(Troon)
January 8, 2025, 12:13pm
9
Thanks, that looks fine. Are you sure it’s the same error (371), or has it moved down to the next tank?
Why are you running an update_entity
at 00:30 on a sensor set to update itself at 00:40?
1 Like
josephny
(Joseph)
January 8, 2025, 2:07pm
10
The STRING type in the result is not the problem?
Troon
(Troon)
January 8, 2025, 2:10pm
11
All entity states are strings. The problem is that the empty string ''
cannot be converted to a number; yet the sensor definition (device class and unit of measurement) means that its state string must represent (“look like”) a numeric value.
1 Like
josephny
(Joseph)
January 8, 2025, 2:29pm
12
I have the automation just for testing for the trigger sensor.
The end goal is to have it updated every day at 00:40.
What is the solution to the error?
Troon
(Troon)
January 8, 2025, 3:02pm
13
The only thing I can think of is that one of the entities feeding into the calculation is not available: the tank rest sensor, perhaps.
Put a default value on all three float
filters and there should be no way that the sensor can be non-numeric:
state: >
{% set midnight = states('input_number.midnight_propane_level_371_claude') | float(0) %}
{% set current = states('sensor.propane_tank_neevo_371_gallons_rest') | float(0) %}
{% set refill = states('input_number.propane_refill_amount_371_claude') | float(0) %}
{{ max(((midnight - current) + refill)|round(2) ,0) }}
Might not be correct if the input is temporarily unavailable, but it’ll at least be numeric.
1 Like
josephny
(Joseph)
January 8, 2025, 7:27pm
14
Now I’m even more confused.
If I run the automation, I do not now get an error.
But, the sensors have a state of UNAVAILABLE.
Current automation:
alias: Propane Usage Daily Update 12 30am
description: ""
triggers:
- trigger: time
at: "00:30:00"
conditions: []
actions:
- action: homeassistant.update_entity
metadata: {}
data:
entity_id:
- sensor.daily_propane_usage_371_trigger
- sensor.daily_propane_usage_76_trigger
- sensor.daily_propane_usage_125_trigger
- sensor.daily_propane_usage_255_trigger
- sensor.daily_propane_usage_355_trigger
- sensor.daily_propane_usage_629_trigger
- sensor.tank_utility_003200223638383015473830
- sensor.daily_propane_usage_630_trigger
mode: single
Current sensors:
- trigger:
- platform: time
at: "00:40:00"
sensor:
- name: "Daily Propane Usage 371 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_371_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_371_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_371_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
- 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
- name: "Daily Propane Usage 355 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_355_claude') | float %}
{% set current = states('sensor.tank_utility_003200223638383015473830') | float %}
{% set refill = states('input_number.propane_refill_amount_355_claude') | float(0) %}
{% if ((midnight - current) + refill) | round(2) > 0 %}
{{ ((midnight - current) + refill) | round(2) * 10 }}
{% else %}
{{ 0 }}
{% endif %}
state_class: measurement
device_class: volume_storage
- name: "Daily Propane Usage 125 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_125_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_125_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_125_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
- name: "Daily Propane Usage 76 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_76_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_76_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_76_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
- name: "Daily Propane Usage 255 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_255_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_255_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_255_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
- name: "Daily Propane Usage 629 trigger"
unit_of_measurement: "gal"
state: >
{% set midnight = states('input_number.midnight_propane_level_629_claude') | float %}
{% set current = states('sensor.propane_tank_neevo_629_gallons_rest') | float %}
{% set refill = states('input_number.propane_refill_amount_629_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
Pasting into TEMPLATE results in:
Clear
Result
Result type: string
midnight: 117.6 current: 110.39999999999999 refill: 0.0 sum: 7.2
This template listens for the following state changed events:
Entity : input_number.midnight_propane_level_371_claude
Entity : input_number.propane_refill_amount_371_claude
Entity : sensor.propane_tank_neevo_371_gallons_rest
But, when I filter all entities by the word “trigger” not all entities appear:
k8gg
January 9, 2025, 3:39am
15
If you read your codes closer, many of your float
didn’t have default value of 0, as Troon suggested earlier:
As a result, if any of those states being non-numeric (for example unknown or unavailable) the entire sensor would become unknown - because the codes are not instructed how exactly you want them to handle edge cases.
There might be other errors. For example, why is one of your calculation coming with a * 10
…?
Also, you want your template sensor to update only upon triggered. Could it be the case that since it is not 00:40:00 just yet, so those sensors naturally have not been triggered, hence unknown…?
1 Like
josephny
(Joseph)
January 9, 2025, 10:03am
16
Thank you @k8gg and @Troon
I understand that I know extremly little about HA, YAML, and programming in general, so please understand I am not arguing – just trying to make sense of it for myself.
I intentionally omitted the default values of those sensors (adding “(0)” after “float”) because I did not want them to be zero in the case of them not being defined. My logic could be wrong, but I’d rather an error or a non-value for the final calculated sensor amount than an incorrect amount.
Regardless, pasting the template @Troon provided in the DEVELOPERS | TEMPLATES showed that the values of those sensors are defined (that is, something other than “available” or “unavailable”), and therefore the default of “0” is not the problem.
(BTW, I also intentionall originally did not have an “else” for the same reason, not realizing it was required. My 30 year old programming skills are from an age when “else” statements were not required.)
The “* 10” is intentional and correct – that one tank has a different sensor that reports the amount off by that amount. Don’t know why, but the integration is not currently supported.
As for the template sensor including a time trigger, I’ve read a bunch of posts that lead me to believe than manually running an automation that includes “homeassistant.update_entity” will override the time trigger. No idea if my understanding is correct on this.
I think that this simple endeavor to get the daily change (“usage,” in my case) is so complicated is because of the readings or updates to the values happen at random times during the day for each tank sensor, so getting a value at (for example) midnight and comparing it to the value as of midnight the day before does not actually provide the day’s usage (and might show up as 0, or some other inaccurate amount).
Thank you very much for your help!
Mayhem_SWE
(Magnus Helin)
January 9, 2025, 3:50pm
17
josephny:
(BTW, I also intentionall originally did not have an “else” for the same reason, not realizing it was required. My 30 year old programming skills are from an age when “else” statements were not required.)
else
is not required. What is required is that your state:
template must render to something , its result cannot be blank / null
.
1 Like
tom_l
January 10, 2025, 8:49am
18
Mayhem_SWE:
else
is not required.
It is most definitely required in this case, how else would they not have a null
result when their if statement resolves to false
?
They only have the one if statement and nothing else in the state template.
1 Like
Mayhem_SWE
(Magnus Helin)
January 10, 2025, 8:58am
19
Is it not completely obvious from my post that what I mean is that it isn’t syntactically required ? Which if you read the part of OP’s post that I was quoting seems fairly clear to me is how he had interpreted previous comments in this thread.
1 Like
josephny
(Joseph)
January 10, 2025, 9:38am
20
FWIW, I (a non-programmer) understand (which means others can also):
The “requirement” of using an ELSE is not because of a language syntax rule, but rather because without it the resolution of the STATE value could be non-existent (i.e., nul), which would mess things up (I don’t know how, but I know it’s a condition we want to avoid).
So, my understanding is that you are both correct.