I am slowly migrating to HASS from OpenHAB and was wondering how to get the loadshedding into Home Assistant. Was thinking of migrating my solution from OpenHAB or installing the integration when I discovered this quite simple way:
https://eskomcalendar.co.za/ publishes calendars for loadshedding schedules which are quite handy.
At the bottom of the page you can get the link to the ICS feed for example:
https://github.com/beyarkay/eskom-calendar/releases/download/latest/city-of-cape-town-area-7.ics
I’ve then created a config package called loadshedding.yaml
(included below) that brings the calendar into Home Assistant. It should appear as a calendar tab on your interface:
(obviously you need to change the URL in the file to match your area).
This creates calendar.loadshedding
which is mainly a binary sensor whether it’s currently loadshedding. Plus it has attributes.
I then create the following:
sensor.loadshedding_start_time
the start time of the next (or the current loadshedding when in loadshedding). This is extracted from the calendar attributes.sensor.loadshedding_end_time
the end time of the next (or the current loadshedding)- I also added an entity for stats purposes called
sensor.loadshedding_time
which tracks the total time in loadshedding for interest only. Basically would allow you to make stats graphs of how many hours you had each day, week, month etc.
My dashboard looks like this then:
homeassistant:
customize:
sensor.loadshedding_start_time:
friendly_name: "Loadshedding Start"
sensor.loadshedding_end_time:
friendly_name: "Loadshedding End"
sensor.loadshedding_time:
icon: mdi:timer-outline
friendly_name: "Loadshedding Time"
state_class: total_increasing
calendar:
- platform: ics_calendar
calendars:
- name: "Loadshedding"
url: "https://github.com/beyarkay/eskom-calendar/releases/download/latest/city-of-cape-town-area-7.ics"
# exclude the end of schedule entry in the calendar
exclude: "['End of schedule']"
template:
- sensor:
- name: "loadshedding_start_time"
unique_id: "loadshedding_start_time"
device_class: timestamp
state: >
{{ (state_attr('calendar.loadshedding', 'start_time') | as_datetime | as_local).isoformat()}}
- sensor:
- name: "loadshedding_end_time"
unique_id: "loadshedding_end_time"
device_class: timestamp
state: >
{{ (state_attr('calendar.loadshedding', 'end_time') | as_datetime | as_local).isoformat()}}
sensor:
- platform: history_stats
name: loadshedding_time
entity_id: calendar.loadshedding
unique_id: loadshedding_time
state: "on"
type: time
start: "{{ 0 }}"
end: "{{ now() }}"