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

Call external API url #14

Open LDSign opened 8 years ago

LDSign commented 8 years ago

Hi

I have no experience in python so far. But I am lucky to got your app up and running :)

I would like to call a external (api) url via get in hue-upnp-helper.sh to control my devices. How could this be done? Could you provide an example?

And how is it achieved that the button on the harmony remote works like a toggle (so calling a different url regarding the state of the light)?

Thanks for your help, Frank

falk0069 commented 8 years ago

I guess the easiest would be to use a wget or curl call inside the hue-upnp-helper.sh. wget is typically included in most Linux distros. Curl might also be, but if not it is normally pretty easy to get. Curl is a little more powerful if wget doesn't work for you. Here is quick example I just pulled from the web using wget:

wget -S -q --header "Accept: application/json" -O - http://server.example.com/resource/1

If you are using the hue-upnp-helper.sh example just update one of the DEVICEN variables at top. E.g.

DEVICE1="MyDevice"

Then update the section below with your on/off commands. E.g.

if [ "$1" == "$DEVICE1" ]; then
  echo "Running directive for $DEVICE1"
  #ON/OFF Directive
  if [ "$2" == "on" ]; then
    if [ "$3" == "true" ]; then
      wget -S -q --header "Accept: application/json" -O - http://server.example.com/resource/on
    elif [ "$3" == "false" ]; then
      wget -S -q --header "Accept: application/json" -O - http://server.example.com/resource/off
    fi

Let me know if that helps.

LDSign commented 8 years ago

Hey

Thanks for your help. Ive already figured it out before reading your post here :) Ive done it exact the same way.

Thanks again, Frank