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

yeah i’ll look to do that. I auto backup my configs to a private repo every night but i don’t want to share everything in that repo. I’ll see if I can share packages to a separate one but will take me some time.

I am not making any changes to this currently as I’m not using it yet, I just tested it and got basic functionality while i await more hardware.

There’s not much more than what I posted in water.yaml.

this helper:

and this automation

alias: Water Counter
description: ""
trigger:
  - platform: state
    from: "off"
    to: "on"
    entity_id:
      - binary_sensor.water_meter
condition: []
action:
  - service: counter.increment
    target:
      entity_id:
        - counter.water_counter
    data: {}
mode: queued
max: 10

everything else you’ve seen.

I found a problem with the days remaining in month sensor now that it’s december. It was calculating the difference from Jan this year instead of next year.

Fixed in the OP using this:

          {% 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 }}

Just noticed you have a “sensor.days_passed_in_year” just wondering how you define this sensor, as you don’t have it listed anywhere (above)?

template:
  - sensor:
      - name: Days Passed in Year
        unique_id: days_passed_in_year
        state: >
          {% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
          {% set first = this.replace(month=1, day=1) %}
          {{ (this.date() - first.date()).days + 1 }}

Sgt Batten,

If your interested in trying it, I’ve uploaded my gas yaml files (/esphome and /packages) to: GitHub - jbhobson/Home-Assistant: Home Assistant - Water Meter (esp8266) for Goulburn Mulwaree Council

This is only with a single gas consumption tarrif rate, but it may be of assistant in your wanting to expand this to support your multiple tariff rates. The only problem I’ve encountered is that whilst the ‘Gas Total Cost Daily’ tracking entity shows the correct running total (MJ consumed cost + Daily connection fee), the energy dashboard shows a different cost. Upon investigation it appears that your formula to calculate the daily total is only adding in the consumed cost and failing to add the daily connection fee.

i.e. this section (& I assume the same error applies to the monthly and yearly totals also):

        state: >
          {% set supply = states('sensor.gas_daily_supply_charge') | float(0) %}
          {% set usage = states('sensor.gas_consumed_daily_mj') | float(0) * states('sensor.gas_cost_per_mj') | float(0) %}
          {{ (supply + usage) | round(2) }}

Have you encountered this issue also with your code, or would you have any suggestions?

PS: If you want to use the esphome yaml file, you can’t scp it to your HA instance. For some reason it rejects code updated this way, instead it works if you copy the contents and then edit the device in ESPHome dashboard, by pasting it into the open/being edited device config file.

BTW instead of adding correction factor, and converting to MJ etc in one step, I’ve defined them as individual steps so there is an sensor output for each. IMHO thought that even though this adds some extra sensors, this was handy to have the different m3 / corrected m3 / mj etc values to allow comparing to these on the retailers invoice and making sure they match.

I don’t have water or gas meters configured, you asked what code i had and nothing has changed since, I just made those at the time.

I don’t see why the daily calculation would not be working, it’s the same method as i use in energy.yaml for electricity and that works fine, i also see it reading as 0 in the energy dashboard when it is reading as 65c everywhere else. until i have a meter setup i can’t really investigate.

I have my own dashboard setup which i use instead of the energy dashboard so i’ve not paid attention to that page so far.

SgtBatten,

Could you assist, trying to update your code to below to have an action that caters for:

  • Peak - 7-9am and 5-8pm (weekdays)
  • Shoulder - 9am - 5pm and 8pm - 10pm (weekdays)
  • Off Peak - 10pm - 7am (weekdays) and ‘all weekend’

Your original code is:

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_power_daily
mode: single

Trying the following and can’t seem to workout the syntax / format to use, to amend the action data option section. Trying the following and failing:

    action:
      - service: select.select_option
        data:
          option: >-
            {% set t = now() %}  {%- if t.hour >=07 and t.hour <09 and
            is_state('binary_sensor.workday_sensor', 'on') %}
              peak
            {%- elif t.hour >= 17 or t.hour < 20 -%}
              peak
            {%- elif t.hour >= 22 or t.hour < 7 -%}
              off-peak
            {%- else -%}
              shoulder
            {%- endif -%}
        target:
          entity_id:
            - select.electricity_imported_power_daily

or

    action:
      - service: select.select_option
        data:
          option: >-
            {% set t = now() %}  {%- if ( t.hour >=07 and t.hour <09 ) or ( t.hour >=17 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_power_daily

Any assistance appreciated. BTW the gas coding works great, seems like there’s a bug in the Energy Dashboard since an update going back a few months. Entities have the correct figures, but dashboard displays something else.

Since yours is most complex to define off-peak it’s easier to define the other two instead. Try this

            {% 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 -%}
              off-peak
            {%- endif -%}

Many thanks, will trying and let you know how it goes. Just worked out my Solar Analytics exports the readings in Wh (and Watts, that would easily allow adding a helper to converto to kWh). :man_facepalming:

IIRC previously you encountered an issue where the workday sensor was adding in holdays, and you added an exclusion for a single holiday (bank holidays). Just stubled on this code, that I thought might be of interest to you, as it will exclude ALL holidays for Australia / specified State and also forced work days to only be Mon-Fri, being in line with AU electricity retailers who work on Mon-Fri rates and weekends being off-peak.

  - platform: workday
    name: Workday Sensor
    country: AU
    province: NSW ### your state code
    workdays: [mon, tue, wed, thu, fri]
    excludes: [sat, sun, holiday]

Yes that’s the sensor I’m using and I think what you have done for workdays and excludes is the default behaviour, hence I don’t have either in my OP. I did have to remove a holiday so that the sensor wasn’t counting the bank holiday a public holiday.
So I wasn’t excluding it from being a workday but removing it from being a holiday.

Sorry got it the wrong way around. I was just thinking for ‘future proofing’, in case any new holidays are added to Australia in future (or get pushed to Mon-Fri, like we just had for Christmas/Boxing Day holidays), that this would mean they’d automatically be excluded in future.

This could be done with (below), by adding holidays to workdays, it should mean any and all holidays are excluded for the tariff purposes, with only M-F vs Weekend being the output. ?

    workdays: [mon, tue, wed, thu, fri, holiday]
    excludes: [sat, sun]

I’m not sure our goals are the same.

AGL considers public holidays as weekend days for me. So my workday sensor is setup to be true Monday to Friday except if it’s a public holiday. This is the default behaviour and logically makes sense as it is titled workday sensor.

I had to remove the bank holiday because it’s not an actual public holiday but the holiday database was counting it as one.

The sensor automatically handles days that fall on weekends and are observed later.

Oh OK my bad, sorry. Every electricity retailer I’ve even had has been Mon-Fri vs Weekend (24x2 offpeak), didn’t think they did it any other way. :+1:

If you just want Monday to Friday with no exceptions I assume you can just not mention holidays at all.

this is great! im on AGL here in QLD, but this hurts my head when reading through it. ill tackle this another day

I only have 1 Demand,4pm-9pm every day of the year
image

Should be fairly easy to adapt. I’ll give you a hand.

One thing that helps is to go onto the agl website and select change plan, then when on the comparison page you can click on your current plan and see the fine print about your rates etc.

You must have a huge system to export that much? Nice!

Oh man that would be great! i started last night.

Im already using packages to break out my yaml files, and that was confusing enough so for now im just adding everything into each yaml file.

Yeah i have a 13kw system on the roof, north and west facing strings. yet to crack 90kw exported for the day, i can get to 85 on a perfect day lol

At the bottom of my first post is a single code block containing the whole setup which you can put in a single yaml file.

Then, hopefully, all we need to adjust is the automations near the bottom.

yeah i saw that, didnt work as i struggle to understand how to add another package in my package folder already lol

All good, im working my way through it as i dont need all the peak and shoulder sensors etc