Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for calendar entries and some additional sensors #23

Open
w1tw0lf opened this issue Oct 12, 2022 · 14 comments
Open

Suggestion for calendar entries and some additional sensors #23

w1tw0lf opened this issue Oct 12, 2022 · 14 comments

Comments

@w1tw0lf
Copy link

w1tw0lf commented Oct 12, 2022

As per mybroadband.

Small suggesttion, the 2 calendar entries feels like a duplication of each other. Can you perhaps look at changing one to a national schedule ? As an example, where loadsheding in active, like today, 16:00 till 00:00.

Also maybe make Cape Town an option when adding the intergration.

Also maybe a sensor to show the eskomsepush status, like we had on the forums

@w1tw0lf w1tw0lf changed the title Suggestion for calendar entries Suggestion for calendar entries and some additional sensors Oct 12, 2022
@w1tw0lf
Copy link
Author

w1tw0lf commented Oct 12, 2022

Some of the sensor we created that might benefit here as well.

https://github.com/w1tw0lf/homeassitant/blob/main/eskomsepush.yaml

@swartjean
Copy link
Owner

Thanks @w1tw0lf, I will try take a look this evening and give some feedback.

Also maybe a sensor to show the eskomsepush status, like we had on the forums

Can you please point me to an example of this?

@w1tw0lf
Copy link
Author

w1tw0lf commented Oct 12, 2022

The code shared in the yaml is a mix of code from mybb, https://mybroadband.co.za/forum/threads/anyone-figured-how-to-use-eskomsepush-to-control-switches-on-ha.1195256/

Looking at it now, the first rest sensor was a value template, that had static status of ok... think it might have gotten confused and used as a way of checking eskomsepush status. Sorry, my mistake... just thinking it can be something like add to existing sensor to check if their is a valid response when doing an update check.

@louispires
Copy link

+1 for this - Even just the Next_Loadshedding_Event would be helpful.

I want to show how long to go before the next Load Shedding

@w1tw0lf
Copy link
Author

w1tw0lf commented Oct 19, 2022

That part is easy with a value template sensor.

{%if is_state('sensor.loadshedding_local_status', '0') %}none{%else%} In {{ ((as_timestamp(state_attr('calendar.loadshedding_local_schedule', 'start_time') | as_datetime)-as_timestamp(now())) | int /60) | round(0) }} mins {%endif%}

Wouldn´t mind splitting it in to hours and minutes, but haven´t been able to get that part right.

@louispires
Copy link

Thanks @w1tw0lf - I only saw your reply this morning.

Got a little carried away, but I made this:

image

The chip is dynamic, when load_shedding_countdown is none, it will not show.

When you are NOT load shedding, but there is an upcoming schedule, it will do a countdown until Load Shedding will START.

When you ARE load shedding, it will then adjust the icon, and countdown until Load Shedding will END.

Also, when there is less than 1 hour remaining, it will only show minutes

- sensor:
      - name: Load shedding start time
        unique_id: "load_shedding_start_time"
        state: >
          {{ (((as_timestamp(state_attr('calendar.loadshedding_local_schedule', 'start_time') | as_datetime) - as_timestamp(now()))) | round(0)) }}
  - sensor:
      - name: Load shedding end time
        unique_id: "load_shedding_end_time"
        state: >
          {{ (((as_timestamp(state_attr('calendar.loadshedding_local_schedule', 'end_time') | as_datetime) - as_timestamp(now()))) | round(0)) }}
  - sensor:
      - name: Load shedding countdown
        unique_id: "load_shedding_countdown"
        state: >
          {% if is_state('sensor.loadshedding_local_status', '0') %}
          none
          {% elif is_state('calendar.loadshedding_local_events', 'off') %}
          {% if states('sensor.load_shedding_start_time') | int > 0 %}
          {% if states('sensor.load_shedding_start_time') | int < 3600 %}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_start_time') | int | timestamp_custom('%-M min', false) }}{%endif%}
          {% else%}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_start_time') | int | timestamp_custom('%-H hrs & %-M min', false) }}{%endif%}
          {% endif %}
          {% else%}
          none
          {% endif %}
          {% else%}
          {% if states('sensor.load_shedding_end_time') | int > 0 %}
          {% if states('sensor.load_shedding_end_time') | int < 3600 %}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_end_time') | int | timestamp_custom('%-M min', false) }}{%endif%}
          {% else%}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_end_time') | int | timestamp_custom('%-H hrs & %-M min', false) }}{%endif%}
          {% endif %}
          {% else%}
          none
          {% endif %}
          {% endif %}
        icon: >
          {% if is_state("calendar.loadshedding_local_events", "off") %}
          mdi:home-lightning-bolt
          {% else %}
          mdi:home-lightning-bolt-outline
          {% endif %}

@louispires
Copy link

louispires commented Nov 23, 2022

@swartjean How often or when does the Attributes change for calendar.loadshedding_local_events?

