This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

JSON items into groups
#1
Hi there,

I'm working with Airzone local API, and I need to write every item into LogicMachine group objects.

This is my script:

Code:
require 'ltn12'
require 'socket.http'
json = require("json")

local request_url = "http://192.168.1.111:3000/api/v1/hvac?systemid=01&zoneid=15"
local response_body = {}

local body, code, hdrs, stat = socket.http.request
  {
    url = request_url;
    sink = ltn12.sink.table(response_body);
  }

log (response_body)
 
And this is the response I get:

Code:
* table:
[1]
  * string: {
    "data":    [{
            "systemID":    1,
            "zoneID":    15,
            "name":    "ZONA 15",
            "thermos_type":    2,
            "thermos_firmware":    "4.53",
            "thermos_radio":    0,
            "on":    1,
            "double_sp":    0,
            "coolsetpoint":    22,
            "coolmaxtemp":    30,
            "coolmintemp":    15,
            "heatsetpoint":    22,
            "heatmaxtemp":    30,
            "heatmintemp":    15,
            "maxTemp":    30,
            "minTemp":    15,
            "setpoint":    22,
            "roomTemp":    22.9,
            "sleep":    0,
            "temp_step":    0.5,
            "mode":    3,
            "speed":    0,
            "coldStage":    2,
            "heatStage":    2,
            "coldStages":    2,
            "heatStages":    2,
            "humidity":    22,
            "units":    0,
            "errors":    [],
            "air_demand":    0,
            "floor_demand":    0,
            "cold_demand":    0,
            "heat_demand":    0,
            "heatangle":    0,
            "coldangle":    0,
            "master_zoneID":    15,
            "eco_adapt":    "off",
            "antifreeze":    0
        }]
}

I'm a newbie at json stuff. Please, can you help me with writing every item (systemID, zoneID, name, etc) into LogicMachine group objects? Thanks in advance!
Reply
#2
Hi alexll

Here is a script

Code:
require('socket.http')
require('json')

url = 'http://192.168.1.111:3000/api/v1/hvac?systemid=01&zoneid=15'
response = socket.http.request(url)

--log (response)

decoded = json.pdecode(response)

--log(decoded)

status = decoded.data[1]

grp.checkwrite('50/1/4', status.systemID)
grp.checkwrite('50/1/5', status.zoneID)
grp.checkwrite('50/1/6', status.name)
Reply
#3
(Yesterday, 07:58)RomansP Wrote: Hi alexll

Here is a script

Code:
require('socket.http')
require('json')

url = 'http://192.168.1.111:3000/api/v1/hvac?systemid=01&zoneid=15'
response = socket.http.request(url)

--log (response)

decoded = json.pdecode(response)

--log(decoded)

status = decoded.data[1]

grp.checkwrite('50/1/4', status.systemID)
grp.checkwrite('50/1/5', status.zoneID)
grp.checkwrite('50/1/6', status.name)

Great! Thank you so much!   Smile
Reply
#4
Should it not be status = decoded[1].data ?
Reply
#5
(9 hours ago)Erwin van der Zwart Wrote: Should it not be status = decoded[1].data ?

I don't know, but I have tried it and it works flawlessly.
Reply


Forum Jump: