21.05.2024, 07:24
Example for brightness control.
Attach an event script to 0..100% scale object. Change WLED_IP to your WLED device IP address.
Attach an event script to 0..100% scale object. Change WLED_IP to your WLED device IP address.
Code:
http = require('socket.http')
json = require('json')
ltn12 = require('ltn12')
url = 'http://WLED_IP/json/state'
value = event.getvalue()
data = json.encode({
on = value > 0,
bri = math.round(value * 2.55),
})
res, code = http.request({
url = url,
method = 'POST',
headers = {
['content-type'] = 'application/json',
['content-length'] = #data,
},
source = ltn12.source.string(data),
})
log(res, code)