Setting up multiple segments on a single strip and controlling them through json api

Hey everyone,

Long time user of Wled on more basic configs but I’m trying to setup a long strip using many segments and running into difficulty getting the segments to respond as I expect

I have set up an ESP8266 with 100 led strip
Using build v0.16.0-alpha “Niji“
I’ve set up 9 segments in the UI
I’ve created a single preset for all 9 for their initial state

This is the general idea

I’m using automations in HomeAssistant to trigger on events, these are then sent to N8N which sends them on to the WLED Json API

For simplicity I can sidestep HA and run the commands through powershell → n8n → WLED

When I send a command to bring up for instance the occupancy leds segment 1 I get back a success true response but the leds don’t change, they stay on the original preset

This is the request I’m sending

[
{
“seg”: [
{
“id”: 1,
“start”: 6,
“stop”: 16,
“grp”: 1,
“spc”: 0,
“of”: 0,
“on”: true,
“frz”: false,
“bri”: 255,
“cct”: 127,
“set”: 0,
“lc”: 1,
“n”: “”,
“col”: [
[
255,
170,
0
],
[
0,
0,
0
],
[
0,
0,
0
]
],
“fx”: 100,
“sx”: 128,
“ix”: 128,
“pal”: 11,
“c1”: 128,
“c2”: 128,
“c3”: 16,
“sel”: true,
“rev”: false,
“mi”: false,
“o1”: false,
“o2”: false,
“o3”: false,
“si”: 0,
“m12”: 1,
“bm”: 0
}
]
}
]

I created this in the wled UI in a preset for just segment 1 then copied it out and deleted that new preset

From what I can see there’s no log to tell what’s going on with the API how can I work out why the command is returning success but actually not working?

If I create a new preset and paste that in with a bit of extra info at the top it works perfectly

Is the global preset causing it to ignore the api commands to change?

I haven’t finished fleshing out the logic yet I have occupancy on and off, solar production in a percentage, and the initial candle

Is this a bug, could it be caused by being on an alpha build?

Cheers
Its a great project

success means just the command is valid. if you only want to change color or fx, there is no need to send full segment update, you can send only what you want to change, for example:

{“seg”:[{“id”:0,“col”:[[0,160,0,0],[0,0,0,0],[0,0,0,0]],“fx”:100}]}

Thanks thats a good change to reduce the complexity of the command

So if the commands valid why would the pattern not change?

Since I can send just changes I’ve reduced the json down to

Occupancy detected

return [{ json: {
seg: [{
“id”: 1,
“col”: [
[
255,
170,
0
],
[
0,
0,
0
],
[
0,
0,
0
]
],
“fx”: 100,
“sx”: 128,
“ix”: 128,
“pal”: 11,
“m12”: 1
}]
}}];

Occupancy cleared

return [{ json: {
seg: [
{
“id”: 1,
“col”: [
[
71,
194,
255
],
[
0,
0,
0
],
[
0,
0,
0
]
],
“fx”: 105,
“sx”: 27,
“ix”: 126,
“pal”: 69,
“m12”: 0
}
]
}}];

Ill test it tomorrow but there’s no real change there just less repeated code

I’ve run the command this morning it accepts it, reports success but nothing on the led strip changes

this is the config from the wled side

Preset code with Apply at boot selected for initial state

{“on”:true,“bri”:128,“transition”:7,“bs”:0,“mainseg”:0,“seg”:[{“id”:0,“start”:0,“stop”:6,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,75,10],[0,0,0],[0,0,0]],“fx”:88,“sx”:96,“ix”:224,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:1,“start”:6,“stop”:16,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[71,194,255],[0,0,0],[0,0,0]],“fx”:105,“sx”:27,“ix”:126,“pal”:69,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:2,“start”:16,“stop”:26,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:128,“cct”:127,“set”:0,“lc”:1,“n”:“Segment 2”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:98,“sx”:129,“ix”:0,“pal”:255,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:3,“start”:26,“stop”:36,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:4,“start”:36,“stop”:53,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:5,“start”:53,“stop”:58,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:6,“start”:58,“stop”:61,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:7,“start”:61,“stop”:64,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:8,“start”:64,“stop”:69,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0},{“id”:9,“start”:69,“stop”:100,“grp”:1,“spc”:0,“of”:0,“on”:true,“frz”:false,“bri”:255,“cct”:127,“set”:0,“lc”:1,“n”:“”,“col”:[[255,170,0],[0,0,0],[0,0,0]],“fx”:0,“sx”:128,“ix”:128,“pal”:0,“c1”:128,“c2”:128,“c3”:16,“sel”:true,“rev”:false,“mi”:false,“o1”:false,“o2”:false,“o3”:false,“si”:0,“m12”:0,“bm”:0}]}

valid != correct. maybe misplaced brackets?

Valid is literally a synonym of correct but I get what you mean, I would’ve hoped the api is returning your packet is correctly formatted and valid rather than you have sent me a packet, especially when there’s no logging or feedback there seems to be no way to troubleshoot?

I created them in wled in a new preset through the UI, and they work there so there’s no missing brackets or invalid anything

I’ve just tested copying the exact code from the presets (before i did the same by extracted just the seg part, now im sending the entire thing) and sending that and it also doesn’t work but if i copy it into a new preset and click to apply it does

i.e.

{
“on”: true,
“bri”: 128,
“transition”: 7,
“bs”: 0,
“mainseg”: 0,
“seg”: [
{
“id”: 1,
“start”: 6,
“stop”: 16,
“grp”: 1,
“spc”: 0,
“of”: 0,
“on”: true,
“frz”: false,
“bri”: 255,
“cct”: 127,
“set”: 0,
“lc”: 1,
“n”: “”,
“col”: [
[
71,
194,
255
],
[
0,
0,
0
],
[
0,
0,
0
]
],
“fx”: 184,
“sx”: 128,
“ix”: 128,
“pal”: 69,
“c1”: 128,
“c2”: 128,
“c3”: 16,
“sel”: true,
“rev”: false,
“mi”: false,
“o1”: false,
“o2”: false,
“o3”: false,
“si”: 0,
“m12”: 0,
“bm”: 0
}
]
}

Ok i think i got it to work ill update the thread when im sure but fingers crossed all good

Ok yep all good now
It was a grok issue and wrong return object in n8n (I used grok at first until i was sick of banging my head against the wall then tried quite awhile prior to asking here)

In n8n i have a webook that takes the message request in from powershell or HA
It then constructs a json object to send with the changes
Then forwards that to the json api for wled

I was using

return [{ json: {
seg: [{
“id”: 1, …

So everything was in a json item

The sending knew it had a body of json to send but wasent set to pull from that json object so it was still sent as constructed

The fix I’ve implemented is just send the content I want without wrapping it and being specific in the body for the json I’ve added

i.e. occupied

return {
seg: [{
“id”: 1,
“col”: [
[255, 170, 0 ],
[ 0, 0, 0 ],
[ 0, 0, 0 ]
],
“fx”: 100,
“sx”: 128,
“ix”: 128,
“pal”: 11,
“m12”: 1
}]
};

Deoccupied

return {
seg: [{
“id”: 1,
“col”: [
[71, 194, 255 ],
[ 0, 0, 0 ],
[ 0, 0, 0 ]
],
“fx”: 105,
“sx”: 27,
“ix”: 126,
“pal”: 69,
“m12”: 0
}]
};

So this is only the changes from the Preset 1 that is applied at boot, ty @dedehai much cleaner

Then the send post is set to this

This is working correctly now tested in powershell and through the HA automations