After lurking for quite some time, I decided to register an account and share my newly created script for reading the values out of my solar collector.
I installed a solar collector set this week. The pump is controlled by a Resol DeltaSol® CS Plus http://www.resol.de/index/produktdetail ... sprache/en and I bought a Resol DL2 Datalogger http://www.resol.de/index/produktdetail ... sprache/en
The Datalogger has some nice features to read the current values, save historic values and post them to the VBus.net site.
I wanted to add those values to my domoticz system, so I wrote a Lua to get the values and update my sensors.
As I am fairly new to LUA and JSON, I had some trouble getting the right values from the JSON to the Lua Table and into Variables.
My Solution: Uncomment the print_r on row 71. This will print a nice table in your log, showing the complete table created from the JSON. From there you can find the associated indexes for the values you require.
Create the Dummy sensors you need, in my case "TempCollector", "TempBoilerTop", "TempBoilerBottom", "CurrentPumpSpeed", "TotalPumpTime".
Note their IDX's and add them to the script.
You will need the json.lua from http://regex.info/blog/lua/json. In my case it is in "/home/pi/domoticz/scripts/lua/". Change the path in row 52 for your location.
Important: I configured my DL2 to allow the guest user (unauthenticated) to read live data. If you don't, you have to add the "...live?sessionAuthUsername=admin&sessionAuthPassword=admin" settings to the URL
As stated, I am not expert on LUA or JSON, so if you know a better way to do some actions, please let me know.
Code: Select all
commandArray = {}
--- Function print_r, used for getting the complete table so you can determine wich values to use
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
print(indent..string.rep(" ",string.len(pos)+6).."}")
elseif (type(val)=="string") then
print(indent.."["..pos..'] => "'..val..'"')
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
if (type(t)=="table") then
print(tostring(t).." {")
sub_print_r(t," ")
print("}")
else
sub_print_r(t," ")
end
print()
end
--- Personal Variables
DL2_URL="http://192.168.1.133/dlx/download/live" ---If guest user doesn't have rights to view live data, you need to add user & password
TempCollectorIDX=188
TempBoilerTopIDX=189
TempBoilerBottomIDX=190
CurrentPumpSpeedIDX=191
TotalPumpTimeIDX=192
JSON = (loadfile "/home/pi/domoticz/scripts/lua/json.lua")()
print("========================================================================================================")
print ("Getting Resol DL2 Data");
print("========================================================================================================")
local dl2_data_get=assert(io.popen('curl '..DL2_URL..''))
local dl2_data = dl2_data_get:read('*all')
dl2_data_get:close()
print ("Decoding JSON Resol DL2 Data to Lua Table");
local lua_value = JSON:decode(dl2_data)
--- To show all the records from the table in the log, uncomment next row. Used to determine the values you need.
--- print_r (lua_value)
print ("Getting interesting Values");
TempCollector = lua_value.headersets[1].packets[1].field_values[1].value
TempBoilerTop = lua_value.headersets[1].packets[1].field_values[3].value
TempBoilerBottom = lua_value.headersets[1].packets[1].field_values[2].value
CurrentPumpSpeed = lua_value.headersets[1].packets[1].field_values[5].value
TotalPumpTime = lua_value.headersets[1].packets[1].field_values[7].value
print("TempCollector=" .. TempCollector)
print("TempBoilerTop=" .. TempBoilerTop)
print("TempBoilerBottom=" .. TempBoilerBottom)
print("CurrentPumpSpeed=" .. CurrentPumpSpeed)
print("TotalPumpTime=" .. TotalPumpTime)
commandArray[0]={['UpdateDevice']=''..TempCollectorIDX..'|0|'..TempCollector..''}
commandArray[1]={['UpdateDevice']=''..TempBoilerTopIDX..'|0|'..TempBoilerTop..''}
commandArray[2]={['UpdateDevice']=''..TempBoilerBottomIDX..'|0|'..TempBoilerBottom..''}
commandArray[3]={['UpdateDevice']=''..CurrentPumpSpeedIDX..'|0|'..CurrentPumpSpeed..''}
commandArray[4]={['UpdateDevice']=''..TotalPumpTimeIDX..'|0|'..TotalPumpTime..''}
return commandArray