[GUIDE] Australian Electricity Demand tariffs (e.g AGL)

Yeah sorry all I posted then took a while to fix the indentation when I saw it :frowning:

some old stuff i had in config was messing this up. My mistake. But that said, you guys are crazy quick to reply. Thanks heaps!

One quick question, if i only have TOU tariffs as opposed to demand tariffs, is it ok to remove references to demand tariffs?

Yes that will be fine. You might find other things aren’t needed either such as the workday sensor

I actually got off demand tariffs myself earlier this year. I just set the demand prices to 0 and it works fine. But you can go through it all and remove it completely.

1 Like

Hi SgtBatten,

First thank you very much for this guide. I have it all working with my current AGL rates.

I’ve been reading through the post and replies and found this one. I have two export rates, $0.15 for the first 10kWh and $0.07 for everything after that. I have tried to implement a calculation similar to what you have posted here, but I’m really struggling to get this going properly and to include it in daily, monthly, yearly totals, including having an entity that tracks the total export $ for the built in energy dashboard. Did you end up implementing something like this?

This is what I have so far:

      - name: Electricity Export Rate Step 1
        unique_id: electricity_export_rate_step_1
        icon: mdi:cash-plus
        unit_of_measurement: $/kWh
        state: "0.15000"
        
      - name: Electricity Export Rate Step 2
        unique_id: electricity_export_rate_step_2
        icon: mdi:cash-plus
        unit_of_measurement: $/kWh
        state: "0.07000"

      - name: Electricity Export Step Value
        unique_id: electricity_export_step_value
        icon: mdi:numeric
        unit_of_measurement: kWh
        state: "10"

      - name: Total Daily Export Earnings
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: $
        state: >
          {% set export = states('sensor.electricity_exported_energy_daily') | float(0) %}
          {% set stepthreshold = states('sensor.electricity_export_step_value') | float(0) %}
          {% set stepone = states('sensor.electricity_export_rate_step_1') | float(0) %}
          {% set steptwo = states('sensor.electricity_export_rate_step_2') | float(0) %}
          {% if export <= stepthreshold %}
            {% set total = export * stepone %}
          {% else %}
            {% set total = (stepthreshold * stepone) + ((export - stepthreshold)*steptwo) %}
          {% endif %}
          {{ (total) | round(2) }}

I’ve not had to deal with the two rates like that but At a quick glance you seem to be doing it exactly how I think it should work.

What’s not working?

I’d chuck it all into developer tools and play around with things until you get some answers.

@QuantumNomad

Try this (and please confirm it works OK), it should give you a sensor that publishes the current FIT rate, by comparing it to the Energy_Meter (enhanced alternative to utility_meter, that you’ll need to install) that tracks the daily exported kWh (also added a monthly and yearly version).

Using the Energy Meter will also give you an entity that tracks the total ‘Compensation’ paid for the daily/monthly/yearly entities also.

For example here’s my daily exported meter, off the HS (Huawei Solar) DTSU-666H meter:

image

and here’s the compensation (FIT paid to me) for that daily kWh exported:

image

Note: For each of these you’ll also see a entity named ‘sensor Compensation’ and entity_ID (example for the power_exported_daily_compensation meter would be: ‘power_meter_exported_power_exported_daily_compensation’) appear, ignore it or make it invisible if desired, but don’t touch. This is the auto created entity that the energy_meter creates per daily/monthly/yearly meter to do its own calculations.

#
#  Uses the Energy_Meter add-on instead of the Utility_Meter, see: https://github.com/zeronounours/HA-custom-component-energy-meter
#
#  Version: 1.0 - Quick draft to assist QuantumNomad to create a sensor that provides the current FIT export rate for electrcity exported. 
#                 Using energy_meter also provides the $ value as a sensor.
#

