wernerhp / ha.integration.load_shedding

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

Automation Ideas #5

Open wernerhp opened 2 years ago

wernerhp commented 2 years ago

This issue is a place where everyone can share their automation ideas or panels they create using this integration.

  1. Specify the release version on which your template works.
  2. Add a screenshot
  3. Put code in a collapsible details tag like so
    
    <details>
    <summary>Code</summary>
EXAMPLE YAML GOES HERE

Capone1983 commented 2 years ago

Hi Great work. I was looking at doing one myself.

If anyone is interested. Add this to configuration.yaml

- platform: template
    sensors:
     load_shedding_next_next:
      friendly_name: "Loadshedding Next Next"
      value_template: >-
         {% if state_attr("sensor.load_shedding_paulshof_ext_65", "schedule")[1].start != None %}
          {{ state_attr("sensor.load_shedding_paulshof_ext_65", "schedule")[1].start | as_datetime - now().strftime("%Y-%m-%d %H:%M%z") | as_datetime }}
         {% else %}
          Unknown
         {% endif %}
     load_shedding_next_start:
      friendly_name: "Loadshedding Next Start"
      value_template: >-
         {% if state_attr('sensor.load_shedding_paulshof_ext_65', 'next_start') != None %}
          {{ state_attr("sensor.load_shedding_paulshof_ext_65", "next_start") | as_datetime - now().strftime("%Y-%m-%d %H:%M%z") | as_datetime }}
         {% else %}
          Unknown
         {% endif %}
     load_shedding_next_end:
      friendly_name: "Loadshedding Next End"
      value_template: >-
        {% if state_attr('sensor.load_shedding_paulshof_ext_65', 'next_end') != None %}
         {{ state_attr("sensor.load_shedding_paulshof_ext_65", "next_end") | as_datetime - now().strftime("%Y-%m-%d %H:%M%z") | as_datetime }}
        {% else %}
         Unknown
        {% endif %}

then in your card

