Skip to content

Commit

Permalink
esp
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed Oct 29, 2023
1 parent ceb5f5c commit 55a849d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions www/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default defineConfig({
{ text: "Settings", link: "/examples/lovelace-settings" },
{ text: "Automations", link: "/examples/a-mode" },
{ text: "Templates", link: "/examples/templates" },
{ text: "ESP", link: "/examples/esp" },
],
},
],
Expand Down
72 changes: 72 additions & 0 deletions www/docs/examples/esp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ESP integration

The ESP integration uses a combination of mysensors + Frontend

Init your ESP sensor with the following **mysensors.py** entry

```python
try:
from ha_addon_sunsynk_multi.esp import ESP
ESP(
api_key="xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx",
area_id="jhbcitypower2-2-victorypark",
ha_prefix="eskom_vp",
)
except ImportError:
pass
```

The following should be saved in you HA config folder `/config/custom_templates/loadshed.jinja`

```jinja
{% macro loadshed_md(espnext) %}
{%- set active = (as_timestamp(states(espnext))<=as_timestamp(now())) | bool %}
{%- set stage = state_attr(espnext, "note") %}
{%- set t0 = state_attr(espnext, "start") | as_timestamp | int %}
{%- set t1 = state_attr(espnext, "end") | as_timestamp | int %}
{%- set t0_min = (t0|int - as_timestamp(now()))|int // 60 %}
{%- set t1_min = (t1|int - as_timestamp(now()))|int // 60 %}
{%- if stage %}
{%- if not bool(active) %}
{%- set mins = t0_min % 60 %}
{%- set hrs = t0_min // 60 %}
{%- set alert = "Load Shedding starts in {h}:{m:02d} ({next})".format(m=mins, h=hrs, next=t0 |
timestamp_custom("%H:%M", True)) %}
{%- if hrs>12 %}
<ha-alert alert-type="success">{{ alert }}</ha-alert>
{%- elif hrs > 1 %}
<ha-alert alert-type="warning">{{ alert }}</ha-alert>
{%- else %}
<ha-alert alert-type="error">{{ alert }}</ha-alert>
{%- endif %}
{%- else %}
{%- set mins = t1_min % 60 %}
{%- set hrs = t1_min // 60 %}
{%- set alert = "Load Shedding ends in {h}:{m:02d} ({next})".format(m=mins, h=hrs, next=t1 |
timestamp_custom("%H:%M", True)) %}
<ha-alert alert-type="error">{{ alert }}</ha-alert>
{%- endif %}
{%- else %}
{%- set mins = t0_min % 60 %}
{%- set hrs = t0_min // 60 % 24 %}
{%- set days = t0_min // 1440 %}
{%- if (t0 == 0 or t1 == 0) %}
{%- set alert = "No Load Shedding" %}
{%- else %}
{%- set alert = "Stage {stage} starts in {d}d {h:02d}:{m:02d} ({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 %}
{% endmacro %}
```

You can now add this card to your frontend to create a status of loadshedding

```yaml
- type: markdown
content: '{% from "loadshed.jinja" import loadshed_md %} {{ loadshed_md("sensor.eskom_vp_next") }}'
```

0 comments on commit 55a849d

Please sign in to comment.