Multiple Buttons / Macros / Segments / JSON

I’ve been working on architectural lighting for my home (wall switches, fixtures) based on pixels for the last couple of years and originally had built a very horse and buggy scene/segment system that I integrated with Tasmota along with Makuna’s NeoPixelBus (tasmota had no support for pixels at all). I discovered the joys of DMX over the holidays and was about to integrate E1.31 support (from ESPPixel’s author) into Tasmota when I ran across WLED.

For my application I want there to always be bullet proof local control if mqtt (or even wifi) isn’t running, while a single button is great most of my switchplates and other widgets have 3 toggle or momentary buttons.

I’ve set up the button support to support 3 buttons with all the flash settings to allow single, double, and long press to invoke macros and send MQTT messages for the buttons themselves (rather than the state of the lights). I was hoping to use the HTTP API to set the state of multiple segments when you press a button (ie: implement a scene on a single or multiple pixel busses). I immediately ran into the problem that segment support via the HTTP GET API only allows you to change the settings of a single segment (the one that’s ‘main’) in a single call; the SS and SV are more about setting up segments than controlling them. The HTTP API parser just scans for the first parameter of a given type so there’s no way you could do multiple segments in a single call. The preset facility doesn’t appear to be able to store (today) presets that affect multiple segments (I couldn’t even make preset 16 do it with 6 segments, probably user error on my part).

With all that background out of the way, here’s what I’m thinking of doing – I’d like a cross check there isn’t some easier way or that I’m crossing the streams wrt some development coming down the pipe. Proposal:

  • Add functionality to read a JSON blob from a SPIFFS file and execute it as a JSON API call; the JSON mechanism appears to be able to set up multiple segments in a single call.
  • Add a JS= to the HTTP API facility that executes a JSON call from a SPIFFS file

With these in place I can upload scenes for multi-segment areas (stairs, cabinets, accent lighting around/under beds) using the SPIFF’s file browser and trigger those scenes with any of the 9 possible button actions.

I have a few places where I use toggle switches to trigger scenes (off the shelf decora switches usually) so I’ll probably make some tweaks to the ‘button’ code to understand stateful switches (in tasmota what I did was make each debounced transition from on–>off or off->on be its own trigger rather than treating it like a button).

I’ll fork/share what I’ve done, but it seems like it might be too specialized to merge generally. My holy grail/long term plan is replacing all my Insteon and z-wave stuff with ESP’s and pixels. I want to set up the system so I can leave in the house and have it not be useless to a naive end user when I eventually move (that’s the local control part of the equation), and that can easily be replaced with dumb mechanical switches for most of the built in stuff if something breaks and there are no spares left.

@bpnine
If you wish i could take a look at the code to help or make things a bit more clear.

Thanks, I would appreciate the sanity check. I’m willing to clean any of this up for public consumption, this WIP is presently just to prove all the bits and pieces can be made to work at all.

Here’s a fork with my 3 button/macro stuff done and working. I haven’t started on the JSON macro thing I proposed above but will do that next unless someone points out its a bad idea :slight_smile:

1 Like

Took a while to find some time but I finished up the idea above and committed to the fork.
Its working well for me: I created a bunch of JSON files on the SPIFFS filesystem with JSON API calls in it to set various scenes, then I used this new JS= parameter I added to the web API to call them via various button presses.

My test spot has a little 3 button controller and I set one button as ‘all segments off’, another as ‘full white on’, and the 3rd as a dim/colorful nightlight (under bed lighting blue and green, over bed lighting red).

One issue is I couldn’t get the segment setup to save to flash using the normal UI, so I set a JSON macro up to run at boot to set up the segments:

{
    "seg": [
    {
        "desc": "All",
        "start": 0,
        "stop": 10,
        "sel": true,
        "rev": false,
        "cln": -1
    },
    {
        "desc": "West bottom",
        "start": 0,
        "stop": 7,
        "sel": false,
        "rev": false,
        "cln": -1
    },
    {
        "desc": "South bottom",
        "start": 7,
        "stop": 35,
        "sel": false,
        "rev": false,
        "cln": -1
    },
    {
        "desc": "East bottom",
        "start": 35,
        "stop": 42,
        "sel": false,
        "rev": false,
        "cln": -1
    },
    {
        "desc": "Top",
        "start": 42,
        "stop": 300,
        "sel": false,
        "rev": false,
        "cln": -1
    }
    ]
}

Here’s an example of the ‘nightlight’ scene:

imp:mbr_bed ev$ cat but2.json 
{
    "on": true,
    "bri": 255,
    "seg": [
    { },
    {
        "desc": "West bottom",
        "fx": 0,
        col: [
            [ 0, 0, 64, 0 ],
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0, 0 ]
        ]
    },
    {
        "desc": "South bottom",
        "fx": 0,
        col: [
            [ 0, 32, 0, 0 ],
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0, 0 ]
        ]
    },
    {
        "desc": "East bottom",
        "fx": 0,
        col: [
            [ 0, 0, 64, 0 ],
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0, 0 ]
        ]
    },
    {
        "desc": "Top",
        "fx": 0,
        col: [
            [ 64, 0, 0, 0 ],
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0, 0 ]
        ]
    }
    ]
}

I ported the logic to the new JSON/SPIFFS system and submitted
pull request 1388 to WLED.

There are some docs on how to configure it and use some scene/preset control tools I wrote to go with it in usersmods/multibutton/README.md (discourse won’t let me post a link to github, so look in the PR).

This is working ‘in production’ (in my home) on several WLED’s alongside HomeAssistant, I use the extra button inputs and modes (single/double/long click) to trigger multiple local scenes and send MQTT messges to HomeAssistant and my ISY994 for more global actions (“turn off everything”, “I’m home, turn on everything”, etc).

I’ve built some custom (mini-d1 based) boards that fit into wall switches with reasonable looking 3d printed switch covers (and Cherry-MX switches) to run this on. If anyone has any questions or comments on the hardware side of this I love talking about this stuff.