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

is there a way to show the demand tariff and amount?

You could create another cost sensor which combines the daily amount and the monthly demand amount so that in theory it would increase incrementally each day your demand usage went higher.

I chose to make my own energy dashboard. Still got work to do on water and gas.

yeah nice!

i think im going to just understand everything I have setup now that im thinking about it lol!

Sorry again, do you have the AGL max solar feed in amount in NSW.

My first 14kwh is at 10c then everthing thereafter is 5c lol…

I went with the flat 5c. My daily charge is a little less and my general usage is also a little less than yours. not much but when i checked the plans available to me the extra daily charge removed most of the benefit from the first 14kwh exported at a better rate.

https://github.com/SgtBatten/HA-Packages

Worked it out. Automated upload every night. I’ve excluded a few of my packages with more sensitive information.

You’ll see many differences between my OP and the same files on github. In this thread i tried to consolidate it into a single package for simplicity of the post, and save for a few typos, should work just as well.

SgtBatten,

For when you get around to adding a gas meter, thought I’d post my /packages/gas-meter.yaml and /esphome/gas-meter.yaml files up, if they’re of interest.
Based it upon your code above and also some from bits from this good thread https://community.home-assistant.io/t/using-home-assistant-to-calculate-my-energy-bill-using-data-from-my-solar-inverter/344913/1.

Next to go back and add TOU plus Demand tariff rates to my electricity, using Solar Analytics for the import/export/production sensors (toss up between Huawei inverters or IoTaWatt also) and then add add water meter with 0-800L (average) per day tarrif tier and 801L-??? tariff tiers.

See: https://github.com/Roving-Ronin/Home-Assistant

BTW would you know why every screenshot of Energy Dash has kWh Import cost is a positive $ (like we are paid to use kWh), whilst Export is a negative (like we are paying to export)?

I suppose it conforms with how it is labelled and typical pricing conventions. The dashboard shows cost, so importing increased the number and exporting decreases the number.

Your energy bill is a positive number. Prices in shops or online are positive numbers.

@cloudbr34k Hey mate, I’m in same boat as you. Did you manage to get it to work? If so can you please share your yaml code?

Think of it like a simple math problem.

If daily exported kwh < 10
daily exported * 14c,
else
10*14c + (daily exported -10) * 5c

Should be fairly easy to convert to that where required.

For monthly cost sensors you might benefit from saving the daily one to a monthly utility meter or something so the value just accumulated automatically without requiring more math.

Thanks. :slight_smile: Mainly interested in what @cloudbr34k did with the code to only use general usage and demand. My bill only shows General Usage and Demand Usage (4-9pm).

Ahh sorry i didn’t check which response you replied to. I thought it was a different post of theirs.

Your code would be much much simpler than mine. You can disregard the different tariffs in the daily, monthly usage etc you wont need the automations to set the usage tariff as it’s constantly the same. You need to update the demand utility meter and automation to fix the times and remove the high/low demand differentiation (just have demand and no-demand)

1 Like

hey mate, sorry i have the SgtBatterns code added. But I had to redo my HA install a few months ago, then had a baby so this little project has fallen to the side. but what he wrote is what I was going to do.

I might have a crack now actually

1 Like

Hi SgtBatten,

Thankyou for the amazing comprehensive script, as a total noob this is very complex, but also very challenging and too good to just pass on. So I bit the bullet and have been at this all day trying to figure this all out and get it working. Any assistance would be most appreciated.

My setup.
I have a shelly EM which have one clamp on the Grid & one clamp on the Solar feed.

sensor.shelly_em_channel_1_power (Grid)
sensor.shelly_em_channel_2_power (solar)

Ausgrid is my supplier with the following.
Peak: 15:00 to 21:00
Offpeak: 21:00 to neaxt day 15:00
Peak tariff: $0.40920
Offpeak tariff: $0.20950
Feed-in tariff: $0.10400
Daily rate: $1.21

