Logic Machine Forum
Deconz REST API - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Deconz REST API (/showthread.php?tid=3306)



Deconz REST API - Kai-Roger - 18.04.2021

Hi.

I have successfully managed to controll Ikea blinds with REST API sent to Deconz.

I have tested this in the "Postman REST client" i google Chrome, and i sent the following:

192.168.1.80:40850/api/8EBFA5778F/lights/2/state/
PUT
{ "lift": 50 }

When "putting" these lines the blinds roll down to 50%
How do i implement these 3 lines in a script in LM?


RE: Deconz REST API - admin - 19.04.2021

Try this:
Code:
http = require('socket.http')
ltn12 = require('ltn12')

body = '{"lift":50}'

res, code = http.request({
  url = '192.168.1.80:40850/api/8EBFA5778F/lights/2/state/',
  method = 'PUT',
  headers = {
    ['Content-Length'] = #body,
  },
  source = ltn12.source.string(body)
})

log(res, code)



RE: Deconz REST API - Kai-Roger - 19.04.2021

(19.04.2021, 06:31)admin Wrote: Try this:
Code:
http = require('socket.http')
ltn12 = require('ltn12')

body = '{"lift":50}'

res, code = http.request({
  url = '192.168.1.80:40850/api/8EBFA5778F/lights/2/state/',
  method = 'PUT',
  headers = {
    ['Content-Length'] = #body,
  },
  source = ltn12.source.string(body)
})

log(res, code)

Excellent Smile Thanks. I had to put in http:// in front of the url, but else it worked perfectly.


RE: Deconz REST API - Kai-Roger - 20.04.2021

Hi again.

I tried to use a variable (Percent) inside the Json expression in the "body". This does not work. Any tips on how to do this?


Code:
Percent    = event.getvalue    ()

http = require('socket.http')
ltn12 = require('ltn12')

--body = '{"lift":100}'
body = '{"lift":Percent}'


res, code = http.request({
  url = 'http://192.168.1.80:40850/api/8EBFA5778F/lights/2/state/',
  method = 'PUT',
  headers = {
    ['Content-Length'] = #body,
  },
  source = ltn12.source.string(body)
})

log(res, code)



RE: Deconz REST API - admin - 20.04.2021

Use this:
Code:
body = require('json').encode({
  lift = event.getvalue()
})



RE: Deconz REST API - Kai-Roger - 20.04.2021

(20.04.2021, 06:24)admin Wrote: Use this:
Code:
body = require('json').encode({
  lift = event.getvalue()
})

Excellent Smile