Page 1 of 1

Checking a string in DzVents

Posted: Wednesday 01 July 2020 22:40
by Jumper3126
I'm getting a string of data from my airco via domoticz.openURL, which looks like this:

Code: Select all

ret=OK,pow=0,mode=3,adv=,stemp=18.0,shum=0,dt1=25.0,dt2=M,dt3=18.0,dt4=25.0,dt5=25.0,dt7=25.0,dh1=AUTO,dh2=50,dh3=0,dh4=0,dh5=0,dh7=AUTO,dhh=50,b_mode=3,b_stemp=18.0,b_shum=0,alert=255,f_rate=7,f_dir=0,b_f_rate=7,b_f_dir=0,dfr1=5,dfr2=5,dfr3=7,dfr4=5,dfr5=5,dfr6=5,dfr7=5,dfrh=5,dfd1=0,dfd2=0,dfd3=0,dfd4=0,dfd5=0,dfd6=0,dfd7=0,dfdh=0,dmnd_run=0,en_demand=0
How would I go about analyzing this string in DzVents? I would like, for example, to take out the value from pow= or stemp= and use it for an IF command.

Re: Checking a string in DzVents

Posted: Wednesday 01 July 2020 23:27
by waaren
Jumper3126 wrote: Wednesday 01 July 2020 22:40 I'm getting a string of data from my airco via domoticz.openURL
How would I go about analyzing this string in DzVents? I would like, for example, to take out the value from pow= or stemp=
Something like

Code: Select all

local response = 'ret=OK,pow=0,mode=3,adv=,stemp=18.0,shum=0,dt1=25.0,dt2=M,dt3=18.0,dt4=25.0,dt5=25.0,dt7=25.0,dh1=AUTO,dh2=50,dh3=0,dh4=0,dh5=0,dh7=AUTO,dhh=50,b_mode=3,b_stemp=18.0,b_shum=0,alert=255,f_rate=7,f_dir=0,b_f_rate=7,b_f_dir=0,dfr1=5,dfr2=5,dfr3=7,dfr4=5,dfr5=5,dfr6=5,dfr7=5,dfrh=5,dfd1=0,dfd2=0,dfd3=0,dfd4=0,dfd5=0,dfd6=0,dfd7=0,dfdh=0,dmnd_run=0,en_demand=0'

local firstSplit = domoticz.utils.stringSplit(response,',') -- split the response string on comma -> one assignment per row

local results = {}
for _, row in ipairs(firstSplit) do
	local hTable = domoticz.utils.stringSplit(row,'=') -- split every row into a helper table containing a key and a value
 	local key = hTable[1]
	local value = tonumber(hTable[2]) or hTable[2] -- store value as number when possible. If not store as string 
	results[key] = value 
end	

if results.pow < 10 then
	print(results.ret)
	print(results.pow)
	print(results.stemp)
end

Re: Checking a string in DzVents  [Solved]

Posted: Wednesday 01 July 2020 23:43
by Jumper3126
Wow, thank you soo much
You made a week work into 30 minutes :D