wernerhp / ha.integration.load_shedding

A Home Assistant integration to track your load schedding schedule.
MIT License
113 stars 21 forks source link

Load Shedding Status is 0, but show Unknown in card. #87

Closed Zodiac-69 closed 7 months ago

Zodiac-69 commented 8 months ago

In the Developer tools, both, sensor.load_shedding_stage_eskom and sensor.load_shedding_stage_capetown, show that the current stage is 0, but the State is Unknown.

image

Seems as if the integration is not running, the "API" count does no change every 30 min., only when i reload.

But implementing your 1st card (Mushroom Chips) i get a stage of "Unknown" for both of them. The 2nd card is also failing, i presume for the same reason, not a number when it tries to calculate the stage.

What i see in

Any idea where i can look?

This is the error i see in the log file:

Error while processing template: Template<template=({% set stage_sensor = "sensor.load_shedding_stage_eskom" %} {% set area_sensor = "sensor.load_shedding_area_capetown_14_melkbosstrand" %} {% 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")).total_seconds() | int // 60 %} {% set mins = starts_in % 60 %} {% set hrs = starts_in // 60 % 24 %} {% set days = starts_in // 1440 %} {% set alert = "Load Shedding starts in {d}d {h}h {m}m ({next})".format(d=days, m=mins, h=hrs, next=as_timestamp(start_time) | timestamp_custom("%H:%M", True)) %} {% if starts_in > 1440 %} <ha-alert alert-type="success">{{ states(stage_sensor) }}</ha-alert> {% elif 60 < starts_in <= 1440 %} <ha-alert alert-type="warning">{{ alert }}</ha-alert> {% else %} <ha-alert alert-type="error">{{ alert }}</ha-alert> {% endif %} {% else %} {% set ends_in = timedelta(minutes=state_attr(area_sensor, "ends_in")).total_seconds() | int // 60 %} {% set mins = ends_in % 60 %} {% set hrs = ends_in // 60 % 24 %} {% set days = ends_in // 1440 %} {% set alert = "Load Shedding ends in {d}d {h}h {m}m ({next})".format(d=days, m=mins, h=hrs, next=as_timestamp(end_time) | timestamp_custom("%H:%M", True)) %} <ha-alert alert-type="error">{{ alert }}</ha-alert> {% endif %} {% else %} {% set stage = state_attr(stage_sensor, "next_stage") %} {% set start_time = state_attr(stage_sensor, "next_start_time") %} {% set end_time = state_attr(stage_sensor, "next_end_time") %} {% set starts_in = timedelta(minutes=state_attr(stage_sensor, "starts_in")).total_seconds() | int // 60 %} {% set mins = starts_in % 60 %} {% set hrs = starts_in // 60 % 24 %} {% set days = starts_in // 1440 %} {% if (start_time == 0 or end_time == 0) %} {% set alert = "No Load Shedding" %} {% else %} {% set alert = "Stage {stage} starts in {d}d {h}h {m}m ({next})".format(stage=stage, d=days, m=mins, h=hrs, next=as_timestamp(start_time) | timestamp_custom("%H:%M", True)) %} {% endif %} <ha-alert alert-type="success">{{ alert }}</ha-alert> {% endif %}) renders=250>

Zodiac-69 commented 8 months ago

Hi Werner

Thank you, that resolved the problem. One more, i presume it also has to do with that here is no loadshedding - "timedelta" error in Status Alert code. image

wernerhp commented 8 months ago

Have you tried copying from the latest examples? There were some fixes in the previous release, but you need to update your dashboards

https://github.com/wernerhp/ha.integration.load_shedding/blob/master/examples/dashboards/status_alert.yaml

Zodiac-69 commented 8 months ago

Hi Werner

Thank you, i did. It seems that the error is there until the next API call. The second blank bar is the Status Alert - Should that also show - "No Load Shedding"?

image

wernerhp commented 8 months ago

It should if you have the latest status_alert.yaml dashboard code, yes.