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

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

You are missing the template sensor in the package.

For all these, check the statistics page in developer tools and fix the error I assume is there about the unit

For these rate ones, delete the comments on the same line as the rate. I’m not sure if you can have them.

Hi SgtBattten,

Thank you for your prompt reply, sorry for all the dumb questions and long posts. I was up till 2;30am but only been able to resolve this so far this morning from your reply. Not been lucky with the others so far.

You are missing the template sensor in the package.

I added the template to the energy_cost.yaml file

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

For all these, check the statistics page in developer tools and fix the error I assume is there about the unit
I looked in the developer tools >statistic page and it displays W but there is no option to change it to kWh like it should be.

For these rate ones, delete the comments on the same line as the rate. I’m not sure if you can have them.
I have done this but not much success at all.

What is so interesting is that when I created it originally all the sensors, rates were there except that the displayed in W and not kWh.

Since making the changes you recommended and deleting the file and replacing it, everything went pear shape.

What is interesting though is that it created the sensor.electricity_supply_charge, this is the only one that got created the second time.

Do you think I should delete the file (energy_cost_yaml)once again totally and add the file again?

Appreciate your advice.

If you like we could use something like anydesk and I can have a look directly at what is going on?

Sure if you can that would be great…

I deleted the file and recreated a new one called energy_cost1.yaml

Just rebooting to see how it goes.

Having a play with this - I’m in NSW
and…first issue ’ The Workday YAML configuration is being removed’
lol…more playing needed

Yes but you can make it using the UI integration. Mine auto imported into the UI.

image
image
image
image

1 Like

Hi Mate,

Hope you had a great weekend?

Is it possible for you to please help me with a yaml file, so I can just put it in the packages folder and not mess with any part of the existing energy_cost.yaml file that you created for me?

I am trying to get to the bottom of this inconsistent readings I am getting. So I want to compare what I have displayed in powerpal and ausgrid to see where this is going pear shape.

So what I am after is a file called hourly_energy_consumed.yaml

This will take the 4 sensor’s you have already created. If its appropriate, if not…
sensor.electricity_imported_energy_daily_off_peak
sensor.electricity_imported_energy_daily_shoulder
sensor.electricity_imported_energy_daily_peak
sensor.electricity_supply_charge

Create 4 sensor’s as follows
sensor.electricity_imported_energy_hourly_off_peak
sensor.electricity_imported_energy_hourly_shoulder
sensor.electricity_imported_energy_hourly_peak
sensor.electricity_supply_charge_hourly

I would greatly appreciate if you can help me with a script.

All you really need is this one. Just make it have the same source as your daily one.

And you need to update the automation to include this utility meter also so that the tarrifs change at the right time.

I don’t see the point of tracking the supply charge hourly, it’s a fixed rate per day.

utility_meter:
  electricity_imported_power_hourly:
    source: sensor.electricity_imported_energy_kwh
    name: Electricity Imported Power Daily
    cycle: hourly
    tariffs:
      - peak
      - shoulder
      - off-peak


Thanks so much for your prompt help…

So this is what I have currently.

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_exported_energy_daily:
    source: sensor.shelly_em_channel_2_energy_returned
    name: Electricity Exported Energy Daily
    cycle: daily

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

I have changed to this, is it correct?

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 Power Daily
    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

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

Yep just change this on the hourly one. My mistake

Thanks so much mate, made the changes below.

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

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
1 Like

Thanks so much for the information.

Would this work to get the Energy Exported Hourly?

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

Automation

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
            - select.electricity_exported_energy_hourly
    mode: single

First bit yes, but don’t add it to the automation. There are no export tariffs so nothing to change with that automation…

Thanks mate for the prompt reply.

The readings I am getting so far is quite close to powerpal, but I have noticed the following.

  1. I am running on batteries, but can see the offpeak is giving me some stray readings like…
    7pm 0.017kWh
    8pm 0.023kWh
  2. But what is really strange and I just cannot put my fingure on this is that instead of displaying offpeak its showing it as peak usage.

Would you know why its dislaying reading as peak usage and not offpeak usage ?energy_hourly_displaying_as_peak

Isn’t 3pm to 9pm peak according to your automation?

Good morning mate, Thanks for your prompt reply

Yes that is the peak time, but I was charging the batteries after 9pm. Even now its show as I am using peak energy. This has got me totally stumped.energy_hourly_displaying_as_peak_23052023
energy_hourly_displaying_as_peak_23052023_1