Queries the solar data from Hoymiles API and stores it in a database and shows it in FHEM.
Go to file
2023-06-24 13:44:41 +00:00
index.php „index.php“ ändern 2023-06-24 13:44:41 +00:00
LICENSE Initial commit 2023-05-29 06:56:11 +00:00
README.md „README.md“ ändern 2023-06-11 10:17:58 +00:00
solar.py „solar.py“ hinzufügen 2023-05-29 07:10:28 +00:00
solar.service „solar.service“ hinzufügen 2023-05-29 07:25:37 +00:00
solardata.sql „solardata.sql“ hinzufügen 2023-05-29 07:11:50 +00:00

Hoymiles-Solar-Database-FHEM

Queries the solar data from Hoymiles API and stores it in a database and shows it in FHEM.

Prerequisites

Make sure you have installed apache2 with php8.1 (and mysql extension). You need python3 too with mysql connector: python3 -m pip install mysql-connector-python

Create folders and rights

mkdir /opt/hoymiles && mkdir /opt/hoymiles/www
chown -R fhem:dialout /opt/hoymiles/www

Upload files

Upload index.php into /opt/hoymiles/www folder. It acts as an JSON-API for serving data to FHEM.
Upload solar.py into /opt/hoymiles folder. It will gather data from Hoymiles API and stores it in the database.

Create database

Use the script solardata.sql to create your database for storing solar data. Make sure you configure the rights accordingly.

Change values

In file index.php insert your database connection details. Do this also in solar.py, where you add also your Hoymiles credentials for login.

Run python script as a service

Copy the file solar.service into the correct path (depends on your os). For example in Ubuntu 20.04 it is /etc/systemd/system/.
Run the following commands to start the service and enable it to restart automatically on server reboot:
sudo systemctl daemon-reload
sudo systemctl stop solar
sudo systemctl enable solar
sudo systemctl start solar
To check, if the service is running, use the following command:
sudo systemctl status solar

Apache example configuration for API

This example shows how to set up the JSON API in apache2.

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName automation.${MYDOMAIN}
    Alias /solarapi "/opt/hoymiles/www"
    <Directory "/opt/hoymiles/www/">
        AllowOverride none
        Require all granted
    </Directory>
    CustomLog /var/log/apache2/${LOG} combined
</VirtualHost>

FHEM example

This is an example, how you can show the data in your FHEM instance.

define Solar HTTPMOD 0
setuuid Solar 64744ab5-f33f-1b7d-ecc0-8b30ed24e4a4b55a
attr Solar event-on-change-reading .*
attr Solar extractAllJSON 1
attr Solar get01Name ReadSolarStats
attr Solar get01Poll 1
attr Solar get01URL http://your-automation-host/solarapi/index.php
attr Solar icon sani_solar
attr Solar room Solar
attr Solar stateFormat {sprintf("Current: %.1f W", ReadingsVal($name,"current",0)).\
sprintf("<br/>Today: %.1f kWh", ReadingsVal($name,"today",0)/1000).\
sprintf("<br/>Week: %.1f kWh", ReadingsVal($name,"week",0)/1000)}