I’ve been on a journey to make my home more energy-independent, and I’m thrilled to share my experience with the community! ![]()
My Setup:
I have a grid-tied solar system paired with a 17kWh battery, all managed through Home Assistant. The inverter automatically switches to battery power during outages, but with finite battery life, I needed a reliable way to detect grid loss and switch to emergency mode effectively.
The Challenge:
Detecting when the grid power is lost can be tricky because solar panels often stop feeding power back to the grid during the day. I wanted a system that could distinguish between normal solar fluctuations and actual grid outages.
My Solution:
I decided to use a Shelly EM connected to my inverter’s grid input. This device monitors power consumption and sends data to Home Assistant. Here’s how I set it up:
-
Template Sensor:
I created a template sensor to calculate the absolute power from both legs of the Shelly EM measurement. This helps in accurately determining the grid status.{{ (states(‘sensor.gmp_power_channel_1_power’) | float(0) | abs) + (states(‘sensor.gmp_power_channel_2_power_power’) | float(0) | abs)}}
-
Statistics Platform:
To smooth out the readings, I used the statistics platform to calculate the average power consumption over 10 minutes.sensor:
- platform: statistics
name: “Recent Average GMP Consumption”
entity_id: sensor.gmp_abs_power
state_characteristic: mean
max_age:
minutes: 10
sampling_size: 50
precision: 2
- platform: statistics
-
Automation Triggers:
I set up triggers to detect when the average power drops below 1 watt for 10 minutes, indicating a grid loss. Conversely, if it rises above 10 watts, the system knows power is restored.alias: “House - Emergency Power Detector”
description: “”
mode: single
triggers:- value_template: “{{ states(‘sensor.recent_average_gmp_consumption’) | float(0) < 1 }}”
id: Lost Power
for:
hours: 0
minutes: 10
seconds: 0
trigger: template - value_template: “{{ states(‘sensor.recent_average_gmp_consumption’) | float(0) > 10 }}”
id: Have Power
for:
hours: 0
minutes: 10
seconds: 0
trigger: template
- value_template: “{{ states(‘sensor.recent_average_gmp_consumption’) | float(0) < 1 }}”
-
Scripts for Shutdown/Restore:
Once the automation detects a grid loss, it triggers scripts to shut down or restore various electric devices like hot water heaters and floor heaters, ensuring efficient battery use.
Outcome:
This setup has been a game-changer for me. It not only detects grid outages accurately but also manages my battery usage effectively. I’ve had several power outages since implementing this, and each time, the system switched seamlessly to emergency mode without any issues.
Tips for Others:
- Testing: Thoroughly test your automation in different scenarios to ensure reliability.
- Sensors: Invest in good quality sensors like the Shelly EM for accurate readings.
- Documentation: Keep your Home Assistant configurations well-documented for easy troubleshooting.
I’m excited to share this with the community and hope it inspires others to explore similar setups! ![]()
If anyone has questions or suggestions, feel free to reach out. Happy automating! ![]()