node-red-contrib-huemagic
node-red-contrib-huemagic copied to clipboard
HueMagic: Connection to bridge lost. Trying to reconnect again in 30 seconds… Event { type: 'error', message: undefined }
Describe the bug The Node disconnects from the Hue bridge with the error HueMagic: Connection to bridge lost. Trying to reconnect again in 30 seconds… Event { type: 'error', message: undefined } After this all nodes stop to work.
Expected behavior Just continue working. This was never a problem in previous versions.
Screenshots If applicable, add screenshots to help explain your problem.
Please complete the following information:
- Node-RED version: 2.2.2
- NodeJS version: 12
- Device running Node-RED: Raspberry pi 4
Additional context Hue Magic version 4.2.2
After I created the bug I realised there is also another error message in the logs: HueMagic: Connection to bridge lost. Trying to reconnect again in 30 seconds… Event { type: 'error', message: 'read ECONNRESET' }
@maconic install the philipshue-events contrib to get more information from the bridge
Since today i have the same issue but without the connection lost. But the initialisation seams to be broken:
11 Jun 17:00:11 - [info] [hue-bridge:Philips hue] Initializing the bridge (192.168.1.28)… 11 Jun 17:00:11 - [info] [hue-bridge:Philips hue] Connected to bridge 11 Jun 17:00:12 - [info] [hue-bridge:Philips hue] Processing bridge resources… 11 Jun 17:00:12 - [info] [hue-bridge:Philips hue] TypeError: Cannot read property 'owner' of undefined 11 Jun 17:00:42 - [info] [hue-bridge:Philips hue] Initializing the bridge (192.168.1.28)… 11 Jun 17:00:42 - [info] [hue-bridge:Philips hue] Connected to bridge 11 Jun 17:00:42 - [info] [hue-bridge:Philips hue] Processing bridge resources… 11 Jun 17:00:42 - [info] [hue-bridge:Philips hue] TypeError: Cannot read property 'owner' of undefined 11 Jun 17:01:12 - [info] [hue-bridge:Philips hue] Initializing the bridge (192.168.1.28)… 11 Jun 17:01:13 - [info] [hue-bridge:Philips hue] Connected to bridge 11 Jun 17:01:13 - [info] [hue-bridge:Philips hue] Processing bridge resources… 11 Jun 17:01:13 - [info] [hue-bridge:Philips hue] TypeError: Cannot read property 'owner' of undefined
Any ideas?
@AleksCee did you got a bridge update? A lot of problems are related that HUE is moving from API V1 to V2. It's an Bridge Update process replacing the old API. HueMagic is using some V1 resources when I understand it correct.
@andesse I update the bridge automatic at 3am every day. But I can't see if was updated today.
I have found out by debugging the code where the error is happens an fixed with this:
I add the if(resource){ } block all over the resource-property-checker - in my case it's seams that the part allResources[fullResource["owner"]["rid"]] is undefined at this time.
With this patch the bridge is connected and seams to work - but I' don't know why the error is occurs - perhaps a ordering/sort problem? Seam that the allResources object is total empty at this time if the error occurs.
this.fullResource = function(resource, allResources = {})
{
const scope = this;
var fullResource = Object.assign({}, resource);
if(resource){
if(resource["owner"])
{
fullResource = scope.fullResource(allResources[fullResource["owner"]["rid"]], allResources);
}
else if(resource["type"] === "device" || resource["type"] === "room" || resource["type"] === "zone" || resource["type"] === "bridge_home")
{
// RESOLVE SERVICES
var allServices = {};
for (var i = resource["services"].length - 1; i >= 0; i--)
{
const targetService = resource["services"][i];
const targetType = targetService["rtype"];
const targetID = targetService["rid"];
if(!allServices[targetType]) { allServices[targetType] = {}; }
allServices[targetType][targetID] = Object.assign({}, allResources[targetID]);
}
// REPLACE SERVICES
fullResource["services"] = allServices;
}
}
return fullResource;
}
@AleksCee i recommend to switch to http requests and not using this contrib. There are several comments in here on other bug reports. There is also an example how to do it.
@andesse I figure out another behaviour - it's seams that there is a Group with a reverence on action breathe an v1-group-id 16 but if I request the groups with the v1-api there is no group 16... ;) oh man! what's happens?
@AleksCee i think you need the rid for this, cause breath is connected to the service and not the group Id. Try this
@andesse sorry, I did not understand. but with the "patch" of my if-block the HueMagic seams to work. But what did you mean with the http-request? Is your solution to deinstall HueMagic and do all with native http-request or did I misunderstand you?
@AleksCee yes exactly. Here is an example
https://github.com/Foddy/node-red-contrib-huemagic/issues/353
It works so flawless to talk directly to api v2 and it also feels faster. It's just some effort to set it up, but it needs no maintenance and you're not relying on a contrib
Same issue, it's driving my wife crazy since all my dimmer automations have been built with this contrib, so a lot of the time we are unable to use our lights... I think I will plug them to Hue directly in the meantime but it means all my complex flows will be unusable...
Anyone has an alternative? I understand that I could do it with http request (if I had several hours to spare) but how would I handle incoming traffic for button press events for example?
this.fullResource = function(resource, allResources = {}) { const scope = this; var fullResource = Object.assign({}, resource); if(resource){ if(resource["owner"]) { fullResource = scope.fullResource(allResources[fullResource["owner"]["rid"]], allResources); } else if(resource["type"] === "device" || resource["type"] === "room" || resource["type"] === "zone" || resource["type"] === "bridge_home") { // RESOLVE SERVICES var allServices = {};
for (var i = resource["services"].length - 1; i >= 0; i--) { const targetService = resource["services"][i]; const targetType = targetService["rtype"]; const targetID = targetService["rid"]; if(!allServices[targetType]) { allServices[targetType] = {}; } allServices[targetType][targetID] = Object.assign({}, allResources[targetID]); } // REPLACE SERVICES fullResource["services"] = allServices; } } return fullResource; }
Does this fix work? In what file should I implement this line of code?
@andesse No offense but I’m not giving any personal info to a stranger on the internet. I believe that any help you can provide on Whats’app can be provided on github
@andesse No offense but I’m not giving any personal info to a stranger on the internet. I believe that any help you can provide on Whats’app can be provided on github
https://github.com/Foddy/node-red-contrib-huemagic/issues/353
Stieger81 has his http request system running now.
I managed to find a way to solve this myself but thanks.
For me, the best fix was to use the "hue_event" event built by the base HA Hue integration.
In nodered, you can create an event-all node to listen only to "hue_event" type events and you can use your different devices id as a switch to configure your flows as you would with Hue Magic.
Basically you would need :
- A first switch splitting your hue_event payload for each of your control devices (device_id)
- A second switch that differentiates between the kind of button pressed (called subtype in hue_event.event)
- A third switch to differentiate between long and short press (type)
@Faskill thats exactly what I am doing for a couple of weeks now :)
Additional http request to the bridge to trigger scenes etc.
@Faskill
Here my repository for https HUE API V2. It's just a flow with everything you need. https://github.com/andesse/node-red-hue-api.v2-flows
@andesse I’m loving that "POOPOO" scene
@Faskill lol, I am having a hue button next to the toilet and when you press it, it turns on the fan and let the light flash pink for 3 seconds. That's what the scene is for.
The other scene names are related to Nanoleaf scene names. I have matching colors for the hue lamps as well