- type: custom:template-entity-row
    icon: mdi:timer-outline
    name: Time Until Start
    state: >-
      {% if not states('sensor.load_shedding_next_start').startswith('-') %} 
      {{states("sensor.load_shedding_next_start")}}  {% else %} 
      {{states("sensor.load_shedding_next_next")}}  {% endif %}
    condition: >-
      {{ not is_state('sensor.load_shedding_paulshof_ext_65', 'No Load
      Shedding') }}
  - type: custom:template-entity-row
    icon: mdi:timer-sand
    name: Time Until End
    state: '{{states(''sensor.load_shedding_next_end'')}}'
    condition: >-
      {{ not is_state('sensor.load_shedding_paulshof_ext_65', 'No Load
      Shedding') and states('sensor.load_shedding_next_start') != None }}
title: Load Shedding

this then will display the next time of loadshedding. During loadshedding display the next schedule and index [1]. Still testing though.

cliffordwhansen commented 2 years ago

As per the v0.2.0-alpha the following is what I use on my dashboard

type: entities
entities:
  - entity: sensor.load_shedding_stage
  - type: custom:template-entity-row
    icon: mdi:timer-outline
    name: Parklands
    state: '{{states(''sensor.load_shedding_parklands'')}}'
    secondary: >-
      {%- macro cleanup(data) -%}
        {%- for item in data.split("\n")  if item | trim != "" -%}
          {{ item | trim }} {% endfor -%}
      {%- endmacro -%}

      {%- macro humanizeMinute(input_minutes) -%}
        {% set hours = (input_minutes / 60)|int %}
        {% set minutes = input_minutes - (hours * 60) %}
        {% set minutes = minutes * -1 %}
        {{ hours }} hr(s) {{ minutes }} min(s)
        {% if input_minutes < 0 %}
        ago
        {% endif %}
      {%- endmacro -%}

      Start {{ cleanup(humanizeMinute(state_attr('sensor.load_shedding_parklands', 'starts_in'))) }} /
      End {{ cleanup(humanizeMinute(state_attr('sensor.load_shedding_parklands', 'ends_in'))) }}
title: Eskom
state_color: true

image image

edit Fixed issue with negative minutes, added screenshot for on state

wernerhp commented 2 years ago

Updated for v0.2.0-alpha

Stage and Area panel

image
Code ```yml type: entities entities: - type: custom:template-entity-row icon: mdi:lightning-bolt-outline name: Status entity: sensor.load_shedding_stage active: '{{ not is_state("sensor.load_shedding_stage", "No Load Shedding") }}' state: '{{states("sensor.load_shedding_stage")}}' - type: custom:template-entity-row icon: mdi:timer-outline name: Milnerton active: '{{ states("sensor.load_shedding_milnerton") == "on" }}' state: >- {{ (state_attr("sensor.load_shedding_milnerton", "start_time") | as_datetime | as_local).strftime("%H:%M") }} - {{ (state_attr("sensor.load_shedding_milnerton", "end_time") | as_datetime | as_local).strftime("%H:%M") }} secondary: >- {% if states("sensor.load_shedding_milnerton") == "off" %} Starts in {{ timedelta(minutes=state_attr("sensor.load_shedding_milnerton", "starts_in")) }} {% else %} Ends in {{ timedelta(minutes=state_attr("sensor.load_shedding_milnerton", "ends_in")) }} {% endif %} entity: sensor.load_shedding_milnerton ```

Schedule panel

image
Code ```yml - type: markdown content: > {% set schedules = state_attr("sensor.load_shedding_milnerton", "schedule") %} {% for s in schedules[:3] %} {% endfor %}
Schedule
{{ as_timestamp(s.start_time | as_datetime) | timestamp_custom("%-d %B %Y", True) }} {{ as_timestamp(s.start_time | as_datetime) | timestamp_custom("%H:%M", True) }} - {{ as_timestamp(s.end_time | as_datetime) | timestamp_custom("%H:%M", True) }}
```
paulbalinnel commented 2 years ago

Groot Dank aan julle! Die integration is bef@k!!!!

n00bster-za commented 2 years ago

cant seem to get the Schedule panel to work.

adding a markdown card and add content change sensor name nothing displays. adding a markdown card then using code editor copy paste code change sensor name nothing displays.

wernerhp commented 2 years ago

cant seem to get the Schedule panel to work.

adding a markdown card and add content change sensor name nothing displays. adding a markdown card then using code editor copy paste code change sensor name nothing displays.

Screenshot of your sensor's attributes from debug console please.

image

image

n00bster-za commented 2 years ago

not sure how to get that.

wernerhp commented 2 years ago

not sure how to get that.

See screenshots above. And please paste your code for your panel here.

Copy and Paste this, then replace [PASTE YOUR CODE] with your code. Preview to check that it looks like this

image
<details>
  <summary>Code</summary>

```yml
[PASTE YOUR CODE]

Drewskieza commented 2 years ago

Load Shedding v0.5.0

image

Code Card ```yml type: entities entities: - type: custom:template-entity-row icon: mdi:lightning-bolt-outline name: Status entity: sensor.load_shedding_stage active: '{{ not is_state("sensor.load_shedding_stage", "No Load Shedding") }}' state: '{{states("sensor.load_shedding_stage")}}' - type: custom:template-entity-row icon: mdi:timer-outline name: Hartbeespoort active: '{{ states("sensor.load_shedding_hartbeespoort") == "on" }}' state: >- {{ (state_attr("sensor.load_shedding_adderley", "start_time") | as_datetime | as_local).strftime("%H:%M") }} - {{ (state_attr("sensor.load_shedding_adderley", "end_time") | as_datetime | as_local).strftime("%H:%M") }} secondary: |- {% if not is_state("sensor.load_shedding_stage", "No Load Shedding") %} {% if states("sensor.load_shedding_adderley") == "off" %} Starts in {{ timedelta(minutes=state_attr("sensor.load_shedding_adderley", "starts_in")) }} {% else %} Ends in {{ timedelta(minutes=state_attr("sensor.load_shedding_adderley", "ends_in")) }} {% endif %} {% endif %} entity: sensor.load_shedding_adderley ```

Hope you find this useful.

Currently I also get a notifications 60 minutes before load shedding and use node-red to shutdown my machines 15 minutes before load shedding starts (the person pressing the button gets over eager at times)

Code Automation ```yml alias: Load Shedding (60min Warning) description: '' trigger: - platform: template value_template: >- {{ timedelta(minutes=(state_attr("sensor.load_shedding_adderley", "starts_in"))) == timedelta(minutes=59) }} condition: - condition: and conditions: - condition: time after: input_datetime.alarm before: '20:00:00' - condition: not conditions: - condition: state entity_id: sensor.load_shedding_adderley state: Unknown - condition: state entity_id: sensor.load_shedding_stage state: No Load Shedding action: - service: media_player.volume_set data: volume_level: 1 target: entity_id: media_player.googlehome5943 - service: tts.google_translate_say entity_id: media_player.googlehome5943 data_template: message: > '{{ ["Load Shedding starts in 60 minutes", "Load Shedding starts in one hour", "Load Shedding starts in 3600 seconds, that is one hour for those that can not math", "Prince of darkness in 60 minutes"] | random }}' - service: automation.turn_off data: {} target: entity_id: automation.load_shedding_45min_warning - service: notify.notify data: title: Loadshedding message: Starts in 60 minutes mode: single ```

Thanks for a great integration.

P.S. I am no developer/programmer and most of my stuff is working by accident.

wernerhp commented 2 years ago

Thanks for the contribution @Drewskieza 0.5.0 was a pre-release/proof of concept that I slapped together in a hurry, and so I would not necessarily recommend it as a daily driver. I made quite a few changes to it over the past two weeks. Initially replaced schedule with forecast, but forecast is not that reliable, because it's scraped from CityPower's website and as load shessing stopped now there's no data available. I added schedules back and made some improvements to include forecast if it's available, but it's likely going to break a few things from previous versions because I renamed a some of fields to be more consistent. If you want you can try out the latest by installing master from HACS Just be sure to wait for it to fully load before hitting the Download button in HACS. I'm still testing and checking for bugs, before I'll release. Haven't updated the README yet.

Drewskieza commented 2 years ago

When you say master you mean V0.4.1?

wernerhp commented 2 years ago

No, I mean the master branch with the latest codeI'm working on. It's at the bottom of the list on HACS > Integrations > Load Shedding then hit the menu button Redownload Screenshot_20220727-082051 Screenshot_20220727-082112

paulbalinnel commented 2 years ago

Hi Werner, it seems I am unable to access the library as my sensor for eerste rivier has stopped working over weekend> I have uninstalled and re-installed... keep getting error... any advice pls

Screenshot 2022-09-05 at 12 45 33
wernerhp commented 2 years ago

@paulbalinnel Please include error logs. That error usually means Eskom was doing maintenance or something and was unavailable. Logs will provide a clearer picture.

paulbalinnel commented 2 years ago

@wernerhp all good, probably as u said, eskom doing something, its all working again. thanks for the reply!!!

cliffordwhansen commented 1 year ago

I set up the following automation as there have been times when I have forgotten to load electricity (pre-paid user) this will send me a notification to tell me to check the meter, as the schedule states we are not load-shedding

The eskom_power sensor is based on an inverter having input power.

Code ```yaml alias: "Eskom: Check pre-paid" description: "" trigger: - platform: state entity_id: - binary_sensor.eskom_power to: "off" - platform: state entity_id: - sensor.load_shedding_area_westerncape_14_parklands to: "off" condition: - condition: state entity_id: sensor.load_shedding_area_westerncape_14_parklands state: "off" - condition: state entity_id: binary_sensor.eskom_power state: "off" action: - service: script.notify_phone_and_tv data: message: ⚡ Check pre-paid electricity mode: single ```

script.notify_phone_and_tv: Just a script I use everywhere for notifications, it does some checks like "is the tv on" "am I home"

cliffordwhansen commented 1 year ago

Another automation I have to notify me of power outages (yes I know EskomSePush also does this :stuck_out_tongue:)

Code ```yaml alias: "Eskom: Power off in 30 min" description: "" trigger: - platform: numeric_state entity_id: sensor.load_shedding_area_westerncape_14_parklands attribute: starts_in below: "30" condition: - condition: not conditions: - condition: or conditions: - condition: state entity_id: sensor.load_shedding_area_westerncape_14_parklands state: unavailable - condition: state entity_id: sensor.load_shedding_area_westerncape_14_parklands state: unknown action: - service: script.notify_phone_and_tv data: message: >- ⚡ Power going off at {{ (state_attr("sensor.load_shedding_area_westerncape_14_parklands", "next_start_time") | as_timestamp | timestamp_custom('%H:%M')) }} (in {{ state_attr("sensor.load_shedding_area_westerncape_14_parklands", "starts_in") }} mins) will be back on around {{ (state_attr("sensor.load_shedding_area_westerncape_14_parklands", "next_end_time") | as_timestamp | timestamp_custom('%H:%M')) }} mode: single ```
cliffordwhansen commented 1 year ago

And of cause we have one when the stage changes

Code ```yaml alias: "Eskom: Stage Change" description: "" trigger: - platform: state entity_id: - sensor.load_shedding_stage_eskom not_from: - Unknown - Unavailable not_to: - Unknown - Unavailable condition: [] action: - service: script.notify_phone_and_tv data: message: "⚡ Eskom stage changed: {{ states('sensor.load_shedding_stage_eskom') }}" mode: single ```
tunavis commented 1 year ago

Was anyone able to create a automation when loadshedding is 5min before start time turn of certain devices?

wernerhp commented 1 year ago

@tunavis Have a look at Example Automation 2 You can tweak it to your needs.