Page 1 of 1

LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Sunday 27 February 2022 11:39
by GSteel25
Hello together,

I am working for years with simple domoticz application which can be used just by adjusting the web surface.
In scripting I am just using some simple blockly skripts for now.

Now we got some solar cells on our roof trying to do something good to enviroment.
This is where domoticz could help now: The idea is that if we get the values provided by our inverter manufacturer Solax into domoticz we could activate power intensive devices when sun is shining.

My idea is to use a LUA-Parser script to grab the values from Solax API.
I created a HTTP/HTTPS poller in the hardware of domoticz and created one device for testing to have an idx to use for the script.

From the Solax API I get the follwing answer:
{"success":true,"exception":"Query success!","result":{"inverterSN":"H34T10H7127031","sn":"SW5RBJXNBS","acpower":2723.0,"yieldtoday":6.9,"yieldtotal":670.9,"feedinpower":14.0,"feedinenergy":287.79,"consumeenergy":1156.83,"feedinpowerM2":0.0,"soc":64.0,"peps1":0.0,"peps2":0.0,"peps3":0.0,"inverterType":"14","inverterStatus":"102","uploadTime":"2022-02-27 11:17:29","batPower":1620.0,"powerdc1":3294.0,"powerdc2":1165.0,"powerdc3":null,"powerdc4":null}}

So the LUA Code has to separate the JSON formated API answer and write the values into the virtual devices.
I found a script to parse JSON via LUA but I was not able to change it for my needs:

Code: Select all

-- Example of JSON parser handling data with the following structure
--{
--  "id": 13,
--  "name": "outside",
--  "temperature": 12.50,
--  "tags": ["France", "winter"]
--}

-- A test with curl would be : curl -X POST -d "@test.json" 'http://192.168.1.17:8080/json.htm?type=command&param=udevices&script=example_json.lua'

-- Retrieve the request content
s = request['content'];

-- Update some devices (index are here for this example)
local id = domoticz_applyJsonPath(s,'.id')
local s = domoticz_applyJsonPath(s,'.temperature')
domoticz_updateDevice(id,'',s)
I think the main problem is that I don't understood what is "s" in the code example and where do I have to adjust the code.
Can someone help me how the script has to look like in my case please with comments for one who wants to work with LUA first time?

Otherwise has someone a better idea for my problem?

Thank you all for help.

Regards! :)

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Sunday 27 February 2022 11:43
by waltervl
You are aware there is a Python plugin for Domoticz that can read the values? viewtopic.php?t=33872

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Sunday 27 February 2022 12:01
by GSteel25
waltervl wrote: Sunday 27 February 2022 11:43 You are aware there is a Python plugin for Domoticz that can read the values? viewtopic.php?t=33872
Thank you for your answer. I found that solution before but had much more respect to adjust that code because it is much longer and I thought I would have more problems to adjust it than the short LUA one. Moreover it looked for me as if its not reading all the values available what would mean more adjusting necessary without understanding the code.
But if you/ or someone else could please mark the parts of the code or commend which lines have to be ajusted, I would try the python script too.

Thank you and best regards!

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Saturday 07 January 2023 16:36
by masselb
Hello Gsteel25,

Do you have the answer to the correct adjustment of the values in the example Lua-parser? I have installed a Solax X3 Hybrid G4 and get values by installing the Python plugin but the problem is that these values are not real time. With the real time get of Solax one would be able to get actual values.
As i am not a "script wizzard" I have no clue on how to use the parser (adjust it to my needs).

If you have got the answer or figured out how to adjust would you post it here please?

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Monday 09 January 2023 15:16
by masselb
Hello Community,

Is there anyone with Lua knowledge that can help in this case. As far as I understand it, the example-parser that is in Domoticz just needs adjustment so the values from the real time API will be injected into Domoticz. I guess in the first part, the 13 is the IDX, and "name" is the virtual device name. These Tags are merely a sort of extra description so not Important (?)

Is there maybe a developer/scripter in th ehoude that can descripe the example so I understand what to alter? I would really like to get actual values in my domoticz, the Plugins I found are functional but only few values and not real time. Little help appreciated :D

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Monday 23 January 2023 15:57
by masselb
No LUA-wizzard available in these forums? :?

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Monday 23 January 2023 18:18
by waltervl
The issue will be more about JSON (or XML) parsing. As that is mostly the tricky part.

So http poller will give a JSON message to the script. Then that message is parsed with command domoticz_applyJsonPath to get a value out of the JSON message and with command domoticz_updateDevice these values as stored into a Domoticz device.

See also wiki https://www.domoticz.com/wiki/HTTP/HTTPS_poller

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Monday 30 January 2023 18:12
by masselb
Hmm I can't follow you walter... The script is beiing activated by the poller yes, but the example script is .. an example. So i would like to know what value I need to alter to make the script spit out the actual value. In essence, the same question as asked by GSteel25. I was very pleased to find Solax has this API because it is real time, where I find all existing plugins read the values out of the Cloud frontend which I can open in a browser myself :)
Also, the documentation from Solax states much more values then those that come out of the plugins.

But, wenn nobody can alter the script to fit the needs of the Solax API, I will have to look for other ways to read the values in real time..
(Maybe install a webcam in front of the inverter display Ghehe) or make a study of Node Red.. dunno yet but It just would be cool to get values in Domoticz. Maybe some hobbyist will buy a Solax as well and write a new plugin... :lol:

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Monday 30 January 2023 18:17
by waltervl
Did you search for other plugins or scripts to read Solax API? HTTP Poller is only one of many methods Domoticz can read inverters.
Check this one. No need to script: https://github.com/ayasystems/SolaxHTTP

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Monday 30 January 2023 18:32
by masselb
Hey, yes but I didn't get it to work on my PI nor my Windows machine. I am not sure if it gets me the real time values or the "5 minutes values" but as i said, didn't work for me.. Maybe i will give this one another try only if it runs i can compare the readings. Also, my spanish is somewaht "rusty" Ghehe

Re: LUA Parser for Inverter Values from Solax Cloud (JSON)

Posted: Tuesday 31 January 2023 9:09
by masselb
Tried again on another Pi but it seems the plugin is not ready to deal with a new Inverter (WiFi 3.0). Guess i am for now stuck with few values and 5 minutes..