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

"No light Id defined. Please check the docs." even if a ID is supplied #300

Open oxivanisher opened 2 years ago

oxivanisher commented 2 years ago

I get the "No light Id defined. Please check the docs." error for my hue lights since the newest version. I use the node in "universal mode" and tried many different things as topic, but nothing works. I think there is a error in this line: https://github.com/Foddy/node-red-contrib-huemagic/blob/7a0d17d7d0f9924e1ef3b92b81393722c68edfec/huemagic/hue-light.js#L124 As far as I can see, the bridge tests for either id or deviceId (the documentation does not really specify which ID is required as topic). But it does not work with both for me.

This is one of my lights status output:

[..]
id: "4635741f-c8a7-4b88-aa82-f701e187132c"
idV1: "/lights/3"
uniqueId: "ba813788-0946-44bd-992f-348103d528a7-4635741f-c8a7-4b88-aa82-f701e187132c"
deviceId: "ba813788-0946-44bd-992f-348103d528a7"
name: "LivingColors 1"
[..]
floriandrott commented 2 years ago

I have the same issue with the universal node. With deviceId it works better as with id but fails more than 50%.

andreas-knx commented 2 years ago

The problem seems to be related to this check: bridge.validResourceID.test(msg.topic) === true due to the following RegEx check: https://github.com/Foddy/node-red-contrib-huemagic/blob/7a0d17d7d0f9924e1ef3b92b81393722c68edfec/huemagic/hue-bridge-config.js#L39

If I remove the check, it is working flawlessly if I pass the deviceId in msg.topic

bland328 commented 2 years ago

Just stopping in to say that I'm also running into this problem, and haven't yet gotten it work even once with either deviceId or id passed as msg.topic.

Edit: I tried disabling line 39 as suggested by @andreas-knx above, and it did get rid of the error message, but didn't make things work any better. I also manually tested that regex statement against my deviceId, and unsurprisingly, it did work properly.

ideaweb commented 2 years ago

I have the same problem. ;-)

No idea what the line is doing, but i guess removing the var breaks javascript when accessing like

bridge.validResourceID.test()

Thats why i replaced the line with the followoing common regex and its working for me:

this.validResourceID = /[a-zA-Z0-9]/gi;

But of course, no idea if this breaks something else (e.g. for non universal mode).

Btw. in recent version id was accepted, which was much easier to handle than deviceid.

andreas-knx commented 2 years ago

Edit: I tried disabling line 39 as suggested by @andreas-knx above, and it did get rid of the error message, but didn't make things work any better. I also manually tested that regex statement against my deviceId, and unsurprisingly, it did work properly.

Hello @bland328 , by disabling the check I meant removing this comparison: bridge.validResourceID.test(msg.topic) === true