Hi all, I am sharing my working configuration for handling demand tariffs which seem fairly unique to Australia and also fairly new to us. I suspect more and more people will find themselves on it over the next few years.
There is a lot to read here, but i’ve also put it all together in one package at the end of this post.
Assumptions:
- You are on a demand tariff (which requires a smart meter)
- You have working electricity usage sensors
-
sensor.electricity_imported_energy_kwh
- a sensor providing a running total of energy imported in kWh -
sensor.electricity_exported_energy_kwh
- a sensor providing a running total of energy exported in kWh- If you do not get paid to export electricity, ignore export sensors and adjust as required.
-
What is a Demand Tariff?
- A demand tariff is an additional charge on top of the standard usage rates.
- My personal plan has a daily supply charge and usage is broken into peak, shoulder and off peak rates depending on the time and day of the week.
- Demand rates are then extra charges on top, again dependant on the time and day.
- Demand usage is only considered on work days, so weekends and public holidays are not included (for some of it).
- Demand charges are a single variable charge applied per calendar month.
- Demand rates are broken into high and low season rates.
- Low season rates apply in April, May, September and October.
- All other months are considered high season.
- Demand is only applicable during certain peak hours. For this guide I’ll base it off AGLs demand windows which are:
- High-season Demand - From 2 pm to 8 pm on working weekdays during 1 November to 31 March (inclusive) – the ‘summer months’. From 5 pm to 9 pm on working weekdays during 1 June to 31 August (inclusive) – the ‘winter months’.
- Low-season Demand - From 2 pm to 8 pm on working weekdays during 1 April to 31 May and 1 September to 31 October (inclusive) – the non-summer and non-winter months
How is the demand tariff calculated?
The TLDR is that the highest 30 minutes of demand usage during the demand windows for the month, in kW, is charged at the applicable demand rate on all days in the month.
What the heck?
It took me a while to get my head around it at first too. Let me explain.
Determine the highest 30 minutes of imported electricity (during a demand period) within the whole month. It might occur on the 1st, 13th or 31st of the month. You generally will have a value in kWh reported by your smart meter or other usage source. Let’s say it is 1.5kWh.
Now we need to convert this to kW. I’ve done the hard maths for you and all you need to do is double it, as in order to use 1.5kW in 30 minutes we must have been importing an average of 3kW during that time. So 3kW.
Multiply by the number of days in the month. 3kW * 31 = 93kW
Multiply by the demand rate. 93 * 0.11726 = $10.91
Got it?
The Config
I will not be sharing the setup of my usage sensors as they will be fairly unique to everyone. I will hopefully use clearly identifiable names for the below configuration so you can edit them to your matching sensors as required.
So let’s make this work in Home Assistant.
There are a couple of extra sensors we need to create in order to make this work. I’ve had these configured for a while and there may be better ways to do it now, but they work. Happy for improvements to be suggested.
binary_sensor:
- platform: workday
name: Workday Sensor
country: AU
province: NSW
remove_holidays:
- "Bank Holiday"
sensor:
- platform: time_date
display_options:
- "date"
template:
- sensor:
- name: Days Remaining in Month
unique_id: days_remaining_in_month
state: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.month + 1 if this.month + 1 <= 12 else 1 %}
{% set last = this.replace(year=this.year + 1, month=1, day=1) if now().month == 12 else this.replace(month=next, day=1) %}
{{ (last.date() - this.date()).days - 1 }}
Now, we need to setup some utility meters to break our electricity usage up into the relevant time periods. The first utility meter captures the standard usage broken into peak, shoulder and off peak.
The second meter breaks the has the same source sensor, but looks at usage in 30 minute increments. I’ll explain more later.
The third meter gives us our daily exported kWh. Unlike imported electricity it has no tariffs because I have a flat export rate.
utility_meter:
electricity_imported_energy_daily:
source: sensor.electricity_imported_energy_kwh
name: Electricity Imported Energy Daily
cycle: daily
tariffs:
- peak
- shoulder
- off-peak
electricity_imported_demand:
source: sensor.electricity_imported_energy_kwh
name: Electricity Imported Demand
cron: 0,30 * * * *
tariffs:
- high-demand
- low-demand
- no-demand
electricity_exported_energy_daily:
source: sensor.electricity_exported_energy_kwh
name: Electricity Exported Energy Daily
cycle: daily
Automating the tariff changes
Now we create some automations to change the utility meter to the appropriate tariff at the right time.
This one is for normal usage (peak, shoulder, off peak) and changes all of my relevant utility meters at once. The time triggers are relevant to when My plan changes it’s rates. Use as an example.
alias: Set Electricity Tariff
description: ''
trigger:
- platform: time
at: '07:00:00'
- platform: time
at: '14:00:00'
- platform: time
at: '20:00:00'
- platform: time
at: '22:00:00'
- platform: homeassistant
event: start
condition: []
action:
- service: select.select_option
data:
option: >-
{% set t = now() %} {%- if t.hour >=14 and t.hour <20 and
is_state('binary_sensor.workday_sensor', 'on') %}
peak
{%- elif t.hour >= 22 or t.hour < 7 -%}
off-peak
{%- else -%}
shoulder
{%- endif -%}
target:
entity_id:
- select.electricity_imported_energy_daily
mode: single
This one sets the demand tariff.
Triggers are time based for all times when my demand period could start or end, as well as a homeassistant boot.
I could place the workday sensor as a condition but chose not to in case something went haywire and needed to be corrected on a weekend.
The action is fairly simple, i had to create a template that captured the possible demand windows and output the correct demand tariff name.
The no-demand period is used for all electricity usage that is not subject to demand rates.
alias: Set Electricity Demand Tariff
description: ''
trigger:
- platform: time
at: '14:00:00'
- platform: time
at: '17:00:00'
- platform: time
at: '20:00:00'
- platform: time
at: '21:00:00'
- platform: homeassistant
event: start
condition: []
action:
- service: select.select_option
data:
option: >-
{% set t = now() %} {% if is_state('binary_sensor.workday_sensor', 'on') %}
{%- if ( t.hour >=14 and t.hour <20 and t.month in [11,12,1,2,3] ) or ( t.hour >=17 and t.hour <21 and t.month in [6,7,8] ) -%}
high-demand
{%- elif t.hour >= 14 and t.hour < 20 and t.month in [4,5,9,10] -%}
low-demand
{%- else -%}
no-demand
{%- endif -%}
{%- else -%}
no-demand
{%- endif -%}
target:
entity_id:
- select.electricity_imported_demand
enabled: true
mode: single
Defining rates/tariffs
The tariff values could be set up a few different ways; as sensors, input numbers or as values directly in calculations in subsequent template sensors. The latter means a little more editing should the prices change in the future. I went with sensors.
Note: My peak, shoulder and offpeak rates are actually the same, but may not always be, so i gave myself the flexibility of changing them easily in the future by separating them now.
template:
- sensor:
- name: Electricity Import Rate High Demand
unique_id: electricity_import_rate_high_demand
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.23452"
- name: Electricity Import Rate Low Demand
unique_id: electricity_import_rate_low_demand
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.11726"
- name: Electricity Import Rate Peak
unique_id: electricity_import_rate_peak
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.13156"
- name: Electricity Import Rate Shoulder
unique_id: electricity_import_rate_shoulder
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.13156"
- name: Electricity Import Rate Off Peak
unique_id: electricity_import_rate_off_peak
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.13156"
- name: Electricity Export Rate
unique_id: electricity_export_rate
icon: mdi:cash-plus
unit_of_measurement: $/kWh
state: "0.05000"
- name: Electricity Supply Charge
unique_id: electricity_supply_charge
icon: mdi:cash-plus
unit_of_measurement: $/day
state: "1.03235"
Storing the Max demand usage.
To store the current 30 minute usage I created an input number. Ensure you set the max to an appropriately high number. Better to be higher than not high enough.
input_number:
electricity_demand_max:
name: Electricity Demand Max Value
# initial: 0 # don't use initial as it will reset upon restart
min: 0
max: 20
step: 0.001
This input number is set using an automation, but before I show that I need to point out that this will only give us enough data for calculating the current month. If we want to be able to track the costs over a whole year we need to store all 12 different demand values. I chose to use a utility meter for this over 12 different input values.
Utility meters don’t take input numbers as sources so I made a template sensor to duplicate the input number above.
template:
- sensor:
- name: "Electricity Demand Max"
unique_id: electricity_demand_max_sensor
unit_of_measurement: kWh
state: >
{{ states('input_number.electricity_demand_max') |float(0) }}
Now that sensor can be the source for our utility meter.
utility_meter:
electricity_demand_max_monthly:
source: sensor.electricity_demand_max
name: Electricity Demand Max Monthly
cycle: yearly
tariffs:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
Automations for storing the Max Demand Usage
This automation updates the input number whenever the current 30 minute usage exceeds the stored maximum. Effectively increases in sync with the demand whenever the demand usage is peaking.
alias: Store max demand usage
description: Calculate and store max 30 minute demand in input_value to survive a reboot
trigger:
- platform: state
entity_id:
- sensor.electricity_imported_demand_high_demand
- sensor.electricity_imported_demand_low_demand
condition:
- condition: template
value_template: >-
{{ (trigger.to_state.state | float(0)) >
(states('input_number.electricity_demand_max') | float()) }}
action:
- service: input_number.set_value
data:
value: '{{ trigger.to_state.state | float() | round(3) }}'
target:
entity_id:
- input_number.electricity_demand_max
mode: single
I use this automation to change the utility meter to the current month and reset the recorded max at the start of each month. The max value for the previous month survives this reset within the utility meter.
alias: Set Monthly max demand and reset Stored Max Value
description: ''
trigger:
- platform: time
at: '00:00:00'
- platform: homeassistant
event: start
condition:
- condition: template
value_template: '{{ now().day == 1 }}'
action:
- service: select.select_option
data:
option: '{{ now().month }}'
target:
entity_id:
- select.electricity_demand_max_monthly
- service: input_number.set_value
data:
value: 0
target:
entity_id:
- input_number.electricity_demand_max
mode: single
Calculating the Totals
Finally we pull it all together into a template sensor that gives us the actual costs.
You have two options below. One that just shows the import costs (good for the energy dashboard) and one for the total cost (in my case that includes solar feed in )
template:
- sensor
- name: Total Daily Import Cost
icon: mdi:currency-usd
state_class: total_increasing
device_class: monetary
unit_of_measurement: $
state: >
{% set supply = states('sensor.electricity_supply_charge') | float(0) %}
{% set offpeak = states('sensor.electricity_imported_energy_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
{% set shoulder = states('sensor.electricity_imported_energy_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
{% set peak = states('sensor.electricity_imported_energy_daily_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
{{ (supply + offpeak + shoulder + peak) | round(2) }}
- name: "Electricity Total Cost Daily"
unique_id: electricity_total_cost_daily
icon: mdi:currency-usd
unit_of_measurement: $
state_class: total
device_class: monetary
state: >
{% set supply = states('sensor.electricity_supply_charge') | float(0) %}
{% set offpeak = states('sensor.electricity_imported_energy_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
{% set shoulder = states('sensor.electricity_imported_energy_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
{% set peak = states('sensor.electricity_imported_energy_daily_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
{% set feedintariff = states('sensor.electricity_exported_energy_daily') | float(0) * states('sensor.electricity_export_rate') | float(0) %}
{% set t = now() %}
{% if t.month in [4,5,9,10] %}
{% set demandrate = states('sensor.electricity_import_rate_low_demand') | float(0) %}
{% else %}
{% set demandrate = states('sensor.electricity_import_rate_high_demand') | float(0) %}
{% endif %}
{% set demand = states('input_number.electricity_demand_max') | float (0) * 2 * demandrate %}
{{ (supply + offpeak + shoulder + peak - feedintariff) | round(2) }}
On the energy dashboard you can use the first sensor to give you the total import cost
Here are a couple more sensors that you might be interested in. A sensor that just calculates the additional cost due to the demand. Also one for the total electricity over the whole year using the 12 max values stored in the utility meter we made earlier.
You’ll need to scroll right to see the full year calculation.
Note that in order to use the yearly calculation you will need to create additional utility meters for the import and export usage that cycle yearly.
template:
- sensor:
- name: "Electricity Demand Monthly Cost"
unique_id: electricity_demand_monthly_cost
unit_of_measurement: $
state_class: total
device_class: monetary
state: >
{% set t = now() %}
{% if t.month in [4,5,9,10] %}
{% set demandrate = states('sensor.electricity_import_rate_low_demand') | float(0) %}
{% else %}
{% set demandrate = states('sensor.electricity_import_rate_high_demand') | float(0) %}
{% endif %}
{{states('input_number.electricity_demand_max') | float (0) * 2 * demandrate * ( now().day + states('sensor.days_remaining_in_month') | int(0) ) }}
- name: "Electricity Total Cost Yearly"
unique_id: electricity_total_cost_yearly
icon: mdi:currency-usd
unit_of_measurement: $
state_class: total
device_class: monetary
state: >
{% set supply = states('sensor.electricity_supply_charge') | float(0) * ( states('sensor.days_passed_in_year') | int(0) + 1 ) %}
{% set offpeak = states('sensor.electricity_imported_energy_yearly_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
{% set shoulder = states('sensor.electricity_imported_energy_yearly_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
{% set peak = states('sensor.electricity_imported_energy_yearly_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
{% set feedintariff = states('sensor.electricity_exported_energy_yearly') | float(0) * states('sensor.electricity_export_rate') | float(0) %}
{% set highdemandrate = states('sensor.electricity_import_rate_high_demand') | float(0) %}
{% set lowdemandrate = states('sensor.electricity_import_rate_low_demand') | float(0) %}
{% set demand = ( states('sensor.electricity_demand_max_monthly_1')| float (0) * 31 + states('sensor.electricity_demand_max_monthly_2') | float (0) * 28 + states('sensor.electricity_demand_max_monthly_3') | float (0) * 31 + states('sensor.electricity_demand_max_monthly_6') | float (0) * 30 + states('sensor.electricity_demand_max_monthly_7') | float (0) * 31 + states('sensor.electricity_demand_max_monthly_8') | float (0) * 31 + states('sensor.electricity_demand_max_monthly_11') | float (0) * 30 + states('sensor.electricity_demand_max_monthly_12') | float (0) * 31 ) * 2 * highdemandrate + ( states('sensor.electricity_demand_max_monthly_4') | float (0) * 30 + states('sensor.electricity_demand_max_monthly_5') | float (0) * 31 + states('sensor.electricity_demand_max_monthly_9') | float (0) * 30 + states('sensor.electricity_demand_max_monthly_10') | float (0) * 31 ) * 2 * lowdemandrate %}
{{ (supply + offpeak + shoulder + peak + demand - feedintariff) | round(2) }}
What else do I do with the data
I have a conditional card that shows up whenever we are in the demand windows. It is a graph with two entities, the current max demand usage for the month and the current 30 minute usage. Gives me a live picture of how close I am to busting the current max demand.
Here you can see I went just over during tonight’s demand window. This demonstrates how the maximum demand usage for the month is updated and stored using the automations above. It went from 1.11 to 1.2 during the third 30 minute window and now the max stays at 1.2 until exceeded again, or reset at the end of the month.
I have several gauge cards which give me a snap shot of the usage for the current month and year.
The first gauge is the highest 30 minute demand usage for the month. The second gauge is how much that usage has cost me. The third and fourth gauges are the total monthly and yearly cost so far including demand.
I have a graph just for the last 10 daily charges so i can pick up on any trends relatively quickly. These do not include demand (though easily could if you wanted to).
Complete Package Template
I have all of the above code included as a single file package in home assistant.
in configuration.yaml
homeassistant:
packages: !include_dir_named packages
Then in [root HA config directory]/packages/energy_costs.yaml
### This package assumes you have an import sensor "sensor.electricity_imported_energy_kwh"
### which provides cumulative electricity imported in kWh
### and an export sensor sensor.electricity_exported_energy_kwh
### which provides cumulative electricity exported in kWh.
### If you use other sensor names, adjust everything below as required to match.
binary_sensor:
- platform: workday
name: Workday Sensor
country: AU
### your state code
province: NSW
remove_holidays:
- "Bank Holiday"
sensor:
- platform: time_date
display_options:
- "date"
template:
- sensor:
- name: Days Remaining in Month
unique_id: days_remaining_in_month
state: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.month + 1 if this.month + 1 <= 12 else 1 %}
{% set last = this.replace(year=this.year + 1, month=1, day=1) if now().month == 12 else this.replace(month=next, day=1) %}
{{ (last.date() - this.date()).days - 1 }}
- name: Electricity Import Rate High Demand
unique_id: electricity_import_rate_high_demand
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.23452"
### edit to your high demand import rate
- name: Electricity Import Rate Low Demand
unique_id: electricity_import_rate_low_demand
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.11726"
### edit to your low demand import rate
- name: Electricity Import Rate Peak
unique_id: electricity_import_rate_peak
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.13156"
### edit to your peak import rate
- name: Electricity Import Rate Shoulder
unique_id: electricity_import_rate_shoulder
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.13156"
### edit to your shoulder import rate
- name: Electricity Import Rate Off Peak
unique_id: electricity_import_rate_off_peak
icon: mdi:cash-minus
unit_of_measurement: $/kWh
state: "0.13156"
### edit to your off peak import rate
- name: Electricity Export Rate
unique_id: electricity_export_rate
icon: mdi:cash-plus
unit_of_measurement: $/kWh
state: "0.05000"
### edit to your solar feed-in-tariff /export rate
- name: Electricity Supply Charge
unique_id: electricity_supply_charge
icon: mdi:cash-plus
unit_of_measurement: $/day
state: "1.03235"
### edit to your daily supply charge
- name: "Electricity Demand Max"
unique_id: electricity_demand_max_sensor
unit_of_measurement: kWh
state: >
{{ states('input_number.electricity_demand_max') |float(0) }}
- name: Total Daily Import Cost
icon: mdi:currency-usd
state_class: total_increasing
device_class: monetary
unit_of_measurement: $
state: >
{% set supply = states('sensor.electricity_supply_charge') | float(0) %}
{% set offpeak = states('sensor.electricity_imported_energy_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
{% set shoulder = states('sensor.electricity_imported_energy_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
{% set peak = states('sensor.electricity_imported_energy_daily_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
{{ (supply + offpeak + shoulder + peak) | round(2) }}
- name: "Electricity Demand Monthly Cost"
unique_id: electricity_demand_monthly_cost
unit_of_measurement: $
state_class: total
device_class: monetary
state: >
{% set t = now() %}
{% if t.month in [4,5,9,10] %}
{% set demandrate = states('sensor.electricity_import_rate_low_demand') | float(0) %}
{% else %}
{% set demandrate = states('sensor.electricity_import_rate_high_demand') | float(0) %}
{% endif %}
{{states('input_number.electricity_demand_max') | float (0) * 2 * demandrate * ( now().day + states('sensor.days_remaining_in_month') | int(0) ) }}
- name: "Electricity Total Cost Daily"
unique_id: electricity_total_cost_daily
icon: mdi:currency-usd
unit_of_measurement: $
state_class: total
device_class: monetary
state: >
{% set supply = states('sensor.electricity_supply_charge') | float(0) %}
{% set offpeak = states('sensor.electricity_imported_energy_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
{% set shoulder = states('sensor.electricity_imported_energy_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
{% set peak = states('sensor.electricity_imported_energy_daily_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
{% set feedintariff = states('sensor.electricity_exported_energy_daily') | float(0) * states('sensor.electricity_export_rate') | float(0) %}
{% set t = now() %}
{% if t.month in [4,5,9,10] %}
{% set demandrate = states('sensor.electricity_import_rate_low_demand') | float(0) %}
{% else %}
{% set demandrate = states('sensor.electricity_import_rate_high_demand') | float(0) %}
{% endif %}
{% set demand = states('input_number.electricity_demand_max') | float (0) * 2 * demandrate %}
{{ (supply + offpeak + shoulder + peak - feedintariff) | round(2) }}
input_number:
electricity_demand_max:
name: Electricity Demand Max Value
# initial: 0 # don't use initial as it will reset upon restart
min: 0
max: 20
step: 0.001
utility_meter:
electricity_imported_energy_daily:
source: sensor.electricity_imported_energy_kwh
name: Electricity Imported Energy Daily
cycle: daily
tariffs:
- peak
- shoulder
- off-peak
electricity_imported_demand:
source: sensor.electricity_imported_energy_kwh
name: Electricity Imported Demand
cron: 0,30 * * * *
tariffs:
- high-demand
- low-demand
- no-demand
electricity_exported_energy_daily:
source: sensor.electricity_exported_energy_kwh
name: Electricity Exported Energy Daily
cycle: daily
electricity_demand_max_monthly:
source: sensor.electricity_demand_max
name: Electricity Demand Max Monthly
cycle: yearly
tariffs:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
automation:
### adjust the time triggers below to match when your standard electricity tariff changes (peak, shoulder, offpeak). Adjust the template in the action block as required to match your plan.
- alias: Set Electricity Tariff
description: ''
trigger:
- platform: time
at: '07:00:00'
- platform: time
at: '14:00:00'
- platform: time
at: '20:00:00'
- platform: time
at: '22:00:00'
- platform: homeassistant
event: start
condition: []
action:
- service: select.select_option
data:
option: >-
{% set t = now() %} {%- if t.hour >=14 and t.hour <20 and
is_state('binary_sensor.workday_sensor', 'on') %}
peak
{%- elif t.hour >= 22 or t.hour < 7 -%}
off-peak
{%- else -%}
shoulder
{%- endif -%}
target:
entity_id:
- select.electricity_imported_energy_daily
mode: single
### adjust the time triggers below to match when your demand electricity tariff changes. Adjust the template in the action block as required to match your plan.
- alias: Set Electricity Demand Tariff
description: ''
trigger:
- platform: time
at: '14:00:00'
- platform: time
at: '17:00:00'
- platform: time
at: '20:00:00'
- platform: time
at: '21:00:00'
- platform: homeassistant
event: start
condition: []
action:
- service: select.select_option
data:
option: >-
{% set t = now() %} {% if is_state('binary_sensor.workday_sensor',
'on') %}
{%- if ( t.hour >=14 and t.hour <20 and t.month in [11,12,1,2,3] ) or ( t.hour >=17 and t.hour <21 and t.month in [6,7,8] ) -%}
high-demand
{%- elif t.hour >= 14 and t.hour < 20 and t.month in [4,5,9,10] -%}
low-demand
{%- else -%}
no-demand
{%- endif -%}
{%- else -%}
no-demand
{%- endif -%}
target:
entity_id:
- select.electricity_imported_demand
enabled: true
mode: single
- alias: Store max demand usage
description: Calculate and store max 30 minute demand in input_value to survive a reboot
trigger:
- platform: state
entity_id:
- sensor.electricity_imported_demand_high_demand
- sensor.electricity_imported_demand_low_demand
condition:
- condition: template
value_template: >-
{{ (trigger.to_state.state | float(0)) >
(states('input_number.electricity_demand_max') | float()) }}
action:
- service: input_number.set_value
data:
value: '{{ trigger.to_state.state | float() | round(3) }}'
target:
entity_id:
- input_number.electricity_demand_max
mode: single
- alias: Set Monthly max demand and reset Stored Max Value
description: ''
trigger:
- platform: time
at: '00:00:00'
- platform: homeassistant
event: start
condition:
- condition: template
value_template: '{{ now().day == 1 }}'
action:
- service: select.select_option
data:
option: '{{ now().month }}'
target:
entity_id:
- select.electricity_demand_max_monthly
- service: input_number.set_value
data:
value: 0
target:
entity_id:
- input_number.electricity_demand_max
mode: single