【问题标题】:Using Applescript and cURL to control Philips Hue lighting system使用 Applescript 和 cURL 控制飞利浦 Hue 照明系统
【发布时间】:2012-10-30 08:44:42
【问题描述】:

我发现可以使用如下命令控制飞利浦 Hue 灯:

向(此处为您的 Hue 网站)发出 HTTP POST 请求

{"username": "YourAppName", "devicetype": "YourAppName"} 如果您没有按下 Hue Hub 上的按钮,您将收到这样的错误;

{"error":{"type":101,"address":"/","description":"链接按钮未按下"}} 按下集线器上的链接按钮,然后再试一次,您应该会收到;

{“成功”:{“用户名”:“密钥”}} 上面的键将是一个 md5 字符串,记住这一点,你在以后的所有请求中都需要它

--但我不知道如何使用 Applescript 来说那种语言--我知道你可以在其中使用“do shell script”和可能的 cURL,但是,我在实际获得代码才能正常工作。

有什么想法吗?

【问题讨论】:

  • 我试过做 shell script "curl -d \"username\": \"me\", \"devicetype\": \"hue\" 192.168.1.112/api" 说无效的 json。我还使用了一个名为 Simple Rest Client 的 Chrome 扩展程序,它确实允许代码工作。
  • 请不要编辑您的问题来添加答案。只需在下面添加答案,并在所需的等待时间后,将其选为正确。

标签: api applescript philips-hue


【解决方案1】:

对于 shell 脚本试试这个:

curl -d "{\"username\": \"yourname\", \"devicetype\": \"yourhuename\"}" [not a link]http://hueIpAddr/api

【讨论】:

    【解决方案2】:

    我能够让我的 python 脚本使用 curl 请求来通过 subprocess 控制灯光(我认为类似于做 shell 脚本),使用:

    curl --request PUT --data \'{"on":true, "xy":[0.4370,0.3706],"bri":255}\' http://{url}/api/{username}/lights/1/state
    

    要使用 curl 创建用户,您可能应该将代码更改为如下所示:

    curl --request POST --data \'{"devicetype":"your_devicetype", "username":"your_username"}\' http://{url}/api/
    

    公平地说,我没有尝试使用 curl,因为我正在努力在 python 中迁移到 urllib2。 希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      另一个带有通过 HSB 和转换时间设置颜色的有用功能的 shell 脚本。

      #!/bin/sh
      #
      # Register "patniemeyer" key with this bridge
      #
      # % curl -d '{"username": "patniemeyer", "devicetype": "Philips hue"}' http://192.168.1.179/api
      # [{"success":{"username":"patniemeyer"}}]
      #
      
      KEY='patniemeyer'
      IP='192.168.1.179'
      
      #
      # Light number, hue, saturation, brightness, transition time
      #
      # hue 0-65535
      # sat 0-255?
      # transition time 1/10 seconds
      #
      lightNHSBT() 
      {
          _lightNum=$1
          _hue=$2
          _sat=$3
          _brightness=$4
          _ttime=$5
          curl --request PUT --data "{\"hue\":$_hue, \"sat\":$_sat, \"bri\":$_brightness, \"on\":true, \"transitiontime\":$_ttime}" http://$IP/api/$KEY/lights/$_lightNum/state/
      }
      
      #
      # CIE 1931 X,Y colors
      # Light number, X, Y, brightness, transition time
      #
      # transition time 1/10 seconds
      #
      lightNXYBT() 
      {
          _lightNum=$1
          _x=$2
          _y=$3
          _brightness=$4
          _ttime=$5
          curl --request PUT --data "{\"xy\":[$_x,$_y], \"bri\":$_brightness, \"on\":true, \"transitiontime\":$_ttime}" http://$IP/api/$KEY/lights/$_lightNum/state/
      }
      
      # 
      for f in 1 2 3 4 5 6 
      do
          lightNHSBT $f 0 255 255 5  # full red
      done
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-18
        • 2015-02-18
        • 1970-01-01
        • 1970-01-01
        • 2017-12-05
        • 1970-01-01
        相关资源
        最近更新 更多