template: 
  - sensor:
    - name: "Electricity - Export Rate (FIT)"
      unique_id: electricity_export_rate
      unit_of_measurement: "$/kWh"
      device_class: monetary
      icon: mdi:cash-plus
      state: >
        {## Enter compensation per kWh rates below ##}
        {% set rate1 = 0.15 %}
        {% set rate2 = 0.07 %}
        {% set fit_exported_today = states('sensor.power_exported_daily') | float %}
        {% if fit_exported_today <= 10 %} {{rate1}}
        {% else %} {{rate2}}
        {% endif %}

#########################
# EXPORT ENERGY METERS (Provides amounts used or exported and the price paid/received).
# 

energy_meter:

# This takes the DSTU-666H meters lifetime reading (only option) and creates a sensor that shows the daily reading.
# Note: The first time this is run, it will read the power meters (lifetime) reading as that for today ! 
#       Ingore it and/or use the utility_meter.calibrate service to corrects, see 
#       https://github.com/zeronounours/HA-custom-component-energy-meter/issues/52 as to why the utility_meter.reset can't be used.
#
  power_exported_daily:
    unique_id: power_exported_daily
    name: Power - Exported Daily
    source: sensor.power_meter_exported
    source_type: to_grid
    cycle: daily
    price_entity: &fit-rate sensor.electricity_export_rate

  power_exported_monthly:
    unique_id: power_exported_monthly
    name: Power - Exported Monthly
    source: sensor.power_meter_exported
    source_type: to_grid
    cycle: monthly
    price_entity: *fit-rate

  power_exported_yearly:
    unique_id: power_exported_yearly
    name: Power - Exported Yearly
    source: sensor.power_meter_exported
    source_type: to_grid
    cycle: yearly
    price_entity: *fit-rate

# ---------------------------------------------------------------------------

If you want to use this in the Energy Dashboard, you’d need to use:

“Power - Exported Daily” and “Power - Exported Daily Compensation”

i.e. (ignore the HS prefix on my sensors):

1 Like

Thanks for having a look. The code I posted works, I get a sensor that correctly tracks the export earnings and resets at midnight, however I got into a bit of a mess when trying to use this to include in your monthly and yearly totals. I was also hoping to use the built in energy dashboard, but this new export earnings sensor seems to be incompatible with the dashboard in some way. I will have to look deeper into the docs.
The sensor is currently, correctly, showing $1.53, but the dashboard is showing $5.20.

If I find a fix for the energy dashboard I’ll post it here.

Thank you Justin, I’ll give this a shot and report back! Really appreciate your detailed write up.

If its of interest/use, here’s the code that I use for my Red Energy TOU plan, updated to use the above code for FIT (but rate1 and rate2 set to same $0.07 as I’m on fixed FIT).

This gives me meters tracking all peak/shoulder/off-peak and FIT kWh for the day/month/year and associated power costs / FIT compensation for those periods, all using the energy_meter (vs utility_meter). Energy_Meter also supports gas and water btw.

Note:
a) The HS prefix is just denoting the data is from my Huawei solar (using WLCRS integration) as opposed to IoTaWatt / SolarAnalytics data.
b) This doesn’t have a daily connection fee charge included, but that could simply be added by making a sensor that just adds $1.x per day as its sole function, that adding that into a meter or adding into the state formula for power/water/gas.

# Updated 1 July 2023 for new Red Energy Rates
# Updated 1 October 2023 for new Red Energy Rates
# Updated 4 January 2024 to replace static FIT rate with a sensor that allows for use with variable FIT providers

template:
  - sensor:

#  Current_Price_RedEnergy_TOU provides a backup method to allow selecting the 'Use an entity with current rate' in Energy Dashboard.
#  If you set the prices here, remember to ALSO set them in the 'electricity_import_rate_???' and daily supply charge sensors.

    - name: "Electricity - Price" 
      unique_id: electricity_price
      unit_of_measurement: "$/kWh"
      device_class: monetary
      state:  "
        {%set Peak = 0.41745 %}
        {%set WeekdayShoulder = 0.35695 %}
        {%set OffPeak = 0.26928 %}
        {%set H = as_timestamp(now())|timestamp_custom ('%-H')|float(0) %} {##Hour (24-hour clock) as a decimal number. 0, 1, 2, ... 23##}
        {%set w = as_timestamp(now())|timestamp_custom ('%w')|float(0) %} {##HWeekday as a decimal number, where 0 is Sunday and 6 is Saturday.	0, 1, …, 6##}	 
        {##0 for weekday, 1 for weekend##}
        {% if (w == 0) or  (w == 6) %} {% set weekday = 0 %}
        {% else %} {% set weekday = 1 %}
        {% endif %}
        {% set charge = 0 %}
        {##peak##}
        {% if (weekday == 1) and (H >= 7) and (H < 9) %} {{Peak}}
        {% elif (weekday == 1) and (H >= 17) and (H < 20) %} {{Peak}}
        {##weekday shoulder##}
        {% elif (weekday == 1) and (H >= 9) and (H < 17) %} {{WeekdayShoulder}}
        {% elif (weekday == 1) and (H >= 20) and (H < 22) %} {{WeekdayShoulder}}
        {##off peak##}
        {% else %} {{OffPeak}}
        {% endif %}
        "

#  Current FIT rate, rate 1 & 2 allows setting a second rate if variable FIT rates (i.e. $0.15 for first 10kWh, then $0.07 thereafter)

    - name: "Electricity - Export Rate (FIT)"
      unique_id: electricity_export_rate
      unit_of_measurement: "$/kWh"
      device_class: monetary
      icon: mdi:cash-plus
      state: >
        {## Enter compensation per kWh rates below ##}
        {% set rate1 = 0.07 %}
        {% set rate2 = 0.07 %}
        {% set fit_exported_today = states('sensor.hs_power_exported_daily') | float %}
        {% if fit_exported_today <= 10 %} {{rate1}}
        {% else %} {{rate2}}
        {% endif %}

#########################
#
# ALTERNATIVE VERSION TO ABOVE TOU
#

#- platform: template
#    sensors:
#      your_tariff:
#        friendly_name: My Tariff
#        unit_of_measurement: '$/kWh'
#        value_template: >
#          {% set tariff = { "Peak": 0.42790, "Shoulder": 0.36498, "OffPeak": 0.27698 } %}
#          {% set time = { "month": (now().strftime('%m') | int), "hour": (now().strftime('%H') | int), "weekday": (now().weekday() | int ) } %}
#          {%if (time.hour > 21) or (time.hour < 7) %}
#              {{ tariff.OffPeak }}
#          {%elif ((time.month > 10) or (time.month < 4)) and (time.weekday < 5) and ((time.hour > 13) and (time.hour < 20)) %}
#              {{ tariff.Peak }}
#          {%elif ((time.month > 5) and (time.month < 9)) and (time.weekday < 5) and ((time.hour > 16) and (time.hour < 21)) %}
#              {{ tariff.Peak }}
#          {%else%}
#              {{ tariff.Shoulder }}
#         {%endif%}
#

####################################
# IMPORT UTILITY METERS
# See: https://github.com/zeronounours/HA-custom-component-energy-meter

# utility_meter:
energy_meter:

  hs_power_imported_daily:
    unique_id: hs_power_imported_daily
    name: HS Power Imported - Daily
    source: sensor.power_meter_consumption
    source_type: from_grid
    cycle: daily
    price_entity: &electricity-price sensor.electricity_price
    tariffs:
      - peak
      - shoulder
      - offpeak

  hs_power_imported_monthly:
    unique_id: hs_power_imported_monthly
    name: HS Power Imported - Monthly
    source: sensor.power_meter_consumption
    source_type: from_grid
    cycle: monthly
    price_entity: *electricity-price
    tariffs:
      - peak
      - shoulder
      - offpeak

  hs_power_imported_yearly:
    unique_id: hs_power_imported_yearly
    name: HS Power Imported - Yearly
    source: sensor.power_meter_consumption
    source_type: from_grid
    cycle: yearly
    price_entity: *electricity-price
    tariffs:
      - peak
      - shoulder
      - offpeak


#########################
# EXPORT UTILITY METERS
# See: https://github.com/zeronounours/HA-custom-component-energy-meter

  hs_power_exported_daily:
    unique_id: hs_power_exported_daily
    name: HS Power - Exported Daily
    source: sensor.power_meter_exported
    source_type: to_grid
    cycle: daily
    price_entity: &fit-rate sensor.electricity_export_rate

  hs_power_exported_monthly:
    unique_id: hs_power_exported_monthly
    name: HS Power - Exported Monthly
    source: sensor.power_meter_exported
    source_type: to_grid
    cycle: monthly
    price_entity: *fit-rate

  hs_power_exported_yearly:
    unique_id: hs_power_exported_yearly
    name: HS Power - Exported Yearly
    source: sensor.power_meter_exported
    source_type: to_grid
    cycle: yearly
    price_entity: *fit-rate


#########################
#
# GROUP - TO SUM UP THE DAILY / MONTHLY / YEARLY IMPORT KWH and $ SENSORS
#         TO GIVE A TOTAL OF EACH
#

sensor:

# DAILY
  - platform: group
    name: HS Power Imported - Daily Total kWh
    unique_id: hs_power_imported_daily_total_kwh
    type: sum
    entities:
      - sensor.hs_power_imported_daily_peak
      - sensor.hs_power_imported_daily_shoulder
      - sensor.hs_power_imported_daily_offpeak

  - platform: group
    name: HS Power Imported - Daily Total Cost
    unique_id: hs_power_imported_daily_total_cost
    type: sum
    entities:
      - sensor.hs_power_imported_daily_cost_peak
      - sensor.hs_power_imported_daily_cost_shoulder
      - sensor.hs_power_imported_daily_cost_offpeak

# MONTHLY
  - platform: group
    name: HS Power Imported - Monthly Total kWh
    unique_id: hs_power_imported_monthly_total_kwh
    type: sum
    entities:
      - sensor.hs_power_imported_monthly_peak
      - sensor.hs_power_imported_monthly_shoulder
      - sensor.hs_power_imported_monthly_offpeak

  - platform: group
    name: HS Power Imported - Monthly Total Cost
    unique_id: hs_power_imported_monthly_total_cost
    type: sum
    entities:
      - sensor.hs_power_imported_monthly_cost_peak
      - sensor.hs_power_imported_monthly_cost_shoulder
      - sensor.hs_power_imported_monthly_cost_offpeak

# YEARLY
  - platform: group
    name: HS Power Imported - Yearly Total kWh
    unique_id: hs_power_imported_yearly_total_kwh
    type: sum
    entities:
      - sensor.hs_power_imported_yearly_peak
      - sensor.hs_power_imported_yearly_shoulder
      - sensor.hs_power_imported_yearly_offpeak

  - platform: group
    name: HS Power Imported - Yearly Total Cost
    unique_id: hs_power_imported_yearly_total_cost
    type: sum
    entities:
      - sensor.hs_power_imported_yearly_cost_peak
      - sensor.hs_power_imported_yearly_cost_shoulder
      - sensor.hs_power_imported_yearly_cost_offpeak


#######################
#
# Checks the time and based upon TOU rate times, updates the 'hs_power_imported_daily/monthly/yearly' entities to use Peak / Shoulder / OffPeak tariff
#

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: 'Set Electricity Tariff (Huawei Solar) depending upon the day of week and time'
    trigger:
      - platform: time
        at: '07:00:30'
      - platform: time
        at: '09:00:30'
      - platform: time
        at: '17:00:30'
      - platform: time
        at: '20:00:30'
      - platform: time
        at: '22:00:30'
      - platform: homeassistant
        event: start
    condition: []
    action:
      - service: select.select_option
        data:
          option: >-
            {% set t = now() %}
            {%- if (( t.hour >= 7 and t.hour < 9 ) or ( t.hour >= 17 and t.hour < 20 )) and
            is_state('binary_sensor.workday_sensor', 'on') %}
              peak
            {%- elif (( t.hour >= 9 and t.hour < 17 ) or ( t.hour >= 20 and t.hour < 22 )) and 
            is_state('binary_sensor.workday_sensor', 'on') %}
              shoulder
            {%- else -%}
              offpeak
            {%- endif -%}
        target:
          entity_id:
#  Selectors used by utility_meter / energy_meter
            - select.hs_power_imported_daily
            - select.hs_power_imported_monthly
            - select.hs_power_imported_yearly
    mode: single

#######################

Using this with the Energy Dashboard gives:


The ‘Daily Yield’ shows a Primary and Secondary inverter (not a duplicate error).

Configured using:

then repeated for the Shoulder and Off Peak (kWh and Cost entities).

this is so cool. I’ve just been forced onto demand tariff and was thinking about how to update my (non-demand) config. You have saved me a bunch of time - many thanks :slight_smile:

1 Like

@nickt444 let me know if/how you go for adding a Demand sensor? Been meaning to have a stab at adding this for if/when I get forced to such a plan.

Ive recently been moved to a demand tarrif – bastards!
Would anyone be interested in an actual integration that calculates it for you? Even better, does such a thing exist ?

The demand tarrif conditions are … wild! and trying to keep track of all the possible permutations with templates is proving challenging.

Peak charges apply 2pm to 8pm Monday to Friday excluding public holidays.
Shoulder charges apply 7am to 2pm & 8pm to 10pm Monday to Friday and 7am to 10pm on weekends and public holidays.
Off peak charges apply from 10pm to 7am, every day.
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.

I had it down pat with TOU.

@sh00t2kill Did you end up making any progress on the Demand plan?

no, none.
I am keen on the idea, and started thinking about it, but just havent had the time to apply brain to problem :slight_smile:

@SgtBatten are you able to post how you made the card with the 30 minute usage with the line indicating previous maximum demand useage?

Here is the card:

type: custom:state-switch
entity: select.electricity_imported_demand
states:
  low-demand:
    type: custom:mini-graph-card
    entities:
      - entity: sensor.electricity_imported_demand_low_demand
        name: Demand (low)
      - entity: sensor.electricity_demand_max
        color: red
        name: MAX
    hours_to_show: 6
    points_per_hour: 60
    line_width: 1
    agregate_function: max
    font_size: 50
    height: 80
    show:
      name: true
      legend: false
      icon: false
      labels: true
  high-demand:
    type: custom:mini-graph-card
    entities:
      - entity: sensor.electricity_imported_demand_high_demand
        name: Demand (high)
      - entity: sensor.electricity_demand_max
        color: red
        name: MAX
    hours_to_show: 6
    points_per_hour: 60
    line_width: 1
    agregate_function: max
    font_size: 50
    height: 80
    show:
      name: false
      legend: false
      icon: false
      labels: true

It only shows up during a demand window.

1 Like

Perfect, thank you

1 Like

Thanks for this. I have just found out about demand windows! Wacky stuff and difficult to control as one episode of absent mindedness screws you for an entire month!

I am with Amber Electric. As well as the demand charge, they charge the wholesale rate which appears as a live sensor in HA. One “gotcha” is that the price charged is actually the average of the last 5 minutes in each half hour period.

Since this package monitors energy usage each half hour it should be adaptable for this calculation. However I have not the slightest idea where to start. Can anyone help?