I’m on tariff with my electricity provider which has ‘peak hour charge’ in the summer between 3:00pm and 7:00pm.
So, I just measured my power usage per hour and tried to stay as low as possible because I interpreted that I would be charged (penalized) by the highest hourly usage.
But … of course, it’s not that easy.
After I inquired because I thought I was overcharged, I was told the penalty is actually based on the highest usage for rolling 60 minutes not per full hour.
So, I implemented a few new sensors, helpers, etc. to be able to record this accordingly.
This is where two automations come into play; they are both very similar and one works reliably while the other one does not.
Here’s the one that works:
alias: Record max kWh Usage per 60min
description: ""
trigger:
- platform: template
value_template: >-
{{ (states.sensor.kwh_used_last_60min.state | float(2) ) >
(states.input_number.max_kwh_usage_per_60min.state |float(2)) }}
condition: []
action:
- service: input_number.set_value
data:
value: "{{ states('sensor.kwh_used_last_60min') }}"
target:
entity_id: input_number.max_kwh_usage_per_60min
mode: single
And here is the one that does not:
alias: Record max kWh Usage per 60min (Peak)
description: ""
trigger:
- platform: template
value_template: >-
{{ (states.sensor.kwh_used_last_60min.state | float(2) ) >
(states.input_number.max_kwh_usage_per_60min_peak.state |float(2)) }}
condition:
- condition: state
entity_id: input_boolean.electricity_peak_recorder
state: "on"
action:
- service: input_number.set_value
data:
value: "{{ states('sensor.kwh_used_last_60min') }}"
target:
entity_id: input_number.max_kwh_usage_per_60min_peak
mode: single
The first automation basically runs all day and gives me the highest 60-minute value; it resets at midnight and seems to be rock-solid.
The second automation is also reset to 0 at midnight but only records when the input_boolean has been switched on because we’re in a peak hour. But, more often than not, it doesn’t start to increase the _peak value when the _recorder switches to on.
I can see in the template editor that the trigger condition is true because the value of the _60min sensor is larger than the _60min_peak input_number one (which is 0 when the _recorder switches on), but the Input_number actually does not get updated until I manually run the action in the automation editor.
I can also see in the automation editor that the template trigger isn’t triggered because the blue banner doesn’t light up when it should. Once I manually ran the action in the automation editor the blue banner lights up and the value updates are happening as they should.
Any idea why the second automation is not working properly?
Or should I somehow figure out how to set it up as a sensor to begin with?