image

I have another event coming up later today:
image

This event ended 13 minutes ago, how long before it changes to the next event in the Calendar?

Thanks

@louispires
Copy link

NVM - Seems to be 15 minutes after the previous event ended...

@swartjean
Copy link
Owner

Hey @louispires, sorry for the delay. See this comment in #24.

The calendar state updates every 30 seconds, which means that you should see calendar.loadshedding_local_events change from true to false within 30 seconds of an event ending.

The upcoming calendar events are updated every 15 minutes, so you should see old events removed from the calendar within 15 minutes of them ending. It's not tied to the event itself ending - I think you must have just gotten a bit unlucky with the timing of the previous update being just before the end of the event.

I seem to remember the 15 minute update period for event being a home assistant core thing. I will investigate a bit to see whether it can be made configurable.

@david-bann
Copy link

Thanks @w1tw0lf - I only saw your reply this morning.

Got a little carried away, but I made this:

image

The chip is dynamic, when load_shedding_countdown is none, it will not show.

When you are NOT load shedding, but there is an upcoming schedule, it will do a countdown until Load Shedding will START.

When you ARE load shedding, it will then adjust the icon, and countdown until Load Shedding will END.

Also, when there is less than 1 hour remaining, it will only show minutes

- sensor:
      - name: Load shedding start time
        unique_id: "load_shedding_start_time"
        state: >
          {{ (((as_timestamp(state_attr('calendar.loadshedding_local_schedule', 'start_time') | as_datetime) - as_timestamp(now()))) | round(0)) }}
  - sensor:
      - name: Load shedding end time
        unique_id: "load_shedding_end_time"
        state: >
          {{ (((as_timestamp(state_attr('calendar.loadshedding_local_schedule', 'end_time') | as_datetime) - as_timestamp(now()))) | round(0)) }}
  - sensor:
      - name: Load shedding countdown
        unique_id: "load_shedding_countdown"
        state: >
          {% if is_state('sensor.loadshedding_local_status', '0') %}
          none
          {% elif is_state('calendar.loadshedding_local_events', 'off') %}
          {% if states('sensor.load_shedding_start_time') | int > 0 %}
          {% if states('sensor.load_shedding_start_time') | int < 3600 %}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_start_time') | int | timestamp_custom('%-M min', false) }}{%endif%}
          {% else%}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_start_time') | int | timestamp_custom('%-H hrs & %-M min', false) }}{%endif%}
          {% endif %}
          {% else%}
          none
          {% endif %}
          {% else%}
          {% if states('sensor.load_shedding_end_time') | int > 0 %}
          {% if states('sensor.load_shedding_end_time') | int < 3600 %}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_end_time') | int | timestamp_custom('%-M min', false) }}{%endif%}
          {% else%}
          {% if is_state('sensor.loadshedding_local_status', '0') %}none{%else%}in {{ states('sensor.load_shedding_end_time') | int | timestamp_custom('%-H hrs & %-M min', false) }}{%endif%}
          {% endif %}
          {% else%}
          none
          {% endif %}
          {% endif %}
        icon: >
          {% if is_state("calendar.loadshedding_local_events", "off") %}
          mdi:home-lightning-bolt
          {% else %}
          mdi:home-lightning-bolt-outline
          {% endif %}

This is amazing - exactly what I was trying to figure out how to do. I am a newby - where does this code go? Into the configuration.yaml, or directly to a chip card? Or something else?

@louispires
Copy link

This is amazing - exactly what I was trying to figure out how to do. I am a newby - where does this code go? Into the configuration.yaml, or directly to a chip card? Or something else?

Yeah, simply add a Template section to your configuration.yaml and add these sensors underneath.

@louispires
Copy link

Hey @louispires, sorry for the delay. See this comment in #24.

The calendar state updates every 30 seconds, which means that you should see calendar.loadshedding_local_events change from true to false within 30 seconds of an event ending.

The upcoming calendar events are updated every 15 minutes, so you should see old events removed from the calendar within 15 minutes of them ending. It's not tied to the event itself ending - I think you must have just gotten a bit unlucky with the timing of the previous update being just before the end of the event.

I seem to remember the 15 minute update period for event being a home assistant core thing. I will investigate a bit to see whether it can be made configurable.

BTW, this kind of got more noticeable...

image

These attributes take up to 1 hour to update after load shedding ends, for instance today after 14:30, these will all stay the same up to like 15:30...

I manually reload the integration to force the update.

@gappie
Copy link

gappie commented May 11, 2023

It seems we need the ability to force an API update. From my experience local events status will not change until an API call is made to ESP.

@ipodmusicman
Copy link

@swartjean any chance you can add a service so that we can force an API update? I find that I need to reloasd the integration to get an update on the calendar for the next LS time in the day for instance instead of waiting for it to happen automatically. I want to be able to do an update after power has been restored to ensure that everything is up-to-date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants