Free Heating from your Solar Panels? Yes Please!
This neat little hack takes (near) real-time statistics data from your Solax Inverter over the network at home, performs a little simple subtraction and works out if you have enough exported energy to run a Fan Heater.
You can probably use a different inverter, provided it has a web API that gives you enough data to do the simple calculation. You will also be able to us a different smart-plug to the HS100 provided there is a script/binary to use for local control of it on your home network.
Stuff you need:
[WARNING] This script will randomly start and stop a high current electrical heating appliance in your home, please use common sense, and do not leave the heater set to run unattended when you cannot verify that it is operating safely. I accept no responsibility for any damage caused by the use of the following scripts!
- A Solax Inverter which supports network real-time data feed
If you have a Solax inverter, plug its network connection into your home network, it should pick up an IP Address from your router. Do a curl to http://inverter_ip/api/realTimeData.htm and see if you get a load of data back. If you do and it looks like the below example, you may be able to use this script 'as is'
{"method":"uploadsn","version":"Solax_SI_CH_2nd_20170906_DE01","type":"AL_SE","SN":"XXXXXXXX","Data":[5.8,4.1,282.4,289.7,9.6,247.8,2348,30,9.0,4757.3,1340,1637,1187,50.69,9.67,490,13,91,0.0,699.4,,,,,,,,,,,,,,,,,,,,,,0.00,0.00,,,,,,,,50.06,,,0.0,0.0,0,0.00,0,0,0,0.00,0,9,0,0,0.00,0,9],"Status":"2"}
- A Raspberry Pi - Any model will do , connected to the network 8-)
- TPLink HS100/HS110 Smart Socket
Other brands will also work, so long as you have a script or binary to turn it on and off from you Pi. Please verify that the smart socket can handle the load from any appliance you connect to it before attempting this!
Scripts
I used the following scripts to set this up. If you have the same inverter and smart-socket, they should work straight off the bat. For other setups, you will need to substitute and edit accordingly.
HS100/110 control
Download George Georgovassilis' excellent little script, from https://github.com/ggeorgovassilis/linuxscripts and check its working for your socket
./hs100.sh -i mysocket
Find out the IP Address of your smart socket from your router DHCP leases, and place a hosts file entry on your Pi with a friendly name. Or you can just use the IP above if you want instead.
autofan.py
This script will check the inverter data feed once, and decide if there is less than 200 watts being drawn from the grid, (e.g you are exporting more than you're using, with a buffer of 200w draw being allowed). If this is the case, then it turns the smart-socket on.
#!/usr/bin/python
import hashlib
import requests
import os
import time
from xml.etree.ElementTree import XML
url = "http://192.168.1.121/api/realTimeData.htm"
r = requests.get(url)
p = r.text.split(",")
print("Generation: {}".format(int(p[15])+int(p[16])))
print("Grid : {}".format(p[14]))
l = (int(p[15])+int(p[16]))-int(p[14])
print("House Load: {}".format(l))
if(int(p[14])>-200):
print "on"
os.system('./hs100.sh -i heater on')
else:
print "off"
os.system('./hs100.sh -i heater off')
Launching the script every 30 seconds
cron can't run things as quickly as every 30 seconds, hence you can do this using a service in linux. The standard pi distros support this, you need to create 2 files in /etc/systemd/system:
/etc/systemd/system/autofan.timer
[Unit]
Description=run the autofan every 30 sec
[Timer]
OnBootSec=30
OnUnitActiveSec=30
AccuracySec=1ms
[Install]
WantedBy=timers.target
/etc/systemd/system/autofan.service
[Unit]
Description=AutoFan
[Service]
ExecStart=/usr/bin/python /solaxmon/auto-fan.py
When you're done, you'll need to register the service, and start it:
systemctl enable autofan.timer
systemctl start autofan
No comments:
Post a Comment