neilenns / node-red-contrib-wled2

NodeRed node for controlling WLED
MIT License
19 stars 8 forks source link

Feature request - query current state #79

Closed TheOriginalMrWolf closed 3 years ago

TheOriginalMrWolf commented 3 years ago

Hi again!

Would it be possible to add a function to query current WLED state (ie - expose the getState() in WledDevice).

Thanks!

neilenns commented 3 years ago

Yes, this would be possible. Best thing to do would be a new node that is dedicated to returning the state. Not sure when I'll be able to get to doing this however.

neilenns commented 3 years ago

This can easily be retrieved using the standard web request node in NodeRed. Just make a request to http://ipaddress/json/state and you will get everything back. There's no need for a special node to do this.

TheOriginalMrWolf commented 3 years ago

@danecreekphotography Of course, that's what I do now. However what about the case where someone has many WLEDs - this would significantly & unneccesarily complicate a flow.

I beg you to reconsider - surely something as basic as checking for a parameter in the incoming message to the existing node (say, msg.getState = true) and then simply returning the json already being retrieved by WledDevice/getState() would be trivial for you to implement?

Thanks again for your consideration.

neilenns commented 3 years ago

I still don't understand the value of having the wled2 node return this when you can just as easily use a web request node to do it. Perhaps you can post a picture of the flow you are trying to build to help me understand?

TheOriginalMrWolf commented 3 years ago

I have 16 WLED instances. I'm using node red to synchronise these with HomeKit. Users can use either HomeKit or the WLED app / web page to control the LEDS. This means I need to synchronise from HK -> WLED & WLED -> HK.

Would be great to minimise the number of nodes representing each entity.

Thanks.

neilenns commented 3 years ago

That's still doable with just a single web request node, with a switch or function node in front to select which one to retrieve the data for.

The goal of this project was to offer an easy UI for UI-based configuration. For what you are trying to do something like switch/function/web request nodes would work.

daredoes commented 3 years ago

@TheOriginalMrWolf Here is a set of Node-Red nodes using the default nodes to get the state. Hope it helps!

image

[
    {
        "id": "772b3bf4.9e5b24",
        "type": "debug",
        "z": "5f9c24b3.699b6c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1570,
        "y": 500,
        "wires": []
    },
    {
        "id": "263ba1fb.4c7a5e",
        "type": "www-request",
        "z": "5f9c24b3.699b6c",
        "name": "Get WLED State",
        "method": "GET",
        "ret": "obj",
        "url": "",
        "follow-redirects": true,
        "persistent-http": true,
        "tls": "",
        "x": 1420,
        "y": 480,
        "wires": [
            [
                "772b3bf4.9e5b24"
            ]
        ]
    },
    {
        "id": "57fad85d.714b28",
        "type": "function",
        "z": "5f9c24b3.699b6c",
        "name": "Set URL based on payload",
        "func": "msg.url = msg.payload + '/json/state'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1240,
        "y": 520,
        "wires": [
            [
                "263ba1fb.4c7a5e"
            ]
        ]
    },
    {
        "id": "2a1ce366.5e301c",
        "type": "switch",
        "z": "5f9c24b3.699b6c",
        "name": "Set Output based on IP Address",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "192.168.1.37",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 990,
        "y": 540,
        "wires": [
            [
                "57fad85d.714b28"
            ]
        ]
    },
    {
        "id": "443baa3e.11d474",
        "type": "function",
        "z": "5f9c24b3.699b6c",
        "name": "Set payload to URL base",
        "func": "msg.payload = 'http://192.168.1.37'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 830,
        "y": 480,
        "wires": [
            [
                "2a1ce366.5e301c"
            ]
        ]
    },
    {
        "id": "b6bc1667.bdf3e8",
        "type": "inject",
        "z": "5f9c24b3.699b6c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 780,
        "y": 420,
        "wires": [
            [
                "443baa3e.11d474"
            ]
        ]
    }
]