This Python script monitors solar power data from a Fronius Inverter and sends Telegram alerts when the battery is full or no longer full. It can also control smart plugs based on battery status.
- Overview
- How it Works
- System Requirements
- Installation & Setup
- Data Monitoring & API
- Additional Resources
- Troubleshooting
- FAQ
Fronius Solar Monitor helps you optimize your solar energy consumption by alerting you when your battery reaches full capacity or drops below it. Perfect for regions where excess energy fed to the grid isn't compensated beyond certain limits. You can also make changes and use it as part of your larger home automation system.
The system can automatically control Tuya-compatible smart plugs based on battery status, allowing you to automatically power devices (like water heaters, AC units, or pool pumps) when excess solar energy is available.
- Fronius Inverter provides real-time data via the Solar API (e.g., battery status, power consumption, etc.).
- Fronius Solar Monitor Script retrieves this data using the API and evaluates the battery status.
- Based on the readings, the script sends Telegram notifications (battery full or not) to the user.
- Alerts are customizable based on frequency and consecutive checks, reducing false positives.
- Smart Plug Control (optional) automatically manages connected devices based on battery status and/or PV production.
- Supported Inverters: Fronius GEN24 series
- Operating System: Any Python-compatible OS (Linux recommended, Windows also ok)
- Python: 3.6 or higher
- Network: Local network access to Fronius inverter
- Smart Plugs (optional): Any Tuya-compatible smart plug
- Python 3.x
- A Fronius inverter with Solar API
- Telegram account
- Tuya-compatible smart plug (optional)
Install the required Python libraries using pip:
pip install requests # Required for making API requests to the Fronius inverter
pip install tinytuya # Required for smart plug controlNote: The
tinytuyalibrary is only required if you plan to use the smart plug feature.
The Solar API must be enabled on Fronius GEN24 devices to avoid 404 errors.
-
Access the Fronius Web Interface
- Enter your Fronius inverter's IP address in a browser.
- Find the IP through:
- Your router's device list
- The IP configured during installation
- Network scanning tools
-
Enable the API
- Navigate to Communication β Solar API
- Toggle the Solar API setting to enabled.
- Save your changes.
A more detailed tutorial is available here.
-
Create Your Bot
- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions. - Save the Bot Token provided.
-
Configure Chat ID
- For a group chat: Add your bot to a group.
- For a private chat: Start a conversation with your bot.
- Send any message to the bot.
- Get your Chat ID by opening:
https://api.telegram.org/bot<TOKEN>/getUpdates - Note: Group chat IDs are negative numbers; private chat IDs are positive.
(more on the smart plug settings further down at Setting Up TinyTuya)
Rename _config.json to config.json and configure it with your settings:
{
"telegram_token": "6467835642:AAAAAl99Ue14-e2cPqF79KSdOol5-aTr123",
"chat_id": "-1048737232455",
"solar_api_ip": "192.168.1.131",
"check_interval_min": 1,
"consecutive_full_checks": 1,
"consecutive_not_full_checks": 4,
"language": "en",
"smart_plug_mode": 1,
"pv_threshold": 500,
"smart_plug": {
"enabled": true,
"dev_id": "bfa03f282eff246980zuioe",
"address": "192.168.1.230",
"local_key": "?quej6(u$e<1<#<<",
"version": 3.5
}
}| Parameter | Description | Recommended Value |
|---|---|---|
telegram_token |
Your Telegram bot token | - |
chat_id |
Target chat ID for notifications | Negative for groups, positive for private chats |
solar_api_ip |
IP address of Fronius inverter | Local network IP of inverter |
check_interval_min |
Time between checks (minutes) | 1-5 |
consecutive_full_checks |
Readings needed before "battery full" alert | 1-3 |
consecutive_not_full_checks |
Readings needed before "battery not full" alert | 2-5 |
language |
Notification language | "en" or "de" |
smart_plug_mode |
Control mode for smart plug | 1 or 2 (see below) |
pv_threshold |
PV production threshold in watts | 500-1000 (depends on your devices) |
smart_plug |
Configuration for smart plug control | See below |
Note: Higher
consecutive_checksvalues reduce false alerts but increase notification delay.
Smart Plug Tip: Any Tuya-compatible smart plug will work with this system. These are widely available on AliExpress for around $5, making it an affordable addition to your solar monitoring setup.
To find your device ID and local key for the smart plug configuration, you can use the TinyTuya library. Visit the official TinyTuya repository for detailed setup instructions:
https://github.com/jasonacox/tinytuya
The repository provides tools to scan your network for Tuya devices, obtain device IDs, and retrieve local keys needed for the configuration.
The smart plug feature allows you to automatically control a Tuya-compatible smart plug based on selected control mode.
-
Mode 1: Battery Status Only (Default)
- The smart plug will turn ON when the battery is full
- The smart plug will turn OFF when the battery is no longer full
- This is the original behavior
-
Mode 2: Battery Status + PV Production
- The smart plug will turn ON only when:
- The battery is full AND
- Current PV production is above the threshold set in
pv_threshold
- The smart plug will turn OFF when either condition is not met
- This mode helps ensure devices only run when there's sufficient ongoing solar production
- The smart plug will turn ON only when:
| Parameter | Description | Example |
|---|---|---|
enabled |
Enable/disable smart plug functionality | true or false |
dev_id |
Device ID of your Tuya smart plug | bfa5c4d187d5ab1234abcd |
address |
IP address of your smart plug | 192.168.1.230 |
local_key |
Local key for device authentication | a1b2c3d4e5f6g7h8 |
version |
Protocol version | 3.5 |
To test if your smart plug is configured correctly, you can use the included test script that toggles the smart plug ON and OFF every 5 seconds:
python test_smart_plug.pyThis is useful for verifying your smart plug connection and configuration before running the main monitoring script.
To run the script manually:
python solar_monitor.pyFor a headless setup on Raspberry Pi running DietPi or (maybe) also other Linux distributions:
-
Install DietPi: Download from dietpi.com.
-
Access via SSH in Terminal:
ssh root@192.168.1.132 # Replace with your Pi's IP -
Install Git and Python via
dietpi-software(or your package manager if using a different Linux distribution). -
Clone the repository and navigate to the project directory:
git clone https://github.com/Persie0/Fronius-Solar-Monitor.git cd Fronius-Solar-Monitor -
Verify the project directory: To ensure you're in the correct directory, run the following command:
pwdIf the output is not
/root/Fronius-Solar-Monitor, you will need to update thePROJECT_DIRvariable in the setup configuration. Edit the script to reflect the correct path.Example:
nano /otherpath/Fronius-Solar-Monitor/setup_autostart.sh
Update the line:
PROJECT_DIR="/otherpath/Fronius-Solar-Monitor"
Then save with Ctrl+O, Enter and Ctrl+X.
-
Setup Auto-Start: Simply run the setup script included in the repository:
sudo bash setup_autostart.sh
-
Configure the bot: Edit the
config.jsonfile to include your bot's token, chat ID, and inverter's IP address.nano config.json
then copy and paste your configured config.json into it. Then Ctrl+O, Enter and Ctrl+X.
-
Restart to test:
sudo systemctl restart solar_monitor
now you should already get a TG notification.
Note: If you did not get an notification, to check for errors, run:
tail -f /root/Fronius-Solar-Monitor/solar_monitor.log
And if you really want to test it run:
sudo reboot
-
Update to latest: To update to the latest version run in the Fronius-Solar-Monitor folder:
git pull origin main
After updating, restart the service:
sudo systemctl restart solar_monitor
To verify connectivity with your Fronius inverter, you can test the API endpoint directly in your web browser: (Replace 192.168.1.131 with your inverter's IP)
http://192.168.1.131/solar_api/v1/GetPowerFlowRealtimeData.fcgi
{
"Body": {
"Data": {
"Inverters": {
"1": {
"Battery_Mode": "battery full",
"P": 4201.64,
"SOC": 100
}
},
"Site": {
"P_Grid": 740.7,
"P_Load": -4942.34,
"P_PV": 4298.14,
"rel_Autonomy": 85.01,
"rel_SelfConsumption": 100
}
}
},
"Head": {
"Status": { "Code": 0 },
"Timestamp": "2025-02-18T14:50:13+00:00"
}
}| Field | Description |
|---|---|
Battery_Mode |
Battery state (e.g., "battery full") |
SOC |
Battery state of charge (percentage) |
P_Grid |
Power from/to the grid (positive = importing, negative = exporting) |
P_Load |
Power consumption (negative values mean energy usage) |
P_PV |
Solar power generation |
rel_Autonomy |
Percentage of energy used from your own sources |
rel_SelfConsumption |
Percentage of solar energy used locally |
For detailed API documentation:
| Issue | Solution |
|---|---|
| 404 Error when accessing the Solar API | Ensure the Solar API is enabled on your Fronius inverter and you're using the correct IP. |
| No Telegram message received | Double-check the Bot Token and Chat ID in config.json. Ensure the bot is correctly added to the group or conversation. |
| Data not updating | Make sure the inverter's IP is correct and accessible from your Python script. Test with ping or use curl to manually check if the API is responding. |
| Script Crashes | Run the script in debug mode by adding -v for more verbose logging. Check the logs in /var/log/solar_monitor.log for detailed errors. |
A: Currently, the Solar Monitor is designed for Fronius GEN24 inverters and Tuya-compatible smart plugs. However, you can adapt the code for other devices that provide API access:
For other inverters:
- Check if your inverter model has an available API
- Find the API documentation and endpoint structure
- Use the API URL and response format along with the solar_monitor.py script to modify the code (you can use AI tools like ChatGPT to help with the conversion)
For other smart plugs:
- Verify if your smart plug has an API or protocol that can be accessed via Python
- Find the required libraries and documentation for your smart plug
- Modify the smart plug integration code accordingly (AI tools can help with this adaptation)
Happy Solar Monitoring! πβ‘



