falk0069 / hue-upnp

Philips Hue UPNP and HTTP emulator (works with the Android Hue app and Logitech Harmony Home Remotes)
30 stars 10 forks source link

Pair with Hue bridge (press button)? #6

Open joq3 opened 8 years ago

joq3 commented 8 years ago

Hi,

Just installed this on my server running Debian. Got everything running. And my Harmony Hub does detect the Philips hue in the network. But when I add it to the Harmony (with the Harmony android app) I'm asked to press the button on the Hue to pair it. How do I do this, as this only emulates Philips Hue and there is no button to press?

Can I send a command via PuTTy to emulate the button-press and thus pairing it?

A quick reply is very very welcome. And thank you for your great work and easy installation!

Have a nice weekend!

joq3 commented 8 years ago

Here is the Error-log: http://pastebin.com/jPnMHKNk

joq3 commented 8 years ago

Also tried with the Windows-application (connecting via USB), here is the debug: http://pastebin.com/Bd8wxEwv

falk0069 commented 8 years ago

Hi job3,

I hope to be able to look into this tonight. I probably should re-run a new test since there has been a new firmware which might have broke things. As far as the button push, you shouldn't need to do this. The hueupnp should automatically reply back as if the button was already pushed.

Thanks for your interest.

--Andy

joq3 commented 8 years ago

Thanks for your quick reply! Have been trying to figure it out for a few hours. No success! Can this error message affect anything: 2015-11-14 21:07:03,779 [INFO ] Http Socket Error: [Errno 99] Cannot assign requested address Traceback (most recent call last):

What does it medan exactly?

Hope you have time, would love to make it work as soon as possible :)

falk0069 commented 8 years ago

Have you tried using a different http port? Also any port less than 1024 requires it to be run as root. I should have time tonight to look at your log closer. Thanks Andy On Nov 14, 2015 4:54 PM, "joq3" notifications@github.com wrote:

Thanks for your quick reply! Have been trying to figure it out for a few hours. No success! Can this error message affect anything: 2015-11-14 21:07:03,779 [INFO ] Http Socket Error: [Errno 99] Cannot assign requested address Traceback (most recent call last):

What does it medan exactly?

Hope you have time, would love to make it work as soon as possible :)

— Reply to this email directly or view it on GitHub https://github.com/falk0069/hue-upnp/issues/6#issuecomment-156752895.

falk0069 commented 8 years ago

I see in your logs the http server is defined like so: http://192.168.1.200:8080

This the IP and Port that I normally use, but I doubt it is right for you. What you are going to want to do is open up the hueUpnp.py and edit some lines. If you open it up you will see these lines at the top:

#config
BCAST_IP = "239.255.255.250"
UPNP_PORT = 1900
BROADCAST_INTERVAL = 200 # Seconds between upnp broadcast
IP = "192.168.1.200" # Callback http webserver IP (this machine)
HTTP_PORT = 8080 # HTTP-port to serve icons, xml, json (80 is most compatible but requires root)
#external script to easily call other activities (e.g. wol, wemo-switch, etc)
EXTERNALPROG = "./hue-upnp-helper.sh"

What you will need to at least do is update the IP to be your machine's IP. So replace the 192.168.1.200 with IP address of the machine where you are running hueUpnp.py.

Let me know if that makes sense.

Thanks --Andy

joq3 commented 8 years ago

I have now replaced the IP with my NAS-IP which is 192.168.1.2. Set the port to 3535. And now I can add the device with my Harmony Android-app. I got three devices, two Wemo and PC Wol. I changed the Mac-adress to the PC I want to wake in this file: hue-upnp-helper.sh

Directly after I added the device in the Harmony app the 3 devices were "On". And pressing the PC Wol brings me to a Color / Warm/cool selection, and a power button on the bottom left (plus a brightness slider on the right). I have tried pressing this power-button when my PC is off with no reaction. I have confirmed that WOL works with my PC before.

Is there something else I forgot to change? Should PC WOL bring up a color-chart?

And is it possible to remove the Wemo devices? Only need the WOL.

falk0069 commented 8 years ago

Well signs are looking good that you will be in business soon. First off, the number devices is pretty much hard coded. This is because the JSON payloads that come from a standard hue contains 3 devices and this is what was captured during traces. I'm pretty sure it would be possible to adjust total number of devices. You probably would just have to play with this string in the code: LIGHTSRESP_TEMPLATE. I'm working with someone else to adjust how JSON is handled in the code and perhaps we can work on making the number of devices adjustable. For now I would suggest just updating the Wemo device names to 'Disabled' or something like that. To do that adjust the values in the GLOBAL HUE STATE section:

HUE1NAME = "PC WOL" HUE1ON = "false" HUE1XY = "[0.0,0.0]" HUE1BRI = "254" HUE1CT = "201" HUE2NAME = "Disabled" HUE2ON = "false" HUE2XY = "[0.0,0.0]" HUE2BRI = "254" HUE2CT = "201" HUE3NAME = "Disabled" HUE3ON = "false" HUE3XY = "[0.0,0.0]" HUE3BRI = "254" HUE3CT = "201"

Also. I would suggest setting to 'ON' states to false:

HUE1ON = "false"

This way the default state for your PC will be off when you first start hueUpnp.py.

I don't think there is a way to avoid the color chart as far as I know. The Harmony thinks it is interfacing with a hue color lamp. so it gives the options to change the color. The only thing you need to worry about is the power button on the screen in the lower left corner. This has never bothered me since I just have it mapped to a button on my remote.

