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.

Curl to Lua -- govee led
#1
Dear, as I am a novice in scripting. Anyone that can help me send a Put request for my govee led stip.

curl --location --request PUT 'https://developer-api.govee.com/v1/devices/control' --header 'Govee-API-Key: 0af6b18b-0303-4c87-b68a-xxxxxxxxx' --header 'Content-Type: application/json' --data-raw '{"device": "FF:AA:A4:C1:xx:xx:xx:xx","model": "H6199","cmd": {"name": "turn", "value": "off"}}'

Thanks
Reply
#2
Govee api reference sample request :

Request URL: https://developer-api.govee.com/v1/devices/control
Request Method: PUT
Request Header:
Content-Type : application/json
Govee-API-Key : 00000000-729c-4b82-b536-000000000
Request body
{
"device": "34:20:03:15:82:ae",
"model": "H6089",
"cmd": {
"name": "turn",
"value": "on"
}
}
Reply
#3
Code:
json = require('json')
http = require('socket.http')
ltn12 = require('ltn12')

url = 'https://developer-api.govee.com/v1/devices/control'
key = '00000000-729c-4b82-b536-000000000'

body = json.encode({
  device = '34:20:03:15:82:ae',
  model = 'H6089',
  cmd = {
    name = 'turn',
    value = 'on'
  }
})

resp = {}

res, code = http.request({
  url = url,
  method = 'PUT',
  headers = {
    ['Content-Type']  = 'application/json',
    ['Content-Length'] = #body,
    ['Govee-API-Key'] = key,
  },
  source = ltn12.source.string(body),
  sink = ltn12.sink.table(resp),
})

log(res, code, resp)
Reply
#4
(19.04.2022, 07:02)admin Wrote:
Code:
json = require('json')
http = require('socket.http')
ltn12 = require('ltn12')

url = 'https://developer-api.govee.com/v1/devices/control'
key = '00000000-729c-4b82-b536-000000000'

body = json.encode({
  device = '34:20:03:15:82:ae',
  model = 'H6089',
  cmd = {
    name = 'turn',
    value = 'on'
  }
})

resp = {}

res, code = http.request({
  url = url,
  method = 'PUT',
  headers = {
    ['Content-Type']  = 'application/json',
    ['Content-Length'] = #body,
    ['Govee-API-Key'] = key,
  },
  source = ltn12.source.string(body),
  sink = ltn12.sink.table(resp),
})

log(res, code, resp)

bad request as answer:
* arg: 1
* number: 1
* arg: 2
* number: 400
* arg: 3
* table:
[1]
* string: <html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
</body>
</html>
Reply
#5
Which firmware version do you have?
Reply
#6
(22.04.2022, 14:37)admin Wrote: Which firmware version do you have?

I updated to latest version and then it works perfect. Thank you very much.
Reply


Forum Jump: