Fronius solar inverter Plugin

Python and python framework

Moderator: leecollings

Post Reply
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Fronius solar inverter Plugin

Post by ayasystems »

Hi

I have completed another plugin to integrate Fronius FV inverter into domoticz
onduleur-fronius-primo-60-1.jpg
onduleur-fronius-primo-60-1.jpg (17.22 KiB) Viewed 4369 times
froniusDomoticz.jpg
froniusDomoticz.jpg (90.07 KiB) Viewed 4523 times

https://github.com/ayasystems/froniusHttp


Enjoy it!
Last edited by ayasystems on Friday 10 July 2020 10:25, edited 1 time in total.
zettie
Posts: 5
Joined: Tuesday 07 July 2020 9:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by zettie »

Hi,
I followed your instructions to install it on my raspberry ( https://domotuto.com/fronius_domoticz_plugin/ ), but i don't see any values in the information fields. When I go to the Fronius converter on my local network I do see the values
Are there some more settings, for instance on the Fronius converter?
User avatar
sincze
Posts: 1301
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Fronius solar inverter Plugin

Post by sincze »

Haha nice. This I got to try. :lol:
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by ayasystems »

zettie wrote: Tuesday 07 July 2020 10:11 Hi,
I followed your instructions to install it on my raspberry ( https://domotuto.com/fronius_domoticz_plugin/ ), but i don't see any values in the information fields. When I go to the Fronius converter on my local network I do see the values
Are there some more settings, for instance on the Fronius converter?
Did you provide the relevant settings??

Host IP ....

Please send a screen shot
zettie
Posts: 5
Joined: Tuesday 07 July 2020 9:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by zettie »

Yes, I,ve filled in the IP adress.
screen.png
screen.png (391.78 KiB) Viewed 4430 times
modules.png
modules.png (221.66 KiB) Viewed 4430 times
zettie
Posts: 5
Joined: Tuesday 07 July 2020 9:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by zettie »

I get the following error messages in the Domoticz logfile:

2020-07-07 21:30:34.416 (Fronius) Good Response received from Solax, Dropping connection.
2020-07-07 21:30:34.417 Error: (Fronius) 'onMessage' failed 'NameError'.
2020-07-07 21:30:34.417 Error: (Fronius) ----> Line 229 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-07 21:30:34.417 Error: (Fronius) ----> Line 164 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-07 21:30:34.418 Error: (Fronius) ----> Line 324 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by ayasystems »

Please set max debug level and send the log

What's your fronius model??

Test to open the following urls and let me know the response

http://IP_FRONIUS/solar_api/v1/GetMeterRealtimeData.cgi?Scope=System
http://IP_FRONIUS/solar_api/v1/GetPowerFlowRealtimeData.fcgi
http://IP_FRONIUS/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System

The plugin was done using a FRONIUS PRIMO 6.0-1 6KW


Regards
zettie
Posts: 5
Joined: Tuesday 07 July 2020 9:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by zettie »

Hi, I have a Fronius Symo 5.0-3-M.

The output for http://IP_FRONIUS/solar_api/v1/GetMeterRealtimeData.cgi?Scope=System is:

{
"Body" : {
"Data" : {
"0" : {
"Details" : {
"Manufacturer" : "Fronius",
"Model" : "S0 Meter at inverter 1",
"Serial" : "n.a."
},
"Enable" : 0,
"Meter_Location_Current" : 0,
"TimeStamp" : 1594141652,
"Visible" : 1
}
}
},
"Head" : {
"RequestArguments" : {
"DeviceClass" : "Meter",
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2020-07-09T13:23:14+02:00"
}
}


the output for http://IP_FRONIUS/solar_api/v1/GetPowerFlowRealtimeData.fcgi is:

{
"Body" : {
"Data" : {
"Inverters" : {
"1" : {
"DT" : 122,
"E_Day" : 3228.5,
"E_Total" : 590416,
"E_Year" : 590416.9375,
"P" : 847
}
},
"Site" : {
"E_Day" : 3228.5,
"E_Total" : 590416,
"E_Year" : 590416.9375,
"Meter_Location" : "unknown",
"Mode" : "vague-meter",
"P_Akku" : null,
"P_Grid" : null,
"P_Load" : null,
"P_PV" : 847,
"rel_Autonomy" : null,
"rel_SelfConsumption" : null
},
"Version" : "12"
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2020-07-09T13:25:13+02:00"
}
}


the output for http://IP_FRONIUS/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System is:

{
"Body" : {
"Data" : {
"DAY_ENERGY" : {
"Unit" : "Wh",
"Values" : {
"1" : 3248
}
},
"PAC" : {
"Unit" : "W",
"Values" : {
"1" : 694
}
},
"TOTAL_ENERGY" : {
"Unit" : "Wh",
"Values" : {
"1" : 590436
}
},
"YEAR_ENERGY" : {
"Unit" : "Wh",
"Values" : {
"1" : 590436
}
}
}
},
"Head" : {
"RequestArguments" : {
"DeviceClass" : "Inverter",
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2020-07-09T13:26:48+02:00"
}
}
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by ayasystems »

You have a diferent Fronius model, seems like json are diferent. I will try to add your model to work
zettie
Posts: 5
Joined: Tuesday 07 July 2020 9:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by zettie »

Hi, that would be terrific!
I didn't know that there is a difference in output between the Primo and the Symo because the picture you fist placed was of a Symo :D
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by ayasystems »

zettie wrote: Friday 10 July 2020 13:13 Hi, that would be terrific!
I didn't know that there is a difference in output between the Primo and the Symo because the picture you fist placed was of a Symo :D
I changed it..

I have not frunius inverter. I did it with data from one friend... I will try to add Symo... I have changed the picture (now it is a Primo)
jansen1443
Posts: 1
Joined: Friday 02 March 2018 20:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by jansen1443 »

Hello,

When using this plugin with a Primo 3.0-1 I get the same message.
Am I doing something wrong?

020-07-20 21:30:47.773 (Fronius) Pushing 'onMessageCallback' on to queue
2020-07-20 21:30:47.773 (Fronius) Processing 'onMessageCallback' message
2020-07-20 21:30:47.773 (Fronius) Calling message handler 'onMessage'.
2020-07-20 21:30:47.773 (Fronius) HTTP Details (3):
2020-07-20 21:30:47.773 (Fronius) a>'Status':'200'
2020-07-20 21:30:47.773 (Fronius) b>'Headers':
2020-07-20 21:30:47.773 (Fronius) ----a>'Content-Type':'application/json'
2020-07-20 21:30:47.773 (Fronius) ----a>'Cache-Control':'no-cache, no-store, must-revalidate'
2020-07-20 21:30:47.773 (Fronius) ----a>'Pragma':'no-cache'
2020-07-20 21:30:47.773 (Fronius) ----a>'Expires':'0'
2020-07-20 21:30:47.773 (Fronius) ----a>'Content-Length':'902'
2020-07-20 21:30:47.773 (Fronius) ----a>'Date':'Mon, 20 Jul 2020 19:30:45 GMT'
2020-07-20 21:30:47.774 (Fronius) ----a>'Server':'webserver'
2020-07-20 21:30:47.774 (Fronius) a>'Data':'b'{\n "Body" : {\n "Data" : {\n "Inverters" : {\n "1" : {\n "DT" : 81,\n "E_Day" : 15056,\n "E_Total" : 16248359,\n "E_Year" : 1798289.625,\n "P" : 0\n }\n },\n "Site" : {\n "E_Day" : 15056,\n "E_Total" : 16248359,\n "E_Year" : 1798289.625,\n "Meter_Location" : "unknown",\n "Mode" : "produce-only",\n "P_Akku" : null,\n "P_Grid" : null,\n "P_Load" : null,\n "P_PV" : null,\n "rel_Autonomy" : null,\n "rel_SelfConsumption" : null\n },\n "Version" : "12"\n }\n },\n "Head" : {\n "RequestArguments" : {},\n "Status" : {\n "Code" : 0,\n "Reason" : "",\n "UserMessage" : ""\n },\n "Timestamp" : "2020-07-20T21:30:45+02:00"\n }\n}\n''
2020-07-20 21:30:47.774 (Fronius) Good Response received from Solax, Dropping connection.
2020-07-20 21:30:47.774 Error: (Fronius) 'onMessage' failed 'NameError'.
2020-07-20 21:30:47.774 Error: (Fronius) ----> Line 229 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-20 21:30:47.774 Error: (Fronius) ----> Line 164 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-20 21:30:47.774 Error: (Fronius) ----> Line 324 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse
2020-07-20 21:30:57.548 (Fronius) Sending 222 bytes of data
2020-07-20 21:30:57.548 (Fronius) 47 45 54 20 2f 73 6f 6c 61 72 5f 61 70 69 2f 76 31 2f 47 65 GET./solar_api/v1/Ge
2020-07-20 21:30:57.548 (Fronius) 74 50 6f 77 65 72 46 6c 6f 77 52 65 61 6c 74 69 6d 65 44 61 tPowerFlowRealtimeDa
2020-07-20 21:30:57.548 (Fronius) 74 61 2e 66 63 67 69 20 48 54 54 50 2f 31 2e 31 0d 0a 43 6f ta.fcgi.HTTP/1.1..Co
2020-07-20 21:30:57.548 (Fronius) 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 78 6d 6c ntent-Type:.text/xml
2020-07-20 21:30:57.548 (Fronius) 3b 20 63 68 61 72 73 65 74 3d 75 74 66 2d 38 0d 0a 43 6f 6e ;.charset=utf-8..Con
2020-07-20 21:30:57.548 (Fronius) 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 2d 61 6c 69 76 65 0d nection:.keep-alive.
2020-07-20 21:30:57.548 (Fronius) 0a 41 63 63 65 70 74 3a 20 43 6f 6e 74 65 6e 74 2d 54 79 70 .Accept:.Content-Typ
2020-07-20 21:30:57.548 (Fronius) 65 3a 20 74 65 78 74 2f 68 74 6d 6c 3b 20 63 68 61 72 73 65 e:.text/html;.charse
2020-07-20 21:30:57.548 (Fronius) 74 3d 55 54 46 2d 38 0d 0a 48 6f 73 74 3a 20 31 39 32 2e 31 t=UTF-8..Host:.192.1
2020-07-20 21:30:57.548 (Fronius) 36 38 2e 32 32 2e 31 31 36 3a 38 30 0d 0a 55 73 65 72 2d 41 68.22.116:80..User-A
2020-07-20 21:30:57.548 (Fronius) 67 65 6e 74 3a 20 44 6f 6d 6f 74 69 63 7a 2f 31 2e 30 0d 0a gent:.Domoticz/1.0..
2020-07-20 21:30:57.548 (Fronius) 0d 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
2020-07-20 21:30:57.798 (Fronius) Pushing 'ReadEvent' on to queue
2020-07-20 21:30:57.799 (Fronius) Processing 'ReadEvent' message
2020-07-20 21:30:57.799 (Fronius) Received 1112 bytes of data
2020-07-20 21:30:57.799 (Fronius) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e HTTP/1.1.200.OK..Con
tjabas
Posts: 562
Joined: Sunday 11 December 2016 13:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by tjabas »

Hi!

i have tried your plugin and it works great but just on one of my fronius inverters,
the one that it works on has a fronius smartmeter, the other one where the plugins doesnt work doesnt have any smart meter, does this plugin require a smartmeter for it to work?
i get this error message in the log:

2020-07-22 11:31:41.176 Error: (Fronius) onStart:
2020-07-22 11:31:41.176 Error: (Fronius) onStart - try
2020-07-22 11:31:41.194 Error: (Fronius) Address: 192.168.1.182
2020-07-22 11:31:41.194 Error: (Fronius) port: 80
2020-07-22 11:31:41.194 Error: (Fronius) Address: 192.168.1.182
2020-07-22 11:31:41.346 Error: (Fronius) 'onMessage' failed 'NameError'.
2020-07-22 11:31:41.346 Error: (Fronius) ----> Line 229 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-22 11:31:41.346 Error: (Fronius) ----> Line 164 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-22 11:31:41.346 Error: (Fronius) ----> Line 324 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse
2020-07-22 11:31:51.548 Error: (Fronius) 'onMessage' failed 'NameError'.
2020-07-22 11:31:51.548 Error: (Fronius) ----> Line 229 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-22 11:31:51.548 Error: (Fronius) ----> Line 164 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-22 11:31:51.548 Error: (Fronius) ----> Line 324 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse
2020-07-22 11:32:01.374 Error: (Fronius) 'onMessage' failed 'NameError'.
2020-07-22 11:32:01.374 Error: (Fronius) ----> Line 229 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-22 11:32:01.374 Error: (Fronius) ----> Line 164 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-07-22 11:32:01.374 Error: (Fronius) ----> Line 324 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by ayasystems »

Do you have meter connected?? I will fix measures without meter....

I have not time at now but i will back after summer, sorry
tjabas
Posts: 562
Joined: Sunday 11 December 2016 13:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by tjabas »

hi!

yes on one of the inverters there is a meter, the other one dont have one.
the one with a fronius smartmeter works good, but not the other one.
tjabas
Posts: 562
Joined: Sunday 11 December 2016 13:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Fronius solar inverter Plugin

Post by tjabas »

i have enabled debuggin on the inverter that doesnt seem to connect, and it actually seems like the plugin connects to the inverter, but i cant read the data from the inverter.
gniazdoj
Posts: 7
Joined: Monday 13 January 2020 21:16
Target OS: Linux
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Fronius solar inverter Plugin

Post by gniazdoj »

ayasystems wrote: Wednesday 22 July 2020 14:14 Do you have meter connected?? I will fix measures without meter....

I have not time at now but i will back after summer, sorry
Hi,
I have as well Primo 3.0-1 without any meter, would be great to have option to disable it on Hardware tab if that is the issue. I'm getting same errors like jansen1443. If you need any dump of communication please let me know. It would be great to use more advance option. Hope it support night when inverter is offline as my current script produce error each minute because of unhandled connection.
Thank you
Jakub
gniazdoj
Posts: 7
Joined: Monday 13 January 2020 21:16
Target OS: Linux
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Fronius solar inverter Plugin

Post by gniazdoj »

gniazdoj wrote: Tuesday 20 October 2020 19:13
ayasystems wrote: Wednesday 22 July 2020 14:14 Do you have meter connected?? I will fix measures without meter....

I have not time at now but i will back after summer, sorry
Hi,
I have as well Primo 3.0-1 without any meter, would be great to have option to disable it on Hardware tab if that is the issue. I'm getting same errors like jansen1443. If you need any dump of communication please let me know. It would be great to use more advance option. Hope it support night when inverter is offline as my current script produce error each minute because of unhandled connection.
Thank you
Jakub
I have Primo 3.0-1 I would see switch on Hardware configuration tab to select between Inverters. We need to use different URL to get data from with different data structure. You can look on draft code that I've changed from original great phyton script from author.

Code: Select all

# Fronius http python plugin
# @2020
# Author: EA4GKQ
#https://github.com/akleber/fronius-json-tools
# 06/05/2020
# - Añadido dummy con valor medio de Grid de las últimas 30 muestras
# - Mejorada reconexión automática
"""
<plugin key="FroniusHttp" name="Fronius http" author="EA4GKQ" version="1.0.2" wikilink="https://github.com/ayasystems/froniusHttp" externallink="https://www.fronius.com/es-es/spain/energia-solar/productos">
    <description>
        <h2>Fronius HTTP Pluging</h2><br/>
        <h3>by @ea4gkq</h3>
		<br/>
		<a href="https://domotuto.com/fronius_domoticz_plugin/">https://domotuto.com/fronius_domoticz_plugin/</a>
		<br/>
    </description>
    <params>
        <param field="Address" label="Fronius IP" width="200px" required="true" default="192.168.1.xx"/>
        <param field="Mode1" label="Protocol" width="75px">
            <options>
                <option label="HTTP" value="80"  default="true" />
            </options>
        </param>
        <param field="Mode2" label="Update speed" width="75px">
            <options>
                <option label="Normal" value="Normal"/>
                <option label="High" value="High"  default="true" />
            </options>
        </param>        
        <param field="Mode6" label="Debug" width="150px">
            <options>
                <option label="None" value="0"  default="true" />
                <option label="Python Only" value="2"/>
                <option label="Basic Debugging" value="62"/>
                <option label="Basic+Messages" value="126"/>
                <option label="Connections Only" value="16"/>
                <option label="Connections+Queue" value="144"/>
                <option label="All" value="-1"/>
            </options>
        </param>
    </params>
</plugin>  
"""
errmsg = ""
try:
 import Domoticz
except Exception as e:
 errmsg += "Domoticz core start error: "+str(e)
try:
 import json
except Exception as e:
 errmsg += " Json import error: "+str(e)
try:
 import time
except Exception as e:
 errmsg += " time import error: "+str(e)
try:
 import re
except Exception as e:
 errmsg += " re import error: "+str(e)
from random import seed
from random import gauss
from functools import reduce

class FroniusHttp:
    httpConn = None
    interval = 1
    runAgain = interval
    connectedCount = 0
    disconnectCount = 0
    sProtocol = "HTTP"
    DAY_ENERGY1 = ""
    PAC1 = ""
    TOTAL_ENERGY1 = ""
    DAY_ENERGY = ""
    PAC = ""
    TOTAL_ENERGY = ""
    P_PV = ""                  #Instant production
    E_Day = ""                 #Total of the day
    E_Total = ""               #Total Production
    E_Year = ""                #Production Year
    P_Grid = ""                #Negative inject Positive consume  
    UAC = ""                #Grid + solar consumption
    FAC = ""
    IAC = ""
    IDC = ""
    UDC = ""
    UAC = ""
    F_PAC = ""
    F_FAC = ""
    F_IAC = ""
    F_IDC = ""
    F_UDC = ""
    F_UAC = ""
    GRID_W = ""	
    listGrid = [] 
    maxGridList = 30
    avgGrid = 0     
    URL2 = "/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System"
    #URL1 = "/solar_api/v1/GetPowerFlowRealtimeData.fcgi"
    URL1 = "/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData"#jakub
    #URL2 = "/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData"#jakub
    #192.168.1.51/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DataCollection=CommonInverterData&DeviceId=1 
    current = ""
    def __init__(self):
        return

    def onStart(self):
     Domoticz.Error("onStart: "+errmsg)
     if errmsg =="":
      try:
        Domoticz.Debug("onStart - try")	  
        if Parameters["Mode6"] == "": Parameters["Mode6"] = "-1"
        if Parameters["Mode6"] != "0":
            Domoticz.Debug("if parameters mode 6: "+Parameters["Mode6"])	  
            Domoticz.Debugging(int(Parameters["Mode6"]))
            Domoticz.Debug("DumpConfigToLog")	
            DumpConfigToLog()
        createDevices(self,"F_PAC")	
        createDevices(self,"F_FAC")
        createDevices(self,"F_IAC")			
        createDevices(self,"F_IDC") 	
        createDevices(self,"F_UAC") 
        createDevices(self,"F_UDC")
   
        if (Parameters["Mode1"].strip()  == "443"): self.sProtocol = "HTTPS"
        if (Parameters["Mode2"].strip()  == "High"): Domoticz.Heartbeat(1)
        Domoticz.Debug("Address: "+Parameters["Address"])
        Domoticz.Debug("port: "+Parameters["Mode1"].strip())
        Domoticz.Debug("Address: "+Parameters["Address"].strip())		
        self.httpConn = Domoticz.Connection(Name=self.sProtocol+" Test", Transport="TCP/IP", Protocol=self.sProtocol, Address=Parameters["Address"].strip() , Port=Parameters["Mode1"].strip() )
        self.httpConn.Connect()
      except Exception as e:
        Domoticz.Error("Plugin onStart error: "+str(e))
     else:
        Domoticz.Error("Your Domoticz Python environment is not functional! "+errmsg)

    def onStop(self):
        Domoticz.Log("onStop - Plugin is stopping.")
    def Average(self):
        if(len(self.listGrid)>self.maxGridList):
            self.listGrid.pop(0)
        #Domoticz.Debug("List values: "+str(self.listGrid))    
        self.avgGrid = reduce(lambda a,b: a + b, self.listGrid) / len(self.listGrid)
        self.avgGrid = round(self.avgGrid,0)
    def onConnect(self, Connection, Status, Description):
        if (Status == 0):
            Domoticz.Debug("Fronius connected successfully.")
            if(self.current==self.URL2):
               self.current=self.URL1
            else:
               self.current=self.URL2	
            self.current=self.URL1               
            sendData = { 'Verb' : 'GET',
                         'URL'  : self.current,
                         'Headers' : { 'Content-Type': 'text/xml; charset=utf-8', \
                                       'Connection': 'keep-alive', \
                                       'Accept': 'Content-Type: text/html; charset=UTF-8', \
                                       'Host': Parameters["Address"]+":"+Parameters["Mode1"], \
                                       'User-Agent':'Domoticz/1.0' }
                       }
            Connection.Send(sendData)
        else:
            Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Mode1"]+" with error: "+Description)

    def onMessage(self, Connection, Data):
        DumpHTTPResponseToLog(Data)
   
        strData = Data["Data"].decode("utf-8", "ignore")
        Status = int(Data["Status"])
        #LogMessage(strData)
        #Domoticz.Debug("Data.onMessage: " + str(Data))
        Domoticz.Debug("Status.onMessage: " + str(Status))
        #Domoticz.Debug("self.disconnectCount & 1: " + str((self.disconnectCount & 1)) )

        if (Status == 200):
            if ((self.disconnectCount & 1) == 1):
                Domoticz.Log("Good Response received from Solax, Disconnecting.")
                self.httpConn.Disconnect()
            else:
                Domoticz.Log("Good Response received from Solax, Dropping connection.")
                self.httpConn = None
            self.disconnectCount = self.disconnectCount + 1
            processResponse(self,Data) 
        elif (Status == 302):
            Domoticz.Log("Fronius returned a Page Moved Error.")
            sendData = { 'Verb' : 'GET',
                         'URL'  : Data["Headers"]["Location"],
                         'Headers' : { 'Content-Type': 'text/xml; charset=utf-8', \
                                       'Connection': 'keep-alive', \
                                       'Accept': 'Content-Type: text/html; charset=UTF-8', \
                                       'Host': Parameters["Address"]+":"+Parameters["Mode1"], \
                                       'User-Agent':'Domoticz/1.0' },
                        }
            Connection.Send(sendData)
        elif (Status == 400):
            Domoticz.Error("Solax returned a Bad Request Error.")
            self.httpConn.Disconnect()
            self.httpConn = None
        elif (Status == 500):
            Domoticz.Error("Solax returned a Server Error.")
            self.httpConn.Disconnect()
            self.httpConn = None
        else:
            Domoticz.Debug("Solax returned a status: "+str(Status))

    def onCommand(self, Unit, Command, Level, Hue):
        Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))

    def onDisconnect(self, Connection):
        Domoticz.Debug("onDisconnect called for connection to: "+Connection.Address+":"+Connection.Port)

    def onHeartbeat(self):
        if(self.connectedCount>10):
            self.connectedCount = 0
            self.httpConn.Disconnect()
            self.httpConn = None    
        #Domoticz.Trace(True)
        if (self.httpConn != None and (self.httpConn.Connecting() or self.httpConn.Connected())):
            Domoticz.Debug("onHeartbeat called, Connection is alive.")
        else:
            self.runAgain = self.runAgain - 1
            if self.runAgain <= 0:
                if (self.httpConn == None):
                    self.httpConn = Domoticz.Connection(Name=self.sProtocol+" Test", Transport="TCP/IP", Protocol=self.sProtocol, Address=Parameters["Address"], Port=Parameters["Mode1"])
                self.httpConn.Connect()
                self.runAgain = self.interval
            else:
                Domoticz.Debug("onHeartbeat called, run again in "+str(self.runAgain)+" heartbeats.")
        #Domoticz.Trace(False)

global _plugin
_plugin = FroniusHttp()

def onStart():
    global _plugin
    _plugin.onStart()

def onStop():
    global _plugin
    _plugin.onStop()

def onConnect(Connection, Status, Description):
    global _plugin
    _plugin.onConnect(Connection, Status, Description)

def onMessage(Connection, Data):
    global _plugin
    _plugin.onMessage(Connection, Data)

def onCommand(Unit, Command, Level, Hue):
    global _plugin
    _plugin.onCommand(Unit, Command, Level, Hue)

def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
    global _plugin
    _plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)

def onDisconnect(Connection):
    global _plugin
    _plugin.onDisconnect(Connection)

def onHeartbeat():
    global _plugin
    _plugin.onHeartbeat()

# Generic helper functions
def LogMessage(Message):
    if Parameters["Mode6"] == "File":
        f = open(Parameters["HomeFolder"]+"http.html","w")
        f.write(Message)
        f.close()
        Domoticz.Log("File written")

def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return
def processResponse(self,httpResp):
    DAY_ENERGY1 = ""#jakub
    PAC1 = ""
    TOTAL_ENERGY1 = ""
    stringData =  httpResp["Data"].decode("utf-8", "ignore")
    jsonData = json.loads(stringData)

    Domoticz.Debug("##self.current: "+self.current)
    Domoticz.Debug("##self.URL2: "+self.URL2)
    Domoticz.Debug("##self.URL1:    "+self.URL1)
    #Domoticz.Debug("httpResp.processResponse: " + str(httpResp))
    
    if(self.current==self.URL2):
       try:
            self.DAY_ENERGY1 = str(jsonData['Body']['Data']['DAY_ENERGY']['Values']['1'])
            self.PAC1 = str(jsonData['Body']['Data']['PAC']['Values']['1'])
            self.TOTAL_ENERGY1 = str(jsonData['Body']['Data']['TOTAL_ENERGY']['Values']['1'])
            if Parameters["Mode6"] == "-1":        
                Domoticz.Debug("DAY_ENERGY1: "+self.DAY_ENERGY1)
                Domoticz.Debug("PAC1: "+self.PAC1)
                Domoticz.Debug("TOTAL_ENERGY1: "+self.TOTAL_ENERGY1)
                self.connectedCount = 0
       except:
         Domoticz.Debug(str(e))   
    if(self.current==self.URL1):#jakub
        try:
            self.PAC     =  str(jsonData['Body']['Data']['PAC']['Value'])
            self.E_Day    =  str(jsonData['Body']['Data']['DAY_ENERGY']['Value'])
            self.E_Total  =  str(jsonData['Body']['Data']['TOTAL_ENERGY']['Value'])
            self.E_Year   =  str(jsonData['Body']['Data']['YEAR_ENERGY']['Value'])
            self.UAC      =  str(jsonData['Body']['Data']['UAC']['Value'])
            self.UDC      =  str(jsonData['Body']['Data']['UDC']['Value'])
            self.IAC      = str(jsonData['Body']['Data']['IAC']['Value'])
            self.IDC      = str(jsonData['Body']['Data']['IDC']['Value'])
            self.FAC      = str(jsonData['Body']['Data']['FAC']['Value']) 
            #self.P_PV     =  str(jsonData['Body']['Data']['Site']['P_PV'])
            #self.listGrid.append(F_IDC)
            #self.Average()       
            if Parameters["Mode6"] == "-1": 
                Domoticz.Error("F_PAC: "+self.PAC)
                Domoticz.Error("E_Day: "+self.E_Day)
                Domoticz.Error("E_Total: "+self.E_Total)
                Domoticz.Error("E_Year: "+self.E_Year)
                Domoticz.Error("F_UAC: "+self.UAC)
                Domoticz.Error("F_UDC: "+self.UDC)                 
                Domoticz.Error("F_IAC: "+self.IAC)
                Domoticz.Error("F_IDC: "+self.IDC)                
                Domoticz.Error("F_FAC: "+self.FAC)
                #Domoticz.Error("List: "+str(self.listGrid))
                #Domoticz.Error("AVG Grid: "+str(round(self.avgGrid,0)))     
            instantaneoFV        = self.PAC
            acumuladoKwhFV       = self.E_Day#daily accumulated
            
            #if(F_IDC>=0):
            #    UpdateDevice("F_FAC",      0, "0;0")
            #    UpdateDevice("F_IDC",      0, str(F_IDC)+";0")
            #Domoticz.Debug("##self.UAC : " + self.UAC )
            #if(F_FAC>0):
            #UpdateDevice("F_FAC",      0, self.P_Grid+";0")
            #    UpdateDevice("F_IDC",      0, "0;0")
            
            UpdateDevice("F_PAC",      0, instantaneoFV+";"+acumuladoKwhFV)
            UpdateDevice("F_UAC",      0, self.UAC+";0")
            UpdateDevice("F_UDC",      0, self.UDC+";0")
            UpdateDevice("F_FAC",      0, self.FAC+";0")
            UpdateDevice("F_IAC",      0, self.IAC+";0")
            UpdateDevice("F_IDC",      0, self.IDC+";0")
            #UpdAteDevice("AVGGRID",       0, self.avgGrid)
            
            self.connectedCount = 0
        except:
         Domoticz.Debug(str(e))   
def DumpHTTPResponseToLog(httpResp, level=0):
    if (level==0): Domoticz.Debug("HTTP Details ("+str(len(httpResp))+"):")
    indentStr = ""
    for x in range(level):
        indentStr += "----"
    if isinstance(httpResp, dict):
        for x in httpResp:
            if not isinstance(httpResp[x], dict) and not isinstance(httpResp[x], list):
                Domoticz.Debug(indentStr + "a>'" + x + "':'" + str(httpResp[x]) + "'")
            else:
                Domoticz.Debug(indentStr + "b>'" + x + "':")
                DumpHTTPResponseToLog(httpResp[x], level+1)
    elif isinstance(httpResp, list):
        for x in httpResp:
            Domoticz.Debug(indentStr + "['" + x + "']")
    else:
        Domoticz.Debug(indentStr + "c>'" + x + "':'" + str(httpResp[x]) + "'")
def createDevices(self,unitname):
      OptionsSensor = {"Custom": "1;Hz"}
      OptionsSensorAVG = {"Custom": "1;w"}
      iUnit = -1
      for Device in Devices:
       try:
        if (Devices[Device].DeviceID.strip() == unitname):
         iUnit = Device
         break
       except:
         pass
      if iUnit<0: # if device does not exists in Domoticz, than create it
        try:
         iUnit = 0
         for x in range(1,256):
          if x not in Devices:
           iUnit=x
           break
         Domoticz.Debug("Creating: "+unitname);
         if iUnit==0:
          iUnit=len(Devices)+1	  
         if(unitname=="F_IDC"): #amper
          Domoticz.Device(Name=unitname, Unit=iUnit,Type=243,Subtype=23,Switchtype=0,Used=1,DeviceID=unitname).Create()
         if(unitname=="F_IAC"): #amper
          Domoticz.Device(Name=unitname, Unit=iUnit,Type=243,Subtype=23,Switchtype=0,Used=1,DeviceID=unitname).Create()
         if(unitname=="F_FAC"): #custom
          Domoticz.Device(Name=unitname, Unit=iUnit,Type=243,Subtype=31,Switchtype=0,Used=1,DeviceID=unitname).Create()
         if(unitname=="F_UAC"): #voltage
          Domoticz.Device(Name=unitname, Unit=iUnit,Type=243,Subtype=8,Switchtype=0,Used=1,DeviceID=unitname).Create()
         if(unitname=="F_UDC"): #voltage
          Domoticz.Device(Name=unitname, Unit=iUnit,Type=243,Subtype=8,Switchtype=0,Used=1,DeviceID=unitname).Create()
         if(unitname=="F_PAC"):
          Domoticz.Device(Name=unitname, Unit=iUnit,Type=243,Subtype=29,Switchtype=0,Used=1,DeviceID=unitname).Create()
         
        except Exception as e:
         Domoticz.Debug(str(e))
         return False
      return 
def UpdateDevice(unitname, nValue, sValue):
    # Make sure that the Domoticz device still exists (they can be deleted) before updating it 
	#        if (Devices[Device].DeviceID.strip() == unitname):
      iUnit = -1
      for Device in Devices:
       try:
        if (Devices[Device].DeviceID.strip() == unitname):
         iUnit = Device
         break
       except:
         pass
      if iUnit>=0: # existe, actualizamos	
            if (Devices[iUnit].nValue != nValue) or (Devices[iUnit].sValue != sValue):
                Devices[iUnit].Update(nValue=nValue, sValue=str(sValue))
                Domoticz.Debug("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[iUnit].Name+")")
Still trying to get rid of error message during inverter is not operating but still responding to PING.

Code: Select all

2020-10-30 15:42:54.894 (FroniusInverter) Good Response received from Solax, Dropping connection.
2020-10-30 15:42:54.895 Error: (FroniusInverter) 'onMessage' failed 'NameError'.
2020-10-30 15:42:54.895 Error: (FroniusInverter) ----> Line 249 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-10-30 15:42:54.895 Error: (FroniusInverter) ----> Line 184 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function onMessage
2020-10-30 15:42:54.895 Error: (FroniusInverter) ----> Line 359 in '/home/pi/domoticz/plugins/froniusHttp/plugin.py', function processResponse
I've changed graphs as I don't have any battery and I'm collecting other information available.
Thanks for great code
Jakub
User avatar
Freakandel
Posts: 24
Joined: Tuesday 18 June 2019 14:23
Target OS: Linux
Domoticz version:
Location: Netherlands, Breda region
Contact:

Re: Fronius solar inverter Plugin

Post by Freakandel »

Hi, I was wonderring if you get it working. I have the same error in Domoticz log, using the plugin with a Fronius Symo 5.0-3 invertor:
2020-11-15 13:53:17.978 Error: (Fronius Solar Inverter) 'onMessage' failed 'NameError'.
2020-11-15 13:53:17.978 Error: (Fronius Solar Inverter) ----> Line 229 in '/home/maarten/domoticz/plugins/froniusHttp/plugin.py'
2020-11-15 13:53:17.978 Error: (Fronius Solar Inverter) ----> Line 164 in '/home/maarten/domoticz/plugins/froniusHttp/plugin.py'
2020-11-15 13:53:17.978 Error: (Fronius Solar Inverter) ----> Line 324 in '/home/maarten/domoticz/plugins/froniusHttp/plugin.py'
Restults with direct links to the Fronius:
Spoiler: show

Code: Select all

{
   "Body" : {
      "Data" : {}
   },
   "Head" : {
      "RequestArguments" : {
         "DeviceClass" : "Meter",
         "Scope" : "System"
      },
      "Status" : {
         "Code" : 0,
         "Reason" : "",
         "UserMessage" : ""
      },
      "Timestamp" : "2020-11-15T13:54:13+01:00"
   }
}[/quote]

[quote]{
   "Body" : {
      "Data" : {
         "Inverters" : {
            "1" : {
               "DT" : 122,
               "E_Day" : 690.29998779296875,
               "E_Total" : 690.00006103515625,
               "E_Year" : 690.29998779296875,
               "P" : 60
            }
         },
         "Site" : {
            "E_Day" : 690.29998779296875,
            "E_Total" : 690.00006103515625,
            "E_Year" : 690.29998779296875,
            "Meter_Location" : "unknown",
            "Mode" : "produce-only",
            "P_Akku" : null,
            "P_Grid" : null,
            "P_Load" : null,
            "P_PV" : 60,
            "rel_Autonomy" : null,
            "rel_SelfConsumption" : null
         },
         "Version" : "12"
      }
   },
   "Head" : {
      "RequestArguments" : {},
      "Status" : {
         "Code" : 0,
         "Reason" : "",
         "UserMessage" : ""
      },
      "Timestamp" : "2020-11-15T13:54:36+01:00"
   }
}[/quote]

[quote]{
   "Body" : {
      "Data" : {
         "DAY_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 691
            }
         },
         "PAC" : {
            "Unit" : "W",
            "Values" : {
               "1" : 54
            }
         },
         "TOTAL_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 691
            }
         },
         "YEAR_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 691
            }
         }
      }
   },
   "Head" : {
      "RequestArguments" : {
         "DeviceClass" : "Inverter",
         "Scope" : "System"
      },
      "Status" : {
         "Code" : 0,
         "Reason" : "",
         "UserMessage" : ""
      },
      "Timestamp" : "2020-11-15T13:55:35+01:00"
   }
}
I use the 06/05/2020 version of the python plugin.

I hove someone has fixed this, I would like to get info into Domoticz.
gniazdoj
Posts: 7
Joined: Monday 13 January 2020 21:16
Target OS: Linux
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Fronius solar inverter Plugin

Post by gniazdoj »

I use the 06/05/2020 version of the python plugin.

I hove someone has fixed this, I would like to get info into Domoticz.
Please use last code published. I've made some changes. Still working to support more devices and some cosmetics.
In general you need to find out your best URL depends of your device specification. You need to know if you have APIv0 or APIv1 and phase 1 or phase 3 installation. This determine URL you should use. The error you presented says we can't find name you requested. Because of wrong URL or missing data.
please update in script URL1 and URL4 to same value and select on Domoticz Hardware Tab-Inverter:"Fronius"
you can see our conversation where APIv0 was needed.
https://github.com/ayasystems/froniusHttp/issues/1

please try URL this is for 1phase devices:
APIv0

Code: Select all

http://IP/solar_api/GetInverterRealtimeData.cgi?Scope=Device&DeviceIndex=1&DataCollection=CommonInverterData
APIv1

Code: Select all

http://IP/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData
you can check different URL in documentation at right bottom of page, eg, 3phase devices
https://www.fronius.com/en/photovoltaic ... 4216b1f709

Good luck
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest