Page 1 of 1

LUA Script Data from ext. Rest not usable

Posted: Thursday 19 October 2017 11:18
by mrox
Hi,

i have a really strange problem. I dont know if im right in LUA or Blocky board, but lets start. I have the following LUA script, that gets me data every minute from a REST:

Code: Select all

commandArray = {}
now=os.date("*t")

-- NB : every 5 minutes only, if u prefer every 2 min or even every 1 min
--      change the 5 below
if now.min % 1 == 0 then
   local stringVorlauf = assert(io.popen("curl -s http://10.168.2.60:8088/rest/devices/Vorlauf/attributes/Temp/value" , 'r'))
   local vorlauf = stringVorlauf:read('*all')
   
   local stringKollektor = assert(io.popen("curl -s http://10.168.2.60:8088/rest/devices/Kollektor/attributes/Temp/value" , 'r'))
   local kollektor = stringKollektor:read('*all')

   print("Pool Wasser: "..vorlauf)
   print("Pool Kollektor: "..kollektor)
   
   commandArray[1] = {['UpdateDevice'] = 18 .. '|0|' .. vorlauf}
   commandArray[2] = {['UpdateDevice'] = 19 .. '|0|' .. kollektor}
   
end
return commandArray
This is working fine, and i can see in the logfile the following entrys:

Code: Select all

2017-10-19 11:16:53.346 EventSystem: Script event triggered: Pool2
2017-10-19 11:16:55.108 LUA: Pool Wasser: 10.5
2017-10-19 11:16:55.108 LUA: Pool Kollektor: 10.5
When im using Blocky with these values, to say: If Temperature is higher then X set Y = ON, it will not work. If im using the temperature i get from Weather Underground it will work. So i expect that my LUA script is the problem. Do you guys have some idea?

Re: LUA Script Data from ext. Rest not usable

Posted: Friday 20 October 2017 15:15
by SweetPants
Can you try:

local cmd_vorlauf = string.format("%d|0|%.2f", 18, vorlauf)
local cmd_kollektor = string.format("%d|0|%.2f", 19, kollektor)

commandArray[1] = {['UpdateDevice'] = cmd_vorlauf}
commandArray[2] = {['UpdateDevice'] = cmd_kollektor}

Re: LUA Script Data from ext. Rest not usable

Posted: Saturday 21 October 2017 21:38
by mrox
Many thanks! I understand now what was wrong. Thank you very much!

Re: LUA Script Data from ext. Rest not usable

Posted: Sunday 22 October 2017 14:07
by SweetPants
mrox wrote: Saturday 21 October 2017 21:38 Many thanks! I understand now what was wrong. Thank you very much!
Your welcome, can you close/mark solved this topic?