Now for the real issue at hand-why isn't the WOL working. I wondering if you don't have the wakeonlan program installed. All the hue-upnp-helper.sh is doing is issuing this command:

wakeonlan 11:22:33:44:55:66

Can you try just running that raw command and make sure it wakes your PC? Otherwise if you are on a Debian/Ubuntu flavored machines run:

sudo apt-get install wakeonlan

Let me know how it goes and if you still can't get it, send me another clip of the log when you press the power button and I will see if I can see any problems.

joq3 commented 8 years ago

Oh, I feel pretty stupid! I did not know there was a separate program running the WOL. Thought it was built in or a system feature. Amazing! Now it works like a charm!! It feel great being able to boot the computer from the Harmony remote!

The PC WOL does however stay On, if I switch to another activity (like TV) before turning everything off with the remote off-button. If I just run the activity with PC WOL and then turn off with the remote it goes off as it should. This causes some problems the next time the command is needed.

Did rename the others to disabled, great idea!

Another stupid question, as this is emulating a Hue bridge, am I able to purchase Philips hue-lights and connect them to this application (without purchasing a real bridge)? And how do you connect them to the bridge?

Thank you for your amazing work and quick help. Sorry for being a bit stupid, not figuring out these things!

EDIT: By the way, it does say, setup log rotation. I have changed the logging to ERROR. Is that enough, or will it build up to be a really big log? I don't know how to setup log rotation. This is in the log after setting it to ERROR: http://pastebin.com/bZrUVDdh It does give some error, but it still wakes the pc up.

falk0069 commented 8 years ago

What I do is I press the button on the remote that I set to WOL and then I start the activity to get other devices going for the media center. Then in my shutdown sequence I press the 'sleep' button to put the PC back to sleep. I know that in recent firmwares you can now add in home control states to activities, but for some reason it caused problems for me because I could not control the order of when the commands fire. I might try again and see if I can make it work better as I now see you can specify it during the start and end sequence. What you might want to try doing is making sure in your activity that you add in the home control for WOL and turn it "off" in the end sequence. This won't do anything really except set the "state" correct so that you can turn it "on" the next time you run that activity.

My understanding is you can have two hue bridges running on the same network, so it should be possible, but what I've noticed is if you go and try setting up another home control device you can't add a second hue. So, I would say at this time the harmony does not support multiple hue bridges.

As for you logging. All those messages are actually coming from the hue-upnp-helper.sh script. If you are only using this to do WOL you could greatly simplify that script. This is probably all you need inside that script:

#!/bin/bash
if [ "$1" == "1" -a "$2" == "on" -a "$3" == "true" ]; then
      wakeonlan 11:22:33:44:55:66 >/dev/null 2>&1
fi

Note: the redirect to /dev/null so you don't see the magic packet output line. You could also opt to append the >/dev/null 2>&1 to each command to prevent the extra logging. If you do this redirect and keep the logging at ERROR, you shouldn't need to worry about log rotation. I doubt you'd see ever a megabyte of logging after a year. Plus, every time you restart, the log would get overwritten.

I hope this helps

joq3 commented 8 years ago

Late reply, but I did exactly what you said. And it works GREAT! Works everytime, log is completely empty!

I can't thank you enough!

falk0069 commented 8 years ago

Great news. Glad it works for you.

joq3 commented 7 years ago

Hi again,

I've been using this nice solution for a year now. Which works great at waking up my computer. But I have a really annoying issue. Everytime I use this to wake my computer up it will not shutdown properly. I shut it down via Windows and it boots back up again immidiatly, and I have to shut it down once more to get it to stay off. This does not happen if I start my computer with the physical button. Does it send two wake on lan packages, which means it does wake up as soon as it is shut off? How can I check this?

Thank you for your awesome work!

falk0069 commented 7 years ago

That is so weird. Even if the script sent two WOL packets, the second one would just be obsolete. It doesn't get cached in the network or Windows. The only way a WOL would be starting it up again would be if it is constantly sending it. But then the second shutdown would also have issues. I did a little searching around on the web. Did you see these pages and possible solutions:

http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/windows-7-computer-restarts-automatically-after/daeb457a-3509-4be9-a85b-2935c8c3e108

http://www.pcworld.com/article/247392/windows/my-computer-reboots-when-i-tell-it-to-shut-down.html

Let me know if you've tried them and if they still didn't help.

On Tue, Nov 8, 2016 at 6:16 AM, joq3 notifications@github.com wrote:

Hi again,

I've been using this nice solution for a year now. Which works great at waking up my computer. But I have a really annoying issue. Everytime I use this to wake my computer up it will not shutdown properly. I shut it down via Windows and it boots back up again immidiatly, and I have to shut it down once more to get it to stay off. This does not happen if I start my computer with the physical button. Does it send two wake on lan packages, which means it does wake up as soon as it is shut off? How can I check this?

Thank you for your awesome work!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/falk0069/hue-upnp/issues/6#issuecomment-259121848, or mute the thread https://github.com/notifications/unsubscribe-auth/AKcViWu9Uf0W8wEV1yrVblmHfgsTYAZ8ks5q8GgmgaJpZM4GiaXm .

joq3 commented 7 years ago

Actually it didn't have anything to do with this application, you were right! I tested with other Wake On Lan apps and got the same issue. So I searched for a while and it actually is the Windows Fast boot that causes this. In Windows settings, uncheck Fast boot and it works great!

Thank you for taking your time to help me!