Hi all HA automation wizards!
I have 30 solar panels, and want to detect when they go offline, or come back online and send me an email. I had ChatGPT assist creating an automation that seems to work in testing (manually changing the state of the entity changing from ‘working’ to anything else) The automation is great because I don’t need to list all of my panels, it dynamically build a list and detects from that, will come in handy should I ever get new panels, more panels, swap panels.
Now we tried to create one that detects returning back to ‘working’ it doesn’t seem to work, no matter what we’ve tried, I mostly ended up going in circles with ChatGPT for an hour, Google Gemini just flat out gave up after 3 or so attempts.
So here is the code that works for testing if the entity state changes from ‘working’ to anything else:
Scroll down a bit for what should work, well ChatGPT seems to think so.
And yes there’s some code in there that ChatGPT has been trying to fix some funky formatting in the email.
alias: Solar Panel Offline Alert
description: >-
Notify when one or more solar panels are NOT in "working" state for more than
5 seconds.
triggers:
- value_template: |-
{{ states.binary_sensor
| selectattr('entity_id', 'search', '^binary_sensor\.inverter_')
| selectattr('state', 'ne', 'working')
| list | count > 0 }}
for: "00:00:05"
trigger: template
actions:
- variables:
offline_panels: |-
{% set panels = states.binary_sensor
| selectattr('entity_id', 'search', '^binary_sensor\.inverter_')
| selectattr('state', 'ne', 'working')
| list %}
{% set panel_names = panels
| map(attribute='attributes.friendly_name')
| map('regex_replace', find=' ', replace='') %}
{% for panel in panel_names %}
- {{ panel }} ({{ panels[loop.index0].state }})
{% endfor %}
- data:
target: [email protected]
title: ⚠️ Solar Panel Alert
message: >-
The following solar panel(s) are NOT in "working" state for over 5
seconds:
{{ offline_panels | join('\n') }}
action: notify.me-at_gmail_com
mode: parallel
max: 5
Okay, now for the code that doesn’t work testing when that sensor changes back to ‘working’
alias: Solar Panel Online Alert
description: Notify when one or more solar panels come back online.
triggers:
- value_template: |-
{{ states.binary_sensor
| selectattr('entity_id', 'search', '^binary_sensor\.inverter_')
| selectattr('state', 'eq', 'working')
| list | count > 0 }}
for: "00:00:05"
trigger: template
actions:
- variables:
online_panels: |-
{% set panels = states.binary_sensor
| selectattr('entity_id', 'search', '^binary_sensor\.inverter_')
| selectattr('state', 'eq', 'working')
| list %}
{% set panel_names = panels
| map(attribute='attributes.friendly_name')
| map('regex_replace', find='[^a-zA-Z0-9]', replace='_') %}
{% for panel in panel_names %}
- {{ panel }} ({{ panels[loop.index0].state }})
{% endfor %}
- data:
level: debug
message: ✅ Online Trigger Fired!
action: system_log.write
- data:
target: [email protected]
title: ✅ Solar Panel Online Alert
message: >-
The following solar panel(s) are back online: {{ online_panels |
join('\n') }}
action: notify.lol_gmail_com
mode: parallel
max: 5
I can manually run the “online” automation, and it does fire off an email, with all 30 panels listed. The formatting is funky, but first I want to fix functionality then the formatting of the email.
Thanks in advance for any assistance.