Foddy / node-red-contrib-huemagic

Philips Hue node to control bridges, lights, groups, motion sensors, temperature sensors and Lux sensors using Node-RED.
https://flows.nodered.org/node/node-red-contrib-huemagic
Apache License 2.0
201 stars 67 forks source link

Hue Group node not working after upgrade to V4.2.2 #400

Open SierraLimaOscar opened 1 year ago

SierraLimaOscar commented 1 year ago

Describe the bug The Hue Group node is reporting the following: "The group in not yet available. Please wait until HueMagic has established a connection with the bridge or check whether the resource ID in the configuration is valid." This is despite the groups being discovered and selected correctly in the node settings. Using the same hue configuration I can make it work using the Hue Light Node instead.

Flow to Reproduce

[
    {
        "id": "284042fde2ef098b",
        "type": "tab",
        "label": "Tmp_hue",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "3c0304cb38ea2063",
        "type": "hue-group",
        "z": "284042fde2ef098b",
        "name": "Dnevna",
        "bridge": "8b1f4a6039e3e2d1",
        "groupid": "0e9bef43-554b-4f9c-90e8-b81e30def65c",
        "skipevents": false,
        "initevents": false,
        "x": 660,
        "y": 480,
        "wires": [
            [
                "da136c4146216839"
            ]
        ]
    },
    {
        "id": "2488419e9ebd11c3",
        "type": "inject",
        "z": "284042fde2ef098b",
        "name": "ON",
        "props": [
            {
                "p": "payload",
                "v": "true",
                "vt": "bool"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 470,
        "y": 460,
        "wires": [
            [
                "3c0304cb38ea2063"
            ]
        ]
    },
    {
        "id": "ec1aa162e1034d05",
        "type": "inject",
        "z": "284042fde2ef098b",
        "name": "OFF",
        "props": [
            {
                "p": "payload",
                "v": "false",
                "vt": "bool"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 470,
        "y": 500,
        "wires": [
            [
                "3c0304cb38ea2063"
            ]
        ]
    },
    {
        "id": "da136c4146216839",
        "type": "debug",
        "z": "284042fde2ef098b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 480,
        "wires": []
    },
    {
        "id": "8b1f4a6039e3e2d1",
        "type": "hue-bridge",
        "name": "Dnevna Bridge 1",
        "bridge": "192.168.0.135",
        "key": "<hidden>",
        "worker": "10",
        "autoupdates": true,
        "disableupdates": false
    }
]

Expected behavior To switch a specific group on or off

Screenshots If applicable, add screenshots to help explain your problem.

Please complete the following information:

Additional context Add any other context about the problem here.

hurenkam commented 1 year ago

For some time, i have had this issue intermittently, not often enough to be a problem. However, since this week, it has turned into a blocking issue. It seems that my node-red/huemagic setup has not changed, so whatever happened, that was not the (only) cause.

Perhaps the firmware of the bridge was upgraded recently? I don't know how to check that, but my current bridge details are:

I do have a rather large setup (30+ lights, 10+ remotes, 10+ sensors), and have added recently some devices as part of a beta test (I'm in the hue beta community), so it could be that the bridge is now reporting more events, or maybe reporting something unexpected?

Checking my podman log (I'm running a nodered/node-red docker image), i notice the following error that might provide a clue: 29 Sep 14:39:12 - [info] [hue-bridge:Attic Hue V2] Initializing the bridge (192.168.1.41)… 29 Sep 14:39:12 - [info] [hue-bridge:Attic Hue V2] Connected to bridge 29 Sep 14:39:13 - [info] [hue-bridge:Attic Hue V2] Processing bridge resources… 29 Sep 14:39:13 - [info] [hue-bridge:Attic Hue V2] TypeError: Cannot read property 'owner' of undefined

Running node-red manually from a local ubuntu install lists a bit more detail: 2 Oct 16:08:54 - [info] [hue-bridge:Attic Hue V2] TypeError: Cannot read property 'owner' of undefined at API.fullResource (/home/hurenkam/.node-red/node_modules/node-red-contrib-huemagic/huemagic/utils/api.js:178:14) at API.fullResource (/home/hurenkam/.node-red/node_modules/node-red-contrib-huemagic/huemagic/utils/api.js:180:25) at /home/hurenkam/.node-red/node_modules/node-red-contrib-huemagic/huemagic/utils/api.js:237:30 at Array.forEach () at /home/hurenkam/.node-red/node_modules/node-red-contrib-huemagic/huemagic/utils/api.js:234:14 at new Promise () at API.processResources (/home/hurenkam/.node-red/node_modules/node-red-contrib-huemagic/huemagic/utils/api.js:214:10) at /home/hurenkam/.node-red/node_modules/node-red-contrib-huemagic/huemagic/hue-bridge-config.js:85:16 at processTicksAndRejections (internal/process/task_queues.js:95:5)

api.js@173 onwards reads:

173        this.fullResource = function(resource, allResources = {})
174        {
175                const scope = this;
176                var fullResource = Object.assign({}, resource);
177
178                if(resource["owner"])

It appears that resource is undefined here.

hurenkam commented 1 year ago

Hmmm, it seems there are 2 different issues at hand here. On the bridge (v2.0) where i have abovementioned problem, i can also no longer access light status through node-red. I have another bridge however (a v2.1 with only a few lights connected), and that does show the "groups not yet available" message, but does not show the TypeError in the logging, and retrieving light status is still working fine just like with OP.

Using curl to access lights or sensors works fine, and also event reporting using curl seems fine for both bridges. Other apps (Hue app & iConnectHue) also seem to work fine.

FredBlo commented 1 year ago

Fyi, I published a pull request #409 which, in addition to fixing the problems mentioned here, also improves the way the bridge overload is handled (following +/- recent changes made to the HUE bridge at this level, aka Error 429)... So if you want to give a try, you can using this one too (installable form FredBlo fork npm install git+https://github.com/fredblo/node-red-contrib-huemagic.git :-) )

brian-gates commented 1 year ago

For posterity, node-red-contrib-huemagic-fork seems the correct way to install this, now.

image