1
0
Fork 0
Hoymiles-Solar-Database-FHEM/README.md

63 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2023-05-29 08:56:11 +02:00
# Hoymiles-Solar-Database-FHEM
2023-05-29 09:32:33 +02:00
Queries the solar data from Hoymiles API and stores it in a database and shows it in FHEM.
2023-05-29 09:08:31 +02:00
## Prerequisites
2023-05-29 09:12:17 +02:00
Make sure you have installed apache2 with php8.1 (and mysql extension). You need python3 too with mysql connector:
<code>python3 -m pip install mysql-connector-python</code>
2023-05-29 09:08:31 +02:00
## Create folders and rights
2023-05-29 09:13:20 +02:00
<code>mkdir /opt/hoymiles && mkdir /opt/hoymiles/www</code>
<code>chown -R fhem:dialout /opt/hoymiles/www</code>
2023-05-29 09:08:31 +02:00
## 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
2023-05-29 09:13:20 +02:00
Use the script solardata.sql to create your database for storing solar data. Make sure you configure the rights accordingly.
2023-05-29 09:08:31 +02:00
## 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
2023-05-29 09:31:05 +02:00
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:
2023-05-29 09:32:33 +02:00
<code>sudo systemctl daemon-reload</code>
<code>sudo systemctl stop solar</code>
<code>sudo systemctl enable solar</code>
<code>sudo systemctl start solar</code>
2023-05-29 09:31:05 +02:00
To check, if the service is running, use the following command:
2023-05-29 09:32:33 +02:00
<code>sudo systemctl status solar</code>
2023-05-29 09:08:31 +02:00
2023-06-11 12:17:58 +02:00
## Apache example configuration for API
2023-05-29 09:08:31 +02:00
This example shows how to set up the JSON API in apache2.
2023-05-29 09:17:13 +02:00
```
<VirtualHost *:80>
2023-05-29 09:13:20 +02:00
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
2023-05-29 09:17:13 +02:00
</VirtualHost>
```
2023-05-29 09:08:31 +02:00
## FHEM example
2023-05-29 09:32:33 +02:00
This is an example, how you can show the data in your FHEM instance.
2023-05-29 09:17:13 +02:00
```
define Solar HTTPMOD 0
2023-05-29 09:08:31 +02:00
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
2023-06-11 12:06:16 +02:00
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)}
2023-05-29 09:17:13 +02:00
```