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¶m=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)
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!
