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
203 stars 68 forks source link

Hue Switch #17

Closed lespatots closed 7 years ago

lespatots commented 7 years ago

I've just installed and tried this:

1) Thanks, fantastic! 2) I think 'Hue Dimmer' coresponds better with the Philips terminology? 3) I had difficulty with installation, I didn't get an upgrade option? The module didn't go in my User modules after an NPM install and produced a couple of WARN messages 4) I get a 'connection error' from the .catch statement even though the setup/config seemed ok? Haven't tried the 'Tap' yet but the other revised nodes for the sensor seem to still be working.

oehm2007 commented 7 years ago

I added a dimmer switch in my flow, but its not working. There is just a constant connection error, and I couldnt get anything out of the node.

Foddy commented 7 years ago

Hm.. thanks for your feedback. I followed the API guidelines but unfortunately I don’t own those devices so I am unable to debug this errors. Instead I am using a combination between Amazon Dash Buttons, Alexa and the motion sensors, but I guess this is another topic...

Can you guys help me out to debug this? Do you get any “native” errors in your Logs when you start / restart Node RED with some of the Hue Tap or Hue Switch nodes preconfigured?

lespatots commented 7 years ago

I’ll do what I can.

"3 Dec 13:16:55 - [info] Stopping flows 3 Dec 13:16:55 - [info] [mqtt-broker:9121a7a4.5939d8] Disconnected from broker: mqtt://192.168.1.111:1883 3 Dec 13:16:55 - [info] [mqtt-broker:a28d846f.f4e72] Disconnected from broker: mqtt://192.168.1.111:1883 3 Dec 13:16:55 - [info] Stopped flows 3 Dec 13:16:55 - [info] Starting flows 3 Dec 13:16:56 - [info] Started flows 3 Dec 13:16:56 - [info] [mqtt-broker:9121a7a4.5939d8] Connected to broker: mqtt://192.168.1.111:1883 3 Dec 13:16:56 - [info] [mqtt-broker:a28d846f.f4e72] Connected to broker: mqtt://192.168.1.111:1883 3 Dec 13:16:59 - [error] [function:Light Store state] TypeError: Cannot read property 'on' of undefined”

Above is the log from a deployment. There last error comes from a node I have taking a light update, and isn’t relevant. The Light Switch node shows ‘waiting’ for about two seconds before it goes into the ‘connection’ error. Perhaps two seconds is a bit short and is this similar to the sensor node where once it’s failed it stays failed?

Anything else, I could send you a switch if that helps?

Regards

Richard

On 3 Dec 2017, at 13:00, Foddy notifications@github.com wrote:

Hm.. thanks for your feedback. I followed the API guidelines but unfortunately I don’t own those devices so I am unable to debug this errors. Instead I am using a combination between Amazon Dash Buttons, Alexa and the motion sensors, but I guess this is another topic...

Can you guys help me out to debug this? Do you get any “native” errors in your Logs when you start / restart Node RED with some of the Hue Tap or Hue Switch nodes preconfigured?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/17#issuecomment-348759267, or mute the thread https://github.com/notifications/unsubscribe-auth/AK2Y3AL5N_7RniKRtI85JJHr6zgLD3D7ks5s8o1igaJpZM4Qy6P8.

lespatots commented 7 years ago

Foddy,

I know little to nothing about JS but this line of code early on in UPDATE STATE looks weird to me

var buttonEvent = context.get('buttonevent') || false;

An or operator used with false surely is pointless? Is there something missing?

Richard

On 3 Dec 2017, at 13:00, Foddy notifications@github.com wrote:

Hm.. thanks for your feedback. I followed the API guidelines but unfortunately I don’t own those devices so I am unable to debug this errors. Instead I am using a combination between Amazon Dash Buttons, Alexa and the motion sensors, but I guess this is another topic...

Can you guys help me out to debug this? Do you get any “native” errors in your Logs when you start / restart Node RED with some of the Hue Tap or Hue Switch nodes preconfigured?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/17#issuecomment-348759267, or mute the thread https://github.com/notifications/unsubscribe-auth/AK2Y3AL5N_7RniKRtI85JJHr6zgLD3D7ks5s8o1igaJpZM4Qy6P8.

Foddy commented 7 years ago

Thanks for that @lespatots!

Unfortunately there is not enough information that could help me out with debugging the Switch node. Could you please update nodered/node_modules/node-red-contrib-huemagic/red/hue-switch.js by adding this code snippet at line 118 right after the catch argument and restart Node RED? This should hopefully give some more information after you use the node (for example with trying to tap on a button on your Hue Switch). Thank you in advance!

scope.error(error);

It should then look like this:

[…]
.catch(error => {
    scope.error(error);
    scope.status({fill: "red", shape: "ring", text: "connection error"});
});

Regarding your second question – you're right, it's something you would call habit or "code style". I use this operator to get the last button code from the registry or to strictly define the variable with the boolean false. Otherwise I get an "undefined" variable on JS which I don't like to check on "if" clauses.

lespatots commented 7 years ago

Foddy

3 Dec 16:44:54 - [error] [hue-switch:TV] TypeError: Cannot read property 'toString' of undefined

Repeats of course!!

On 3 Dec 2017, at 16:05, Foddy notifications@github.com wrote:

Thanks for that @lespatots https://github.com/lespatots!

Unfortunately there is not enough information that could help me out with debugging the Switch node. Could you please update nodered/node_modules/node-red-contrib-huemagic/red/hue-switch.js by adding this code snippet at line 18 right after the catch argument and restart Node RED? This should hopefully give some more information after you use the node (for example with trying to tap on a button on your Hue Switch). Thank you in advance!

scope.error(error);

It should then look like this:

[…] .catch(error => { scope.error(error); scope.status({fill: "red", shape: "ring", text: "connection error"}); }); Regarding your second question – you're right, it's something you would call habit or "code style". I use this operator to get the last button code from the registry or to strictly define the variable with the boolean false. Otherwise I get an "undefined" variable on JS which I don't like to check on "if" clauses.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/17#issuecomment-348780386, or mute the thread https://github.com/notifications/unsubscribe-auth/AK2Y3O6Teoo-mVB7BBtCkxRge1K4DJTLks5s8rjBgaJpZM4Qy6P8.

oehm2007 commented 7 years ago

3 Dec 17:03:15 - [error] [hue-switch:Schalter Schlafzimmer] TypeError: Cannot read property 'toString' of undefined 3 Dec 17:03:18 - [error] [hue-switch:Schalter Schlafzimmer] TypeError: Cannot read property 'toString' of undefined 3 Dec 17:03:21 - [error] [hue-switch:Schalter Schlafzimmer] TypeError: Cannot read property 'toString' of undefined 3 Dec 17:03:24 - [error] [hue-switch:Schalter Schlafzimmer] TypeError: Cannot read property 'toString' of undefined

Foddy commented 7 years ago

Oh okay I guess I found it.... -_-

It's not "sensor.state.buttonevent", it is "sensor.state.buttonEvent". Sorry for that. Just released a fix (1.2.2). Can you confirm that it's working now?

(I should probably buy one for the future)

lespatots commented 7 years ago

Foddy,

I did a quick edit to that line and one other instance I spotted and the quick answer is it is now working. I’ll have to be cleverer in flows as the ‘off’ state (which is probably the last press) is repeating. I suppose the enquiry must return something and the last press would make sense. I’ll upgrade to 1.2.2 just to make sure I got all the changes to Event!!

Thanks for the quick fix, just have to figure out all the possible uses, including battery monitor and use of some actions that aren’t programmed into the bridge v Node-Red actions.

Regards

Richard

On 3 Dec 2017, at 17:04, Foddy notifications@github.com wrote:

Oh okay I guess I found it.... -_-

It's not "sensor.state.buttonevent", it is "sensor.state.buttonEvent". Sorry for that. Just released a fix (1.2.2). Can you confirm that it's working now?

(I should probably buy one for the future)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/17#issuecomment-348788691, or mute the thread https://github.com/notifications/unsubscribe-auth/AK2Y3Gq0X3gGrwUGHxEA_-W9lnN3x08_ks5s8saSgaJpZM4Qy6P8.

oehm2007 commented 7 years ago

