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

Have you reloaded your automations or restarted HA? the automation might not be updated yet

Yes I have reloaded the automations several times and same with restarting HA. I also completely rebooted the whole setup twice, checked the configs till my eye’s are sore…lol

Upload your current version of the relevant utility meters and automation from the package

When I go to the sensor for offpeak its showing as paused, but the peak one is showing collecting. See screen shots



Here is the whole file as requested.Processing: energy_cost.yaml…

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 Peak
        unique_id: electricity_import_rate_peak
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.40920"

      - name: Electricity Import Rate Shoulder
        unique_id: electricity_import_rate_shoulder
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.000"

      - name: Electricity Import Rate Off Peak
        unique_id: electricity_import_rate_off_peak
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.20950"

      - name: Electricity Export Rate
        unique_id: electricity_export_rate
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.10400"

      - name: Electricity Supply Charge
        unique_id: electricity_supply_charge
        icon: mdi:transmission-tower
        unit_of_measurement: $/day
        state: "1.210"

      - name: Total Daily Import Cost
        icon: mdi:currency-usd
        state_class: total
        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) %}
          {{ (supply + offpeak + shoulder + peak - feedintariff) | round(2) }}

utility_meter:
  electricity_imported_energy_daily:
    source: sensor.shelly_em_channel_1_energy
    name: Electricity Imported Energy Daily
    cycle: daily
    tariffs:
      - peak
      - shoulder
      - off-peak
  
  electricity_imported_energy_hourly:
    source: sensor.shelly_em_channel_1_energy
    name: Electricity Imported Energy Hourly
    cycle: hourly
    tariffs:
      - peak
      - shoulder
      - off-peak

  electricity_exported_energy_daily:
    source: sensor.shelly_em_channel_2_energy_returned
    name: Electricity Exported Energy Daily
    cycle: daily
    
  electricity_exported_energy_hourly:
    source: sensor.shelly_em_channel_2_energy_returned
    name: Electricity Exported Energy Hourly
    cycle: hourly

automation:
  - alias: Set Electricity Tariff
    description: ""
    trigger:
      - platform: time
        at: "15:00:00"
      - platform: time
        at: "21:00:00"
      - platform: homeassistant
        event: start
    condition: []
    action:
      - service: select.select_option
        data:
          option: >-
            {% set t = now() %}  
            {%- if t.hour >=15 and t.hour <21 %}
                peak
            {%- else -%}
                off-peak
            {%- endif -%}
        target:
          entity_id:
            - select.electricity_imported_energy_daily
            - select.electricity_imported_energy_hourly
    mode: single

paused is normal when the utility meter is on another tariff. all my peak and offpeak ones currently say paused and shoulder ones say collecting as that is what period I am in.

go to developer tools > states and look for select.electricity_imported_energy_

do you see both the daily and hourly ones?

everything looks perfect, but the automation didn’t change the tariff for the hourly one. I’ve got no idea why.

try removing the automation from the package and create it in the UI via settings>automations.

oh ok, so its not something I have done then…phew.

is there anyway to manually create an automation to just do that one?? if so can you assist. What is strange is that it did that from the time I created it last night.

you can manually do it via dev tools>services and choose select.select_option, then enter the select.electricity… and type off-peak

Did that is this correct??


Yes it worked. now see if it changes itself at 3pm as the automaton should be doing it.

Ok mate will do thanks so much for your valuable help its most appreciated.

Would I have to do this every day or at each hourly change??

well if you do it manually it’s twice a day. 3pm to peak and 9pm to off-peak. But that’s what the automation is meant to do, and does do for your daily one (which is why it’s crazy that it’s not working)

that was my thinking too. One thing that comes to mind now that you share this is that from the time I set it up last night it was peak time so maybe im talking rubbish and thinking the same thing. Then again this setup has been a real headspinner, if not for your kind help and time spent I would have never go it going

The data I am getting now is very interesting if you look at the graphs, I getting some strange readings overnight with the export etc. This could mean that something is being picked up by the shelly EM, which I have noticed working on this now… Maybe I have to move the Shelly out of the meter box completely and have the 2 clamps only going to the cables.

Yes i noticed you had a small export overnight. I can’t help with that side of things as i’m neither experienced with batteries or shellys. There is probably a bunch of info around on these forums though.

Yes last night I even noticed that when I am running on the batteries, the import & export readings are bouncing between sometimes 250w + to 250w - this could be throwing all our calculations haywire. When its switched over to grid it then is perfect, So it needs a load for some reason.

UPDATE

This is for all who are following this post or come across it.

Once I manually changed from peak to offpeak in yaml, it broke everything related, after spending many hours on this I finally resolved my issue.

Remedy
I had one file called energy_cost.yaml This was the biggest mistake as the latest version of HA does not like the Automations part in the same file.
Home Assistant 2023.5.3
Supervisor 2023.04.1
Operating System 10.1
Frontend 20230503.3 - latest

I created a blank automation file using the UI, clicked on the 3 dots at the top and added the automation part, once saved, ran the automation once.

So here is my final config file.

Create a file called energy_cost.yaml in packages folder and added the below.

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 Peak
        unique_id: electricity_import_rate_peak
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.40920"

      - name: Electricity Import Rate Shoulder
        unique_id: electricity_import_rate_shoulder
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.000"

      - name: Electricity Import Rate Off Peak
        unique_id: electricity_import_rate_off_peak
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.20950"

      - name: Electricity Export Rate
        unique_id: electricity_export_rate
        icon: mdi:transmission-tower
        unit_of_measurement: $/kWh
        state: "0.10400"

      - name: Electricity Supply Charge
        unique_id: electricity_supply_charge
        icon: mdi:transmission-tower
        unit_of_measurement: $/day
        state: "1.210"

      - name: Total Daily Import Cost
        icon: mdi:currency-usd
        state_class: total
        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) %}
          {{ (supply + offpeak + shoulder + peak - feedintariff) | round(2) }}

utility_meter:
  electricity_imported_energy_daily:
    source: sensor.shelly_em_channel_1_energy
    name: Electricity Imported Energy Daily
    cycle: daily
    tariffs:
      - peak
      - shoulder
      - off-peak
  
  electricity_imported_energy_hourly:
    source: sensor.shelly_em_channel_1_energy
    name: Electricity Imported Energy Hourly
    cycle: hourly
    tariffs:
      - peak
      - shoulder
      - off-peak

  electricity_exported_energy_daily:
    source: sensor.shelly_em_channel_2_energy_returned
    name: Electricity Exported Energy Daily
    cycle: daily
    
  electricity_exported_energy_hourly:
    source: sensor.shelly_em_channel_2_energy_returned
    name: Electricity Exported Energy Hourly
    cycle: hourly

Then using the method above I created a blank automation file from the UI and added the below.


automation:
  - alias: Set Electricity Tariff
    description: ""
    trigger:
      - platform: time
        at: "15:00:00"
      - platform: time
        at: "21:00:00"
      - platform: homeassistant
        event: start
    condition: []
    action:
      - service: select.select_option
        data:
          option: >-
            {% set t = now() %}  
            {%- if t.hour >=15 and t.hour <21 %}
                peak
            {%- else -%}
                off-peak
            {%- endif -%}
        target:
          entity_id:
            - select.electricity_imported_energy_daily
            - select.electricity_imported_energy_hourly
    mode: single

Thankyou very much for all the hand holding and assistance SgtBatten it seems to now look promising.