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

Automation Ideas #5

Open
wernerhp opened this issue May 13, 2022 · 20 comments
Open

Automation Ideas #5

wernerhp opened this issue May 13, 2022 · 20 comments

Comments

@wernerhp
Copy link
Owner

wernerhp commented May 13, 2022

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>

```yml
EXAMPLE YAML GOES HERE
```
</details>
@Capone1983
Copy link

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
Copy link

cliffordwhansen commented Jul 2, 2022

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
Copy link
Owner Author

wernerhp commented Jul 2, 2022

Updated for v0.2.0-alpha

Stage and Area panel

image

Code
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
  - type: markdown
    content: >
      {% set schedules = state_attr("sensor.load_shedding_milnerton",
      "schedule") %} <table width="100%">
        <tbody>
        <tr>
          <td width="10%"><ha-icon icon="mdi:calendar"></ha-icon></td>
          <td align="left">Schedule</td>
          <td align="right"></td>
        </tr>
        {% for s in schedules[:3] %}
        <tr>
          <td></td>
          <td width="50%" align="left">{{ as_timestamp(s.start_time | as_datetime) | timestamp_custom("%-d %B %Y", True) }}</td>
          <td width="100%" align="right">{{ as_timestamp(s.start_time | as_datetime) | timestamp_custom("%H:%M", True) }} - {{ as_timestamp(s.end_time | as_datetime) | timestamp_custom("%H:%M", True) }}</td>
        </tr>
        {% endfor %}
        </tbody>
      </table>

@paulbalinnel
Copy link

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

@n00bster-za
Copy link

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
Copy link
Owner Author

wernerhp commented Jul 5, 2022

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
Copy link

not sure how to get that.

@wernerhp
Copy link
Owner Author

wernerhp commented Jul 7, 2022

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]
```
</details>

@Drewskieza
Copy link

Drewskieza commented Jul 26, 2022

Load Shedding v0.5.0

  • No longer shows starting or ending in the second row, unless we are actually load shedding.
  • Also does not show it active if not actually load shedding.
  • I still need to work in schedule changes affect on this (not sure how to test this as we no longer have a schedule).
  • Still trying to figure out how to hide second line if not load shedding (again this would also need to tie back to schedule)

image

Code Card
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)

  • Set volume on speaker to 100%
  • Play random message (3 to choose from)
  • Turn off the 45 minute automation (this was in case we missed the message at 60 minutes due to schedule changes/reboots/etc.)
  • Notification to all
Code Automation
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
Copy link
Owner Author

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
Copy link

When you say master you mean V0.4.1?

@wernerhp
Copy link
Owner Author

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
Copy link

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
Copy link
Owner Author

wernerhp commented Sep 5, 2022

@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
Copy link

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

Repository owner deleted a comment from Mrmuttley Sep 17, 2022
@wernerhp wernerhp mentioned this issue Nov 9, 2022
@cliffordwhansen
Copy link

cliffordwhansen commented Jul 12, 2023

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
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
Copy link

cliffordwhansen commented Jul 12, 2023

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

Code
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
Copy link

cliffordwhansen commented Jul 12, 2023

And of cause we have one when the stage changes

Code
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
Copy link

tunavis commented Jul 23, 2023

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

@wernerhp
Copy link
Owner Author

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

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

7 participants