Okay, I have recently gotten solar panels as well and have been wrestling with the read-outs. It's a Solis inverter (Ginlong) with a LAN-interface that automatically uploads its statistics to the portal page at m.ginlong.com. I use the mobile app called "Solis Home", so if you use that as well, there's a good chance you can use my read-out method in a similar way.
I have been searching a lot on how to get the statistics in Domoticz. I've seen a lot of information and topics of people approaching this in various ways, some with success, others without any. This is how I approached it, hopefully some of you can use this. I am deliberately crossposting to make sure people that need this or are looking for it find it somewhere.
The approach:
- Make sure you can log in to m.ginglong.com and have the/a username and password available
- In Domoticz, create Dummy hardware with 2 sensors attached to it: 1 for the usage (in watts), which will show how many watts your PV is producing, 1 switch, which will show the status of your PV (on or off). For me, this looks like this:
- Next, put the Python-script below (called ginlong.py in my case) on your Domoticz-device and make sure Python is available on the system.
Make sure you update the parameters under #config and #domoticz settings:
Code: Select all
#!/usr/bin/python
import requests
import urllib, urllib2
import json
#config
username = '[email protected]' #your username to log on to m.ginlong.com
password = 'P@ssw0rd!' #your password to log on to m.ginlong.com
domain = 'm.ginlong.com' #webportal to read
plantId = '965529' #plant id (can be found on m.ginlong.com page information)
lan = '2' #language (2 = English)
#domoticz settings
domoticz_host = 'domoticzuser:[email protected]' #Username/password and IP of Domoticz
domoticz_port = '8080' #Port to connect to Domoticz
domoticz_url = 'json.htm' #URL to post stats to Domoticz, does not require changes normally
domoticz_device_idx = '486' #IDX of Watt meter in Domoticz
domoticz_device_onoff_idx = '485' #IDX of on/off switch (to see whether its on or off for PV)
# Create session for requests
session = requests.session()
#building url
url = 'http://'+domain+'/cpro/login/validateLogin.json'
params = {
"userName": username,
"password": password,
"lan": lan,
"domain": domain,
"userType": "C"
}
#login call
resultData = session.post(url, params=params)
resultJson = resultData.json()
if resultJson['result'].get('isAccept') == 1:
print("Login Succesful!")
else:
print("Login Failed!!")
Exit()
# Get plant details
url = 'http://m.ginlong.com/cpro/epc/plantview/view/doPlantList.json'
cookies = {'language': lan}
resultData = session.get(url, cookies=cookies)
resultJson = resultData.json()
# Uncomment lines below to write the exported json-file to the location noted
#out_file = open("/usr/local/bin/ZPExport.json", "w")
#json.dump(resultJson, out_file, indent = 6)
#out_file.close()
ActualPower = resultJson['result']['pagination']['data'][0].get('curPower')
ActualPowerNoSep = str(ActualPower).split(".")[0]
etoday = resultJson['result']['pagination']['data'][0].get('energyToday')
multiply='1000.0'
etotal1000 = float(etoday) * float(multiply)
etotalstr=str(etotal1000)
etotalstrNoSep = str(etotalstr).split(".")[0]
OnOrOff = resultJson['result']['pagination']['data'][0].get('status')
#logging values
print 'ActualPower: ' + str(ActualPowerNoSep)
print 'etoday: ' + str(etotalstrNoSep)
print 'Status: ' + str(OnOrOff)
#uploading values to domoticz
url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command¶m=udevice&idx=" + domoticz_device_idx+ "&nvalue=0&svalue=" + str(ActualPowerNoSep))
urlonoff = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command¶m=udevice&idx=" + domoticz_device_onoff_idx+ "&nvalue=" + str(OnOrOff))
urllib.urlopen(url)
urllib.urlopen(urlonoff)
- Make the script executable using command
while you are in the directory that contains the script. Due to a lack of knowledge I always do a
Code: Select all
[sudo chmod 777 ginlong.py/code] as well to make sure all users can use it. I'm sure it's not needed or a security-thing, but let's just say ignorance is bliss ;)
- Run the script once on the device and make you see output on the commandline.
I start the script using command:
[code]sudo /usr/bin/python /usr/local/bin/ginlong.py
Getting output? Great! Most likely you first values are also visible on your newly created Domoticz-devices as well, yay! Treat yourself to a beer at this point!
- Next, create anóther switch in Domoticz (by simply creating one using the Manual option, with random settings). Edit the switch and make it a "Push On" button. In the "On action" and "Off action", put the script location so it is started whenever the button is triggered. For me, this looks like this:
When using the configuration above (so: "script://ginlong.sh"), you are assuming that the script is located in the scripts folder under the Domoticz installation folder. If that's not the case, change the path (google or search the forum on how to incorporate the path)
- Press the update-knop (so the device you just created) and make sure the values are updated
- And here comes the clue: Running the script once every X-minutes. Note that I am no Linux-Raspbian expert and I couldn't get it to work using a crontab-job (just as well though, as I now have everything in Domoticz, which I prefer). Putting a timer on the switch did not allow running the task (pressing the button) often enough and I was wrestling errors in Domoticz whilst trying to get it up and running, eventuelly I ended up using a dzVents script. The script looks like this (basically saying, press the button every 5 minutes):
Code: Select all
return {
on = { timer = {"every 5 minutes"} },
execute = function(domoticz, _)
local myDevice = domoticz.devices("Zonnepanelen Update")
if myDevice.state == "On" then
myDevice.switchOn()
else
myDevice.switchOn()
end
end
}
I'm sure that there's a better way to do this but again: for me ignorance is bliss and I adhere to "if it ain't broken don't fix it" (lazy, jep!)
That ought to do it!
Disclaimers and more detailed info:
- I am no programmer, developer or whatever, just a hobbyist. Had to "learn" a bit (more) Python and JSON but I am no expert. So: No warranties, and I'm sure it lacks efficiency etc. Knock yourself out on improvements
- I am only reading the current usage/production and the status. The status can have various values I found (0 = off, 1 = on, 2 something else?), but the switch only understands 0 and 1, when it's 2 it shows "Dimmed". Not sure what other statusses other than 0 and 1 mean, enlighten me if you figured it out
- In the JSON I am retrieving there's more values that might be interesting and that can be used for calculations. I couldn't figure it out quickly and had accomplished my goal so this is it for me. Feel free to venture onward!
- This is it for me, I've accomplished the goal I wanted to achieve, so I won't be updating and advancing the functionality. Knock yourself out doing so
-
Credits for large parts of the scripting go to the people that had already created this before me, I just modded a bit!
Hopefully this helps the people that were running into the same questions/issues I was. I'm happy about it (and kind of proud as well, gotta be honest
). The end result looks like this:
And now I'm done typing. My fingers are sore...