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.

Deconz REST API
#1
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?
BR
Kai-Roger
Reply
#2
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)
Reply
#3
(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.
BR
Kai-Roger
Reply
#4
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)
BR
Kai-Roger
Reply
#5
Use this:
Code:
body = require('json').encode({
  lift = event.getvalue()
})
Reply
#6
(20.04.2021, 06:24)admin Wrote: Use this:
Code:
body = require('json').encode({
  lift = event.getvalue()
})

Excellent Smile
BR
Kai-Roger
Reply


Forum Jump: