Sharing How To: Adding Ontario Hydro/Electricity Time of Use Rates to Home Assistant

I had a heck of a time adding my Ontario TOU to HA. A lot of the toutorials were just incomplete or wrong or even outdated. So I boiled them all down and created a step by step guide on how to set up a proper TOU for Ontario Hydro so that you can track energy use on your energy dashboard and also see costs for a device

Adding Ontario Hydro/Electricity Time of Use Rates to Home Assistant

Please let me know if somthing is wrong so I can update it

1 Like

Thanks, I might have to mix a bit of your solution in with mine since I’d rather update current rates in the front end with number helpers, for some reason I never though of that :roll_eyes:. I just created a sensor in templates.yaml to accomplish this, but it currently requires updating the file before potential price changes on May. 1 and Nov. 1.

I also did not know about the integrated calendar for holidays, and it’s actually accurate… I spent way too long hunting down an Ontario holiday calendar and stripping out Easter Monday and Truth & Reconciliation.

This was my solution, crude but effective.

# Provide cost/kWh based on 'Time Of Use' (TOU)
- sensor:
    - name: "TOU Cost per kWh"
      unit_of_measurement: CAD/kWh
      device_class: monetary
      state: >
        {% set hour_now = now().hour %}
          {% set offpeak = is_state('calendar.stat_holidays', 'on')
                            or now().weekday() in [5,6]
                            or ((hour_now < 7) or (hour_now >= 19)) %}
          {% set onpeak = (hour_now >= 11) and (hour_now < 17) %}
          {% set this_month = now().month %}
          {# Summer Rates #}
          {% if this_month in [5,6,7,8,9,10] %}
            {% if offpeak %} {{ '0.087' }}
            {% elif onpeak %} {{ '0.182' }}
            {% else %} {{ '0.122' }}
            {% endif %}
          {# Winter Rates #}
          {% elif this_month in [1,2,3,4,11,12] %}
            {% if offpeak %} {{ '0.076' }}
            {% elif onpeak %} {{ '0.158' }}
            {% else %} {{ '0.122' }}
            {% endif %}
          {% else %}
            {{ 'unavailable' }}
          {% endif %}
1 Like

The only holiday missing from the calendar is Civic holidy. Again if my rates are of for one day a year I am okay with that so I dont have to create my own calendar and keep it upto date. Its a good idea to tput the unavailable in there also to prevent the large number to 0 then back to large nubmer that causes spikes in the readings. I also like your use of the IN statment for checking for summer

this_month in [1,2,3,4,11,12] makes it much more readable. I like readabale code more than a 1 liner!!. Just FYI you dont need to do the Else this_minth in as if its not in the first if then it HAS to be in the else? No need to put logic in there!!

It took a lot of digging to figure this one out. Also the Hydro Rates Number Helpers and Tariff Selector, can all be reused for all your devices that you want to calculate energy costs.

I wish the utility meter would store all the data in one utility meter and cost. It would ask for the price for each tariff and you can staticly se the price or use a number helper. Then you could add just a single Utility meter to the energy dashboard, rather than adding 3 consumption devices for every single device and prices. Its so redundant!! Think about a house with 50 energy monitoring devices. that is 150 consumption devices you have to add.

I’m big on readable simple code as well, after all I’m going to have to figure it out again at some point. I originally had a simple else for the winter rates but couldn’t figure out a better way to include the unknown without wrapping the whole thing in a pointless test, there’s not a lot there to test against.

And yes the energy dashboard/configuration could use some work, there’s no lack of mentioning this in the current ‘Month of WTH’.

Yeah sorry I didnt notice it was so you can have the unavailable status. I am trying to find a way now to get my hydro reading from Enova Power. Seems like you can but it will be a day late.

Since this was a top result in my search, I thought I’d share my final config. And this thread was a great help to point me in the right direction, so thanks for that!

My rates are a little different. In Winter, there are 2 time slots.
I also setup multiple template sensors, 1 for a friendly text output to use on dashboards, and another for actual monetary rate associate with the former. And my OnPeak and OffPeak rates are stored in 2 Input Helpers.

This is my rate chart for Wisconsin Public Service
OFF Peak Times:
Summer: (May - Sept) 19:00 to 9:00
Winter: (Oct - April) 12:00 to 16:00 and 21:00 to 8:00
Holiday and Weekends are also OFF Peak

Prerequisites:
Holidays Integration (Holiday - Home Assistant)
My resulting entity = ‘calendar.united_states_wi’ (Be sure to update the references in the below code to match your entity)

Helpers/Sensors Overview:
All done in the GUI. Configurations.yaml was not touched.

Input Helpers:
These are where you enter the actual prices. Since rates fluctuate, an Input helper makes it easy to plug in updated rates without needing to update any templates.

  • input_number.time_of_use_rate_offpeak
  • input_number.time_of_use_rate_peak

Template Sensors:

  • sensor.timeofusecalctext
    (Does the main calculation depending on Time, Month, Weekend/Holiday)
  • sensor.time_of_use_current_rate_calc
    (Determine the current rate, based off the sensor.timeofusecalctext. For USA, the unit MUST be in ‘USD/kWh’ in order to associate it with the Energy dashboard)

sensor.timeofusecalctext

{% set hour_now = now().hour %}
{% set holidayweekend = is_state('calendar.united_states_wi', 'on')
  or now().weekday() in [5,6] %}
{% set this_month = now().month %}
{# Summer Rates #}
{% if this_month in [5,6,7,8,9] %}
  {% if holidayweekend %} {{ 'OffPeak (Summer/Holiday/Weekend)' }}
  {% elif (hour_now >=19 or hour_now <=9 )%} {{ 'OffPeak (Summer)' }}
  {% else %} {{ 'OnPeak (Summer)' }}
  {% endif %}
{# Winter Rates #}
{% elif this_month in [1,2,3,4,10,11,12] %}
  {% if holidayweekend %} {{ 'OffPeak (Winter/Holiday/Weekend)' }}
  {% elif (hour_now >=12 and hour_now <=16 )%} {{ 'OffPeak (Winter/TimeSlotA)' }}
  {% elif (hour_now >=21 or hour_now <=8 )%} {{ 'OffPeak (Winter/TimeSlotB)' }}
  {% else %} {{ 'OnPeak (Winter)' }}
  {% endif %}
{% else %}
  {{ 'unavailable' }}
{% endif %}

sensor.time_of_use_current_rate_calc
Uses a Jinja text compare, ‘in’. If you alter the text values above, make sure your text comparison here are compatible.

{% set timeOfUseText = states('sensor.timeofusecalctext') %}
{% if 'OffPeak' in timeOfUseText %}
{{states('input_number.time_of_use_rate_offpeak')}}
{% elif 'OnPeak' in timeOfUseText %}
{{states('input_number.time_of_use_rate_peak')}}
{% else %}
failed
{% endif %}

Testing/Validation in Dev Tools:

Dashboard Examples: (Using History Graph Card and Mushroom Template Card)
2025-01-02 11_47_47-Overview – Home Assistant — Mozilla Firefox

Updating your Energy Dashboard to use your new Time of Use rates:

Bonus: Determining cost of INDIVIDUAL devices with ToU factored in:
While HA can determine the TOTAL grid price with ToU factored in, we can’t break it down at the indicidual device level. This is a frustrating limitation of HA.

I found this HACs add-on:

Further reading:

Feature Request thread (Open since 2021)

Yeah I found that I didn’t understand the Energy dashboard and how I was using it. This is meant to track your total power coming in from like your main braker. We have hijacked it to show the price of individual things because its the only way to do it really… Really wish they would allow cost for individual items!

Thanks for sharing your code and process. I’m sure this will help others also that are wanting to do this!

It’s nice to see community effort on this, I’m glad this topic has become a “top result in my search”. It would be nice to see someone step up and create an integration that ties all these steps together in a flexible ‘Energy Time of Use’ UI, or at least a flexible blue print… way beyond my skill set.

2 Likes

how does this differ from this one:

i used hacs to install it in my HA a few months back

Hey welcome @Sarum

I never even knew this existed to be honest till you posted it. I’ll have a look at it. the only thing I would steer away from this for is the fact that it’s using an API to connect to some other service which means it could be offline at some points. when I created my helper that shows the peak off peak time it is completely local it’s all calculated locally so there’s no possibility of it being offline. but again I have not had a few minutes to look at it but this is really great and I’ll have a look at it thank you!!