solar inverter

Python and python framework

Moderator: leecollings

Post Reply
philiphili
Posts: 4
Joined: Tuesday 07 March 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

solar inverter

Post 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
Attachments
2023-03-07.jpg
2023-03-07.jpg (274.5 KiB) Viewed 631 times
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: solar inverter

Post 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.
philiphili
Posts: 4
Joined: Tuesday 07 March 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: solar inverter

Post by philiphili »

Hoe geraak ik aan de json url? Is dit via een script in python?
philiphili
Posts: 4
Joined: Tuesday 07 March 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: solar inverter

Post by philiphili »

How do I get the json url? Is this via a script in python?
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: solar inverter

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
philiphili
Posts: 4
Joined: Tuesday 07 March 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: solar inverter

Post 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.
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: solar inverter

Post by waltervl »

Thake a look at this example script https://www.domoticz.com/wiki/Python_-_ ... o_PVOutput
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: solar inverter

Post 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

willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: solar inverter

Post 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&param=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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest