My energy provider is charging me a fee every month and I would like to divide this charge through the amount of days that month.
The general idea is to use Python’s monthrange:
- platform: template
sensors:
daily_cost_electrics:
friendly_name: Daily cost of electrics
value_template: >
{% set e = states('sensor.monthly_cost_electrics') %}
{% set y = now().strftime('%Y') %}
{% set m = now().strftime('%m') %}
{% r = monthrange(y, m) %}
{{ e / r | float(0) | round(2) }}
I’m going to use this sensor in the Energy dashboard and it will allow me to spread the fixed cost of energy evenly throughout the month. With your “trick” I would pay the whole fixed cost on the first day, then again half on the second day, a thrid on the third day, etc. etc. @123 has provided a great sollution to solve my issue.