Load shedding card using the EskomSePush API

Hope someone can help. I have added the code but getting error.

Setup was working all fine and then now its given to ghost although you can see its using the API calls etc, unless they have changed the area name

image
Did a area name check and updated that as it seems to have changed

Any Ideas

Indentation is key in HA

sensor:
  - platform: rest
    name: esp_loadshedding
    resource: https://developer.sepush.co.za/business/2.0/area?id=......
    headers:
      token: B...8
    json_attributes:
      - events
    scan_interval: 3600
    value_template: '{{ value_json.info.name }}'

Any pointers on how to do this if you do not use a templates.yaml file?

Hi

If you replace the rest platform sensor with the GitHub - wernerhp/ha.integration.load_shedding: A Home Assistant integration to track your load schedding schedule. it will create a sensor for your specific area. That sensor has attributes that contain
the schedule.

From there my card code is

    type: markdown
    content: >
      {% set stage_sensor = "sensor.load_shedding_stage_eskom" %} {% set
      area_sensor = "sensor.load_shedding_area_jhbcitypower2_2_parkview" %}  {%
      set start_time = state_attr(stage_sensor, "start_time") %} {% set end_time
      = state_attr(stage_sensor, "end_time") %} {% set area_schedule =
      state_attr(area_sensor, "forecast") %} {% if area_schedule %}
        {% set start_time = area_schedule[0].start_time %}
        {% set end_time = area_schedule[0].end_time %}
        {% if is_state(area_sensor, "off") %}
          {% set starts_in = timedelta(minutes=state_attr(area_sensor, "starts_in")) %}
          {% if is_state_attr(stage_sensor, "stage", 0) or starts_in.seconds > 86400  %}
            <ha-alert alert-type="success">{{ states(stage_sensor) }}</ha-alert>
          {% elif not is_state_attr(stage_sensor, "stage", 0) and 0 < starts_in.seconds <= 86400 %}
            <ha-alert alert-type="warning">Starts in {{ starts_in.seconds // 3600 }}h{{ (starts_in.seconds // 60) - (starts_in.seconds // 3600 * 60) }}m ({{ as_timestamp(start_time) | timestamp_custom("%H:%M", True) }})</ha-alert>
          {% endif %}
        {% else %}
          {% set ends_in = timedelta(minutes=state_attr(area_sensor, "ends_in")) %}
          {% if is_state_attr(stage_sensor, "stage", 0) or ends_in.seconds > 86400 %}
            <ha-alert alert-type="success">{{ states(stage_sensor) }}</ha-alert>
          {% elif not is_state_attr(stage_sensor, "stage", 0) and 0 < ends_in.seconds <= 86400 %}
            <ha-alert alert-type="error">Load Shedding ends in {{ ends_in.seconds // 3600 }}h{{ (ends_in.seconds // 60) - (ends_in.seconds // 3600 * 60) }}m  ({{ as_timestamp(end_time) | timestamp_custom("%H:%M", True) }})</ha-alert>
          {% endif %}
        {% endif %}
      {% endif %} {% set area_forecast = state_attr(area_sensor, "forecast" )%}
      {% if area_forecast %} 
        <table width="100%"  border=0>
        <tbody>
        <tr>
          <td width="34px"><ha-icon icon="mdi:calendar"></ha-icon></td>
          <td align="left" colspan=3>Forecast : :  {{ state_attr(area_sensor, "friendly_name") }}</td>
        </tr>
        {% for forecast in area_forecast[:3] %}
        <tr>
          <td></td>
          <td align="left">
          {{ as_timestamp(forecast.start_time) | timestamp_custom("%A, %b %d", True) }}
          </td>
          <td align="left">
          {{ as_timestamp(forecast.start_time) | timestamp_custom("%H:%M", True) }} - {{ as_timestamp(forecast.end_time) | timestamp_custom("%H:%M", True) }}
          </td>
          <td align="right">{{ forecast.stage }}</td>
        </tr>
        {% endfor %}
        </tbody>
      </table>  {% endif %} {% set area_schedule =
      state_attr(area_sensor,"schedule" )%}  {% if area_schedule %} 
        <table width="100%"  border=0>
        <tbody>
        <tr>
          <td width="34px"><ha-icon icon="mdi:calendar"></ha-icon></td>
          <td align="left" colspan=3>Schedule : : {{ state_attr(area_sensor, "friendly_name") }}</td>
        </tr>
        {% for slot in area_schedule[:3] %}
        <tr>
          <td></td>
          <td align="left">
          {{ as_timestamp(slot.start_time) | timestamp_custom("%A, %b %d", True) }}
          </td>
          <td align="left">
          {{ as_timestamp(slot.start_time) | timestamp_custom("%H:%M", True) }} - {{ as_timestamp(slot.end_time) | timestamp_custom("%H:%M", True) }}
          </td>
          <td align="right">{{ slot.stage }}</td>
        </tr>
        {% endfor %}
        </tbody>
        </table> 
      {% endif %}

New to HA, just completed getting HACS installed, then Werner’s integration. I have an api key from ESP, where is the config file to set it in?

This is working really well for me - but I am struggling to figure out how to change the end time to remove the half hour. Has anybody got a pointer for me?
And thank you Werner. This is a really fantastic integration.

@wernerhp I’ve used your integration in the past and it has worked great!

I tried to use it in a different area however its displaying as ‘All Day’ as opposed to the actual load shedding times. Any advice?

See below image:

Issue resolved. I removed the card and re added and seemed to have resolved the issue.

1 Like

Why does this mention stage 2 and 4 and not just one 2.5 hrs loadshedding session under one stage (stage 4).

Only our wonderful Eskom can answer that. This app only pulls the data directly from ESP api as it displays in the app and im sure the app would have shown the exact same 2 options.

But Im assuming that from your example, is that if it was stage 4, then you would have only had a 30 minute outtage and not the 2 hours for stage 2 and the 30 extra minutes for stage 4. Ive seen that before when we are only affected for 30 minutes between schedules and the implementation of loadshedding. Usually you wouldnt even go off at all for that 30 minutes. Perhaps you already have your answer for what happened that day.

Hi guys,

Any idea why my Load Shedding integration will be showing unknown?
All seems to be working but just showing unknown for both Eskom Stage and Cape Town Stage?
Forecast = off
Quota used is only on 12
And my Area in ethekwini is also Off.

My status alert integration worked quite nicely showing the loadshedding forecast. Since last week I got the following error and the markdown card shows nothing:

TypeError: unsupported type for timedelta minutes component: StrictUndefined

Code:

type: markdown
content: >-
  {%- set stage_sensor = "sensor.load_shedding_stage_eskom" -%}
  {%- set area_sensor = "sensor.load_shedding_area_tshwane_3_garsfonteinext8" -%}
  {%- set stage = state_attr(stage_sensor, "stage") -%}
  {%- set next_stage = state_attr(stage_sensor, "next_stage") -%}
  {%- set next_start = state_attr(stage_sensor, "next_start_time") -%}
  {%- set next_end = state_attr(stage_sensor, "next_end_time") -%}
  {%- set alert = states(stage_sensor) -%}
  {%- set alert_type = "success" -%}
  {% set area_forecast = state_attr(area_sensor, "forecast") -%}
  {%- set starts_in = state_attr(area_sensor, "starts_in") -%}
  {%- set ends_in = state_attr(area_sensor, "ends_in") -%}

  {%- if area_forecast -%}
    {%- set next_start = area_forecast[0].start_time -%}
    {%- set next_end = area_forecast[0].end_time -%}
  {%- endif -%}

  {%- if is_state(area_sensor, "off") and starts_in and next_start and next_end -%}
    {%- set next_in = starts_in if starts_in else 0 -%}
    {%- if next_start == 0 or next_end == 0 -%}
      {%- set next_time = as_timestamp(next_start, default=0.0) -%}
      {%- set alert = "Stage {stage}".format(stage=next_stage) + " starts in {d}d {h}h {m}m ({next})" -%}
    {%- elif not stage and starts_in > 1440 -%}
      {%- set next_time = as_timestamp(next_start, default=0.0) -%}
      {%- set alert = "No Load Shedding" -%}
    {%- else -%}
      {%- set next_time = as_timestamp(next_start, default=0.0) -%}
      {%- set alert = "Load Shedding starts in {d}d {h}h {m}m ({next})" -%}
    {%- endif -%}
    {% if next_in > 1440 %}
      {%- set alert_type = "success" -%}
    {% elif 1440 >= next_in >= 60 %}
      {%- set alert_type = "warning" -%}
    {% elif 60 > next_in %}
      {%- set alert_type = "error" -%}
    {% endif %}
  {%- elif is_state(area_sensor, "on") and ends_in -%}
    {%- set next_time = as_timestamp(next_end, default=0.0) -%}
    {%- set next_in = ends_in if ends_in else 0 -%}
    {%- set alert = "Load Shedding ends in {d}d {h}h {m}m ({next})" -%}
    {%- set alert_type = "error" -%}
  {%- endif -%}

  {%- set next_in_sec = timedelta(minutes=next_in).total_seconds() | int(default=0) // 60 -%}
  {%- set mins = next_in_sec % 60 -%}
  {%- set hrs = next_in_sec // 60 % 24 -%}
  {%- set days = next_in_sec // 1440 -%}
  {%- set alert = alert.format(d=days, m=mins, h=hrs, next=next_time | timestamp_custom("%H:%M", True)) -%}

  <ha-alert alert-type="{{ alert_type }}">{{ alert }}</ha-alert>

Any ideas how to fix this please?

removed and reinstalled integration, working again.

There’s a stage change at 22:00 going from Stage 2 to Stage 4. Enable Multi-stage events to merge it into a single event.

Think some stricter markdown or just an unhandled error in the old template. Fixed in the new dashboard examples.

Bump the minimum event duration to 31m to hide events shorter than 30 minutes.

@katomic