Posts: 3
Threads: 1
Joined: Nov 2017
Reputation:
0
Hi,
Has anyone done a WLED integration? Tried searching the forums (and google), without luck. My goal is to use KNX+ LM visualization to control WLED (on/off, dim, color, effects).
I've also tried looking at other json scripts, but its quite difficult to understand with zero lua scripting knowledge...
The WLED page on json isn't very helpful (
https://kno.wled.ge/interfaces/json-api/ )
WLED also support MQTT (
https://kno.wled.ge/interfaces/mqtt/ ), but that was even more difficult to understand
--Dan
Posts: 8072
Threads: 43
Joined: Jun 2015
Reputation:
471
Example for brightness control.
Attach an event script to 0..100% scale object. Change WLED_IP to your WLED device IP address.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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 )
Posts: 60
Threads: 12
Joined: May 2021
Reputation:
1
(20.05.2024, 20:43) danborge Wrote: Hi,
Has anyone done a WLED integration? Tried searching the forums (and google), without luck. My goal is to use KNX+ LM visualization to control WLED (on/off, dim, color, effects).
I've also tried looking at other json scripts, but its quite difficult to understand with zero lua scripting knowledge...
The WLED page on json isn't very helpful (https://kno.wled.ge/interfaces/json-api/ )
WLED also support MQTT (https://kno.wled.ge/interfaces/mqtt/ ), but that was even more difficult to understand
--Dan
I have developed a pretty good library if you want. It just controls one segment though, but you can adapt it a little to control more than one
Posts: 3
Threads: 1
Joined: Nov 2017
Reputation:
0
21.05.2024, 18:05
(This post was last modified: 21.05.2024, 18:06 by danborge .)
(21.05.2024, 11:37) Andrea Becagli Wrote: (20.05.2024, 20:43) danborge Wrote: Hi,
Has anyone done a WLED integration? Tried searching the forums (and google), without luck. My goal is to use KNX+ LM visualization to control WLED (on/off, dim, color, effects).
I've also tried looking at other json scripts, but its quite difficult to understand with zero lua scripting knowledge...
The WLED page on json isn't very helpful (https://kno.wled.ge/interfaces/json-api/ )
WLED also support MQTT (https://kno.wled.ge/interfaces/mqtt/ ), but that was even more difficult to understand
--Dan
I have developed a pretty good library if you want. It just controls one segment though, but you can adapt it a little to control more than one
Thanks, that would be great
Got one segment on two different ESP32s, so its just what I'm looking for.
(21.05.2024, 07:24) admin Wrote: Example for brightness control.
Attach an event script to 0..100% scale object. Change WLED_IP to your WLED device IP address.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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 )
Thanks, I'll make a script and try this
Posts: 60
Threads: 12
Joined: May 2021
Reputation:
1
22.05.2024, 15:31
(This post was last modified: 22.05.2024, 15:37 by Andrea Becagli .)
There you go, I will attach the library i made. Sorry I am italian so most of the comments are in italian
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
json =
require (
'json' )
http =
require (
'socket.http' )
wled_ctrl = {
defaults = {
debug_mode =
false ,
token =
nil
}
}
function wled_ctrl :
init (
params )
local n =
setmetatable ({}, {
__index =
wled_ctrl })
local k ,
v
n.params =
params
for k ,
v in pairs (
wled_ctrl.defaults )
do
if n.params [
k ] ==
nil then
n.params [
k ] =
v
end
end
return n
end
function wled_ctrl :
basic_post_req (
body_req )
res ,
err =
http.request ({
url =
'http://' ..
self.params.ip.. '/json/state' ,
method =
"POST" ,
body =
body_req ,
headers = {[
"Content-Type" ] =
"text/plain" }
})
return res ,
err
end
function wled_ctrl :
accensione (
valore ,
stato )
body1 =
'{"on":' ..
tostring (
valore )..
'}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"accensione - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
luminosita (
valore ,
stato )
body1 =
'{"bri":' ..
tostring (
math.floor (
valore *
2.55 ))..
'}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"luminosita - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
colore (
valore ,
stato )
hexcolor =
string.format (
"%X" ,
tostring (
valore ))
while hexcolor :
len () <
6 do
hexcolor =
"0" ..
hexcolor
end
log (
hexcolor )
body1 =
'{"seg":[{"col":["' ..
hexcolor.. '"]}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"colore - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
effetto (
valore ,
stato )
body1 =
'{"seg":[{"fx":' ..
tostring (
valore )..
'}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"effetto - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
color_temp (
valore ,
stato )
body1 =
'{"seg":[{"cct":' ..
tostring (
valore )..
'}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"color temp - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
palette (
valore ,
stato )
body1 =
'{"seg":[{"pal":' ..
tostring (
valore )..
'}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"palette - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
stato ()
res ,
err =
self :
basic_post_req (
'{}' )
local info =
json.decode (
res )
if self.params.debug_mode then log (
"Response: " ..
tostring (
res )..
" Error: " ..
tostring (
err ))
end
return {
accensione =
info.state.on ,
luminosita =
info.state.bri ,
colore =
info.state.seg [
1 ].
col [
1 ],
effetto =
info.state.seg [
1 ].
fx ,
palette =
info.state.seg [
1 ].
pal
}
end
Posts: 3
Threads: 1
Joined: Nov 2017
Reputation:
0
(22.05.2024, 15:31) Andrea Becagli Wrote: There you go, I will attach the library i made. Sorry I am italian so most of the comments are in italian
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
json =
require (
'json' )
http =
require (
'socket.http' )
wled_ctrl = {
defaults = {
debug_mode =
false ,
token =
nil
}
}
function wled_ctrl :
init (
params )
local n =
setmetatable ({}, {
__index =
wled_ctrl })
local k ,
v
n.params =
params
for k ,
v in pairs (
wled_ctrl.defaults )
do
if n.params [
k ] ==
nil then
n.params [
k ] =
v
end
end
return n
end
function wled_ctrl :
basic_post_req (
body_req )
res ,
err =
http.request ({
url =
'http://' ..
self.params.ip.. '/json/state' ,
method =
"POST" ,
body =
body_req ,
headers = {[
"Content-Type" ] =
"text/plain" }
})
return res ,
err
end
function wled_ctrl :
accensione (
valore ,
stato )
body1 =
'{"on":' ..
tostring (
valore )..
'}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"accensione - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
luminosita (
valore ,
stato )
body1 =
'{"bri":' ..
tostring (
math.floor (
valore *
2.55 ))..
'}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"luminosita - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
colore (
valore ,
stato )
hexcolor =
string.format (
"%X" ,
tostring (
valore ))
while hexcolor :
len () <
6 do
hexcolor =
"0" ..
hexcolor
end
log (
hexcolor )
body1 =
'{"seg":[{"col":["' ..
hexcolor.. '"]}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"colore - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
effetto (
valore ,
stato )
body1 =
'{"seg":[{"fx":' ..
tostring (
valore )..
'}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"effetto - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
color_temp (
valore ,
stato )
body1 =
'{"seg":[{"cct":' ..
tostring (
valore )..
'}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"color temp - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
palette (
valore ,
stato )
body1 =
'{"seg":[{"pal":' ..
tostring (
valore )..
'}]}'
res ,
err =
self :
basic_post_req (
body1 )
if err ==
200 then grp.write (
stato ,
valore )
end
if self.params.debug_mode and err ~=
200 then log (
"palette - Error: " ..
tostring (
err ))
end
end
function wled_ctrl :
stato ()
res ,
err =
self :
basic_post_req (
'{}' )
local info =
json.decode (
res )
if self.params.debug_mode then log (
"Response: " ..
tostring (
res )..
" Error: " ..
tostring (
err ))
end
return {
accensione =
info.state.on ,
luminosita =
info.state.bri ,
colore =
info.state.seg [
1 ].
col [
1 ],
effetto =
info.state.seg [
1 ].
fx ,
palette =
info.state.seg [
1 ].
pal
}
end Thanks. I'll test this
No problem with the Italian, google translate if its something I dont understand
Posts: 367
Threads: 83
Joined: Jun 2017
Reputation:
8
Hi,
long time ago I used very interesting project with ESP8266 and ws2812 LEDs. It was Tobias Blum's MC lighting project.
Some links I found below.
https://github.com/toblum/McLighting/
https://github.com/FabLab-Luenen/McLighting
https://hackaday.io/project/122568-mc-lighting
https://www.hackster.io/news/mclighting-...b1705a44de
Why I decided to mention it - you can very easy control yours WLED's over WiFi with mobile phone, and main - using your LM/SL/HL and just REST API commands - only one line string commands.
Possible to change WLED effects, colors, On/Off, Dimm etc. I also created color clock - at 7:00 all wleds are green, at night all are red etc
BR,
Alexander