type: custom:html-template-card ignore_line_breaks: true content: > {% set area_sensor = "sensor.load_shedding_area_tshwane_3_garsfonteinext8" %} {% set number_of_days = 2 %} {% set show_day_borders = false %} {% set show_end_times = false %} {% set timeslots = 48 %} {%- set area_schedule = state_attr(area_sensor, "forecast") %} {%- if area_schedule is none %}{% set area_schedule = [] %}{% endif %} {%- for day_offset_idx in range(number_of_days) %} {%- set today_datetime_midnight = now().replace(hour=0,minute=0,second=0,microsecond=0) + timedelta(days=day_offset_idx) %}

{{ today_datetime_midnight.strftime("%A, %B %-d") }}

{%- set ns = namespace(active_class_name="", last_slot_was_active=false, current_slot_was_activated=false) %} {%- for half_hour_time_slot_idx in range(timeslots) %} {%- set half_hour_time_slot = today_datetime_midnight + timedelta(minutes=30*half_hour_time_slot_idx) %} {%- set ns.active_class_name = "" %} {%- set ns.current_slot_was_activated = false %} {%- for loadshedding in area_schedule %} {%- if not ns.current_slot_was_activated %} {%- if loadshedding["start_time"] <= half_hour_time_slot < loadshedding["end_time"] %} {%- if not ns.last_slot_was_active %} {%- set percentage_of_region = (half_hour_time_slot_idx/timeslots)*100 %}   {{ half_hour_time_slot.strftime("%H:%M") }} {%- endif %} {%- set ns.current_slot_was_activated = true %} {%- set ns.last_slot_was_active = true %} {%- set ns.active_class_name = "active_slot active_slot_" + loadshedding['stage']|lower|replace(' ','_') %} {%- endif %} {%- endif %} {%- endfor %} {%- if not ns.current_slot_was_activated %} {%- if show_end_times and ns.last_slot_was_active %} {%- set percentage_of_region = (half_hour_time_slot_idx/timeslots)*100 %}   {{ half_hour_time_slot.strftime("%H:%M") }} {%- endif %} {%- set ns.last_slot_was_active = false %} {%- endif %}
 
{%- endfor %} {%- if day_offset_idx == 0 %} {%- set current_time_indicator_progress = now().hour*2 + now().minute/30 %} {%- set percentage_of_region = (current_time_indicator_progress/timeslots)*100 %}   {%- if not show_end_times %} Now {%- endif %} {%- endif %}
{%- endfor %}