Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Created my longest Template Sensor Yet... a Water Bill Estimator

$
0
0

@forte wrote:

I figured I’d share it for others to ogle and appreciate, and possibly critique or be inspired by. I used my city’s breakdown of how they calculate my bill… and made my own bill estimator.

My water bill is calculated in blocks, there are base charges that are the same every month like the stormwater charge and base-fees for water/sewer, there is static rate charges like the sewer charges, then there’s the actual water usage that’s based on blocks. So the first 6000 gallons are charged at .536 cents a gallon, then gallon 6001-9000 at .697 cents per gallon, and all gallons over 9000 are charged at .858 cents per gallon.

So I set up some variables so I can easily tweak the block break points, or the rates in the future, and then just made three different formulas, and used some if statements to use the particular formula needed for the amount of water I’m projected to use.

    {% set blocks = {
      "first": 6000,
      "second": 9000
    } %}
    {% set rates = {
      "first": 0.00536,
      "second": 0.00697,
      "third": 0.00858,
      "sewer": 0.00562,
      "waterbase": 4.04,
      "sewerbase": 3.39,
      "stormwater": 3.1
    } %}
    
    {% if ((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30) < blocks.first %}
    {{ ((rates.waterbase + rates.sewerbase + rates.stormwater)+(((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30) * rates.sewer) + ((((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30)*rates.first))) | round(2) }}
    {% elif ((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30) < blocks.second %}
    {{ ((rates.waterbase + rates.sewerbase + rates.stormwater)+(((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30) * rates.sewer) + ((blocks.first * rates.first)+((((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30)-6000)*rates.second))) | round(2) }}
    {% elif ((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30) > blocks.second %}
    {{ ((rates.waterbase + rates.sewerbase + rates.stormwater)+(((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30) * rates.sewer) + ((blocks.second * rates.second)+(blocks.first * rates.first)+((((states('sensor.my_house_water_monitor_monthly_water') | float / utcnow().day)*30)-9000)*rates.third))) | round(2) }}
    {% else %}
    ERROR 
    {% endif %}

And then I removed all the line breaks and threw it into my config… and it’s been working well so far!

Just sharing for sharing’s sake. I couldn’t find an example of this anywhere else, and spent over an hour getting it to work, so I figured I’d share it with others. If you want to use this, just replace sensor.my_house_water_monitor_monthly_water with a sensor you have that gives how many gallons of water you’ve used so far this month, and set the variables in the begining of the template with whatever your water provider charges.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>