I have configured my binary sensor and history_stats platform to count ON time of my heating. I am tracking monthly usage. I’d like to have also monthly cost.
Mathematics would be:
Time_Heating_On * Average_Gas_Usage_Per_Hour * Cost, for example:
98:44 * 1,3 * 3,55
I think for simplicity i could extract just hours from time and then display results of multiplicationbut have no idea kow.
How do i proceed with this, any ideas or somebody has something similar implemented?
This is the best i could get from ChatGPT. I feel i am almost there, but code is giving errors bc of outdatet info in chatgtp
sensor:
- platform: template
sensors:
monthly_heating_cost:
friendly_name: "Monthly Heating Cost"
value_template: >
{% set on_time = state_attr('sensor.heating_this_month', 'value') %}
{% set average_gas_usage_per_hour = 1.3 %} # Replace with your actual value
{% set cost_per_hour = 3.55 %} # Replace with your actual cost
{{ (on_time | float / 3600) * average_gas_usage_per_hour * cost_per_hour | round(2) }}
unit_of_measurement: 'currency_symbol' # Replace with your currency unit