Page 1 of 1
solar inverter
Posted: Tuesday 07 March 2023 14:35
by philiphili
Hello everyone. I'm new here and my name is Philip.
I have a script to scrape the data from my solar inverters website but how can i send the scraped data to different dummy devices?
Please help. I'm stuck. Thank you
Re: solar inverter
Posted: Tuesday 07 March 2023 15:04
by willemd
If you have the various values already in your python program, then you could use JSON calls to get data into the domoticz database for chosen devices.
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
If your website shows the data as in your second screen print, you could also use http poller setup in the hardware section to get the data in.
Re: solar inverter
Posted: Wednesday 08 March 2023 16:31
by philiphili
Hoe geraak ik aan de json url? Is dit via een script in python?
Re: solar inverter
Posted: Wednesday 08 March 2023 17:22
by philiphili
How do I get the json url? Is this via a script in python?
Re: solar inverter
Posted: Wednesday 08 March 2023 20:16
by waltervl
Here you have a python script that does something like this for an Omnik Inverter.
https://www.domoticz.com/wiki/Omnik_Solar_Inverter
Re: solar inverter
Posted: Thursday 09 March 2023 15:18
by philiphili
Thanks but that's not what I'm looking for. I just want an addition to my script to send the result to domoticz and I also have no idea how to get a json url.
Re: solar inverter
Posted: Thursday 09 March 2023 15:31
by waltervl
Re: solar inverter
Posted: Thursday 09 March 2023 16:07
by willemd
Here is an extract from one of my python programs. It shows you how to assign a json url string to a variable and then how to call that url.
The string created from the combination of two substrings called "baseJSON" and "apiCall" is called with requests.get.
Code: Select all
import requests, json
## Domoticz server
domoticzIP="127.0.0.1" # internal IP address of the Domoticz server.
domoticzPort="8080" # Domoticz port
baseJSON="http://"+domoticzIP+":"+domoticzPort+"/json.htm?" # the base string for any JSON call.
def getPercentageDevice(varIDX):
# function to get the value of a percentage device indicated by the varIDX number
try:
apiCall="type=devices&rid="+str(varIDX)
response = requests.get(baseJSON+apiCall)
responseResult=str(response.json()["status"])
if responseResult=="ERR":
raise Exception
else:
varString=response.json()["result"][0]["Data"]
varValue=float(varString.split("%")[0])
responseResult=True
except:
print("ERROR: unable to retrieve the value of device with IDX ",varIDX)
print("Response was : ",response.json())
responseResult=False
varValue=None
return responseResult,varValue
Re: solar inverter
Posted: Thursday 09 March 2023 16:09
by willemd
and a similar construct you can then use to update a device. Here is an example for a text device:
Code: Select all
def setTextDevice(textIDX,displayText):
# update the value of a text device and adds an entry to the device log file
try:
if len(displayText)<=200:
urlText=urllib.parse.quote(displayText)
apiCall="type=command¶m=udevice&idx="+str(textIDX)+"&nvalue=0&svalue="+urlText
response=requests.get(baseJSON+apiCall)
responseResult=str(response.json()["status"])
if responseResult=="ERR":
raise Exception
else:
responseResult=True
else:
print("ERROR: displayText too long (max 200 characters).")
raise Exception
except:
print("ERROR: failed to update text device with IDX ",textIDX)
print("Response was : ",response.json())
responseResult=False
return responseResult