Logic Machine Forum
Curl to Lua -- govee led - 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: Curl to Lua -- govee led (/showthread.php?tid=4001)



Curl to Lua -- govee led - Keitz - 18.04.2022

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


RE: Curl to Lua -- govee led - Keitz - 18.04.2022

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"
}
}


RE: Curl to Lua -- govee led - admin - 19.04.2022

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)



RE: Curl to Lua -- govee led - Keitz - 22.04.2022

(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>


RE: Curl to Lua -- govee led - admin - 22.04.2022

Which firmware version do you have?


RE: Curl to Lua -- govee led - Keitz - 23.04.2022

(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.