I have a barrel I fill with water, I know the max amount the barrel holds is 50.
I have a pump to fill the barrel, with a water meter attached.
I have a pump to drain the barrel, with a water meter attached.
When I know the barrel is full, I reset my values, and say its at 50.
The issue:
Say if I use 20 gallons, there is 30 gallons left. So my input_number would say 30.
When I start to fill the barrel, I have an mqtt msg coming in for every pulsemeter change, despite that its a super busy mqtt topic, homeassistant stays caught up. But, what im trying to do is have a label show how full the barrel is at all times, not show whats there when its not being filled. So say in this automation:
- service: input_number.set_value
data_template:
entity_id: input_number.water_amount_left
value: >-
{% set X1 = (states('input_number.water_amount_left')|round(1) + states('sensor.water_amount_filled')|round(1))|round(1) %}
{%- if X1 > 50 %}
50.0
{% else %}
{{X1}}
{% endif %}
but when each update is pushed via pulse, the number gets all wonky and jumps all over the place because technically the amount_filled makes changes like
1.2gallons
2.5gallons
2.8 gallonsâŚ
and when the math is done its being computed like
(amount left) + 1.2 turning into (31.2)
(31.2) + 2.5 turning into (33.7)
(33.7) + 2.8 turning into (36.5)
when really, it should only be 32.8 (starting at that 30 mark said above the code)
A-- I understand variables were added to homeassistant automations, but is that a use case here?
Bâ Or should I have a secondary, unseen input_text that has the original amount left before the filling automation started?
again the goal is to keep the visual labels actively changing for aesthetics.
I have tried and stopped this goal a few times, have a array of input_text and input_numbers so on, and messyâd the entire thing up.
Almost guarantee im overthinking the entire scenario.
Also, fwiw, when i pump water out, im doing the same thing, so the water being used at the same time as the barrel being refilled, is also a concern, for overlapping redundant headaches.
Any ones input on the situation would be greatly appreciated!
- Im aware code above may not be exact to what I explained, more or less trying to illustration the usage.