I have created the “packages” folder and the files in there is “energy_costs.yaml” & energy.yaml

  1. energy.yaml (is empty as I don’t know what to put in there)
  2. energy_costs.yaml (has the one I tried to alter for my requirement, below), I’m not sure if its right
  3. I like to keep the shoulder rate in case for the future if things change.
  4. Why is the electricity export power daily showing W.
`### This package assumes you have an import sensor "sensor.electricty_imported_power_kwh" 
### which provides cumulative electricity imported in kWh 
### and an export sensor sensor.electricty_exported_power_kwh 
### which provides cumulative electricity exported in kWh. 
### If you use other sensor names, adjust everything below as required to match. 

sensor:
  - platform: time_date
    display_options:
      - "date"

template:
  - sensor:
      - name: Electricity Import Rate Peak
        unique_id: electricity_import_rate_peak
        icon: mdi:cash-minus
        unit_of_measurement: $/kWh
        state: "0.40920" ### 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.000" ### 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.20950" ### edit to your off peak import rate

      - name: Electricity Export Rate
        unique_id: electricity_export_rate
        icon: mdi:cash-minus
        unit_of_measurement: $/kWh
        state: "0.10400" ### edit to your solar feed-in-tariff /export rate

      - name: Electricity Supply Charge
        unique_id: electricity_supply_charge
        icon: mdi:cash-minus![electricity_export_power_daily|465x499](upload://nt4XK5udLSjvPBr4JgaWknXU8Xr.png)

        unit_of_measurement: $/day
        state: "1.210" ### 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_power_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
          {% set shoulder = states('sensor.electricity_imported_power_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
          {% set peak = states('sensor.electricity_imported_power_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_power_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
          {% set shoulder = states('sensor.electricity_imported_power_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
          {% set peak = states('sensor.electricity_imported_power_daily_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
          {% set feedintariff = states('sensor.electricity_exported_power_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_power_daily:
    source: sensor.shelly_em_channel_1_power
    name: Electricity Imported Power Daily
    cycle: daily
    tariffs:
      - peak
      - shoulder
      - off-peak

  electricity_exported_power_daily:
    source: sensor.shelly_em_channel_2_power
    name: Electricity Exported Power Daily
    cycle: daily

  electricity_demand_max_monthly:
    source: sensor.shelly_em_channel_1_power
    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: '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 and
            is_state('binary_sensor.workday_sensor', 'on') %}
                peak
            {%- else -%}
                off-peak
            {%- endif -%}
        target:
          entity_id:
            - select.electricity_imported_power_daily
    mode: single`

We should start with the import and export sensors.

Your Shelly is giving you power in W but you need energy in kWh. So first you want to make two template sensors, one that gives import and one that gives export in kWh. This is not included in the yaml I’ve provided as it is the first assumption at the top.

You should call them electricty_imported_power_kwh and electricty_exported_power_kwh because that what the package is looking for.

I’m on mobile currently but if you can’t find any examples of how to do it I’ll help of course.

Where you have entered your Shelly entities, change the back to the names of the sensors you make.

Edit: I realise naming them as imported and exported “power” was a bad idea in hindsight. That is just how I colloquially refer to using electricity in the house. Maybe change power to energy for future pricing. I’ll try updating the OP when I have time

Thanks so much for the prompt reply [SgtBatten].

Just for the fullness of my question 4 and your answer and to help others in the future, I have created the 2 sensors & changed them to the below. Settings > Devices & Services > Helpers > Create Helper > Riemann sum integral sensor >
Name: electricty_imported_power_kwh
Input Sensor*: sensor.shelly_em_channel_1_power
Integration method: Left Riemann sum
Precision*: 2 decimals
Metric prefix: k (kilo)
Time unit: Hours
Hit Submit button at the bottom right

Name: electricty_exported_power_kwh
Input Sensor*: sensor.shelly_em_channel_2_power
Integration method: Left Riemann sum
Precision*: 2 decimals
Metric prefix: k (kilo)
Time unit: Hours
Hit Submit button at the bottom right

1 Like

I have also updated the OP to rename power to energy as that is the correct term.

you may want to re-do those helpers now too to avoid a desire to rename them at any later point.

Thanks for the advice… now how do I remove all of the sensors created? do I just delete the whole energy_cost.yaml file?

To remove any sensor you’d need to delete the yaml or integration that creates it, then either restarting HA or searching for the entity and deleting it should make them go away.

Looks like I hit a big roadblock once I deleted the whole energy_cost.yaml file.

I deleted the whole file did a full reboot, then created the 2 sensors, (sensor.electricity_imported_energy_kwh &
sensor.electricity_exported_energy_kwh), recreated the energy_cost.yaml file, added the contents of the file like below. Saved restarted yaml made sure there were no errors, did a full reboot.

This is the result.

Entity: input_number.electricity_demand_max (issue showing power W)
Entity: sensor.days_remaining_in_month (no sensor created)
Entity: sensor.electricity_export_rate (no sensor created)
Entity: sensor.electricity_exported_power_daily (issue showing power W)
Entity: sensor.electricity_import_rate_low_demand (no sensor created))
Entity: sensor.electricity_import_rate_off_peak (no sensor created)
Entity: sensor.electricity_import_rate_peak (no sensor created)
Entity: sensor.electricity_import_rate_shoulder (no sensor created)
Entity: sensor.electricity_imported_power_daily_off_peak (issue showing power W)
Entity: sensor.electricity_imported_power_daily_peak (issue showing power W)
Entity: sensor.electricity_imported_power_daily_shoulder (issue showing power W)

I’m totally stuck…

### This package assumes you have an import sensor "sensor.electricty_imported_power_kwh" 
### which provides cumulative electricity imported in kWh 
### and an export sensor sensor.electricty_exported_power_kwh 
### which provides cumulative electricity exported in kWh. 
### If you use other sensor names, adjust everything below as required to match. 

sensor:
  - platform: time_date
    display_options:
      - "date"

template:
  - sensor:
      - name: Electricity Import Rate Peak
        unique_id: electricity_import_rate_peak
        icon: mdi:cash-minus
        unit_of_measurement: $/kWh
        state: "0.40920" ### 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.000" ### 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.20950" ### edit to your off peak import rate

      - name: Electricity Export Rate
        unique_id: electricity_export_rate
        icon: mdi:cash-minus
        unit_of_measurement: $/kWh
        state: "0.10400" ### edit to your solar feed-in-tariff /export rate

      - name: Electricity Supply Charge
        unique_id: electricity_supply_charge
        icon: mdi:cash-minus
        unit_of_measurement: $/day
        state: "1.210" ### 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_power_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
          {% set shoulder = states('sensor.electricity_imported_power_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
          {% set peak = states('sensor.electricity_imported_power_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_power_daily_off_peak') | float(0) * states('sensor.electricity_import_rate_off_peak') | float(0) %}
          {% set shoulder = states('sensor.electricity_imported_power_daily_shoulder') | float(0) * states('sensor.electricity_import_rate_shoulder') | float(0) %}
          {% set peak = states('sensor.electricity_imported_power_daily_peak') | float(0) * states('sensor.electricity_import_rate_peak') | float(0) %}
          {% set feedintariff = states('sensor.electricity_exported_power_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_power_daily:
    source: sensor.electricity_imported_energy_kwh
    name: Electricity Imported Power Daily
    cycle: daily
    tariffs:
      - peak
      - shoulder
      - off-peak

  electricity_exported_power_daily:
    source: sensor.electricity_exported_energy_kwh
    name: Electricity Exported Power Daily
    cycle: daily

  electricity_demand_max_monthly:
    source: sensor.electricity_imported_energy_kwh
    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: '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 and
            is_state('binary_sensor.workday_sensor', 'on') %}
                peak
            {%- else -%}
                off-peak
            {%- endif -%}
        target:
          entity_id:
            - select.electricity_imported_power_daily
    mode: single