Works perfect now in my flow as well. Even the short released and holded function. Just amazin work again. By the way I`m really interested in a decent use of my dashbuttons. Just because you mentioned your use of them. I tried some done packages of github, but actually the results were not satisfying at all. Cheers

lespatots commented 7 years ago

That’s 1.2.2 tested and I see I must have missed an Event somewhere as 1.2.2 only sends the state once until changed. The TAP node is working fine too!!

On 3 Dec 2017, at 17:04, Foddy notifications@github.com wrote:

Oh okay I guess I found it.... -_-

It's not "sensor.state.buttonevent", it is "sensor.state.buttonEvent". Sorry for that. Just released a fix (1.2.2). Can you confirm that it's working now?

(I should probably buy one for the future)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/17#issuecomment-348788691, or mute the thread https://github.com/notifications/unsubscribe-auth/AK2Y3Gq0X3gGrwUGHxEA_-W9lnN3x08_ks5s8saSgaJpZM4Qy6P8.

Foddy commented 7 years ago

Awesome! Thank you for helping me out with this error.

@oehm2007 I really recommend "hacking" Amazon's Dash buttons for some special use cases but not as an Hue Switch / Tap replacement – since it takes some time to find them on your network and run your flows (about 3-7 seconds for me). If you don't care about this latency you could do things like this for example with this awesome node:

example

This flow deactivates the Hue motion sensor for an hour and dims down the lights on my living room, so I can Netflix and chill without being interrupted by bright lights just because I moved a centimeter ;)!

lespatots commented 7 years ago

Foddy,

There is now a huge range of things that can be done because of your switch nodes, beyond the obvious.

1) We can know the last action at every switch and in the case of a power outage put the lights back to what they were. 2) It is now easy to switch lights on multiple bridges from one switch AND distribute switches regardless of worrying about which lights can be controlled. 3) Additional logic can be added into the switch like daylight light level v evening AND a night setting of say Blue 4) We could add audible confirmations to switch actions 5) We can add any Node-Red flow to a button (TV on, lights low, blinds close) 6) Connectivity and battery status can be monitored

I haven’t found a switch that I like more than the Hue Dimmer switch, particularly because it has no wiring, four buttons and double/long press capability. I was waiting for Philips to produce a new switch in a ‘two gang’ version but now I don’t think I need one, ALSO the switch limit per hub is no longer a problem, it had recently been lowered from 12 to 7 because of hub limitations on rules. I have three first gen. round hubs bought with light packs (for free) that can now easily be brought into use if need be.

I think this nodes will be a huge success.

Many thanks once again

On 3 Dec 2017, at 17:52, Foddy notifications@github.com wrote:

Awesome! Thank you for helping me out with this error.

@oehm2007 https://github.com/oehm2007 I really recommend "hacking" Amazon's Dash buttons for some special use cases but not as an Hue Switch / Tap replacement – since it takes some time to find them on your network and run your flows (about 3-7 seconds for me). If you don't care about this latency you could do thinks like this for example with this awesome node https://www.npmjs.com/package/node-red-contrib-amazondash:

https://user-images.githubusercontent.com/5302050/33527518-a7f23292-d852-11e7-854f-b015e162bf1b.png This flow deactivates the Hue motion sensor for an hour and dims down the lights on my living room, so I can Netflix and chill without being interrupted by bright lights just because I moved a centimeter ;)!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Foddy/node-red-contrib-huemagic/issues/17#issuecomment-348795332, or mute the thread https://github.com/notifications/unsubscribe-auth/AK2Y3AVPkEVsvOic44eUhjNHWYdArT-Nks5s8tG-gaJpZM4Qy6P8.

oehm2007 commented 7 years ago

@oehm2007 I really recommend "hacking" Amazon's Dash buttons for some special use cases but not as an Hue Switch / Tap replacement – since it takes some time to find them on your network and run your flows (about 3-7 seconds for me). If you don't care about this latency you could do things like this for example with this awesome node:

Yes you`re definetly right. I already tried some stuff with the dashbutton, but after a little while they were just ignoring my comands. Even finding the buttons in the network isnt that easy :-) But I will try to give it a second chance, because of your example.

Unfortunatelly I have a last little issue, with the dimmer switches. I just noticed, that there is a small higher latency in the reaction of the lamps, controllinmg them by the dimmer switch through node-red. The switches connected straight to the hue-bridge without node-red reacts maybe 1.5s faster. I just made a comparison. (In node red is just an easy function between the button and the lamp )

Do you know, maybe how to speed that up a little bit? Its complaining on a high comfort level, but maybe youve got an idea.

Foddy commented 7 years ago

@oehm2007 I know what you mean. Unfortunately the Philips Hue API doesn't offer any real time communication with the bridge and devices. That means that HueMagic has to periodically check on the bridge if there are "updates" available.

But you could indeed try to modify your "Poll interval" setting in your Hue Bridge node to a lower number. Maybe 1000 (1 second) or 2000 (2 seconds), which means that HueMagic will check every second (or every two seconds) if you tapped a button on your Hue Switch/Tap and fire up your flow much faster.

config

I don't recommend to go lower than that. This could lead to problems on your Hue Bridge, NodeRED Host or even on your local network.