This Python script fetches real-time solar power data from the SolarEdge API and utilizes the information to manage the D-LINK W115 smart plug. The goal is to optimise leisure/device battery charging when solar output is high.
Without the addition of consumption monitoring to measure available power, this approach does have its downsides, but it's a start for those without access to realtime consumption data.
Note: "For a more manual approach, I've developed a Solar Production Forecast Advisor. This tool incorporates geography and panel orientation forecasts to notify residents about the optimal times of the day for using or charging electrical devices. See solarProductionAdvisor/README.md
-
Solar Power Monitoring:
- Fetches current solar power data from the SolarEdge API.
- Logs data and status to a specified log file.
-
Smart Plug Automation:
- Controls a smart plug based on the retrieved solar power information.
- Adjusts the plug's state (on/off) according to predefined thresholds.
- Configure solar monitoring parameters in the
config.py
file, including API key and endpoint. - Customize smart plug settings, such as IP address, PIN code, and model, within the script.
- Python 3.x
- Requests library for HTTP requests (
pip install requests
) - SolarEdge Solar System and access to monitoring API
- D-LINK DSP W115 Smart Plug (other models may work with minor modifications)
- Local connectivity to the smart plug (e.g., same WiFi network)
-
Obtain API Key:
- See here for info on how to get a SolarEdge API key. Configure it in
config.py
to give the script access to your current solar output.
- See here for info on how to get a SolarEdge API key. Configure it in
-
Configure Smart Plug:
- See the guide here for instructions on how to configure the smart plug. Use PIN only method.
- Adjust smart plug parameters in 'config.py' , including IP, PIN, and model.
-
Schedule the Script:
- Schedule the execution of
solar_power_query.py
to fetch solar power data and control the smart plug. The server hosting the script must have local connectivity to the D-LINK smart plug.
For example, use cron to run the script every 5 minutes:
*/30 8-19 * * * /usr/bin/python3 /home/pi/solar-smart-plug/solarsmartplug.py
- Schedule the execution of
- This integration is intended to be run on the same network as the D-Link smart plug. Certain SSL checks in the dspW245 module have been bypassed to allow direct access to the D-LINK smart plug via a local connection, preventing the need for a home automation cloud service. Attempting to connect over the internet is not recommended for security reasons. See lines 199-206 in dspW245.py for code changes.
- Review and adjust the power threshold in config.py to control when the smart plug is turned on/off.
This project is built upon a modified version of the dspW245 project by Jonas Johansson. The original project provides a Python interface for interacting with DSP-W245 smart plugs. Many thanks to Jonas Johansson for most of the hard work.