结合飞利浦 Hue、HomeKit 和音乐(iTunes 或 Spotify)

Combine Philips Hue, HomeKit and Music (iTunes or Spotify)

第一次在这里使用HomeKit

我有 Philips Hue 并使用 Siri (HomeKit) 我用我的声音激活了不同的 scenes/ambients,这真的很酷。

我想更进一步...

在 WWDC 中,我看到关于 HomeKit,我们可以使用恒温器、风扇、灯、门、窗帘、开关、警报器、传感器... 但是我看到缺少创建环境的关键元素:音乐。

我知道使用 Hue 可以创建环境,如海滩日落,使用红色和橙色作为灯光,但同时我想播放特定的播放列表,例如海浪或海浪的声音,或者只是夏威夷音乐。可能性可能是无穷无尽的,而且超级酷。

我需要做什么?

我是否必须创建自己的使用 HomeKit 和 Spotify API 或 Apple Music API 的应用程序?

我的想法是用Siri启动ambient(也就是灯光和音乐),但我不知道我想要的在技术上是否可行。

有什么建议吗?那太棒了。

您可以使用 AppleScript 非常轻松地执行此操作(如果您使用的是 Macintosh,那就是...)这里有一些示例 AppleScript 代码,您可以从这里开始。 (将此代码粘贴到脚本编辑器 window。)

-- define baseUrl to point to your Hue hub address and one of the keys in your whitelist
set baseUrl to " http://YOUR-HUB-IP/api/YOUR-WHITELIST-ENTRY"

-- read the info about light 1
set lightJson to do shell script "curl " & baseUrl & "/lights/1"

-- define some JSON to set a light state
set lightStateOn to the quoted form of " {\"on\": true,\"bri\": 254,\"hue\": 8000,\"sat\": 254} "

-- send the JSON to set a light state (on and with specified hue, saturation, and brightness)
do shell script "curl --request PUT --data " & lightStateOn & baseUrl & "/lights/1/state/"

tell application "Spotify"
    play track "spotify:track:3AhXZa8sUQht0UEdBJgpGc"
end tell

set lightStateOff to the quoted form of "{\"on\": false}"
do shell script "curl --request PUT --data " & lightStateOff & baseUrl & "/lights/1/state/"

编辑 baseUrl 以包含集线器的真实 IP 和集线器 JSON 文件中白名单(用户)中的密钥之一。

然后编写 curl 命令脚本以获取或发送 JSON 到集线器,这会改变您的灯光。

最后,Spotify 和 iTunes 都可以编写脚本,因此您可以让它们播放歌曲、播放列表等。请参阅 http://dougscripts.com/ 了解有关编写 iTunes 脚本的更多信息。

您也可以使用其他语言和平台执行此操作,具体取决于您的硬件和技能。语法会有所不同,但策略是相似的:发送命令来控制 hue hub,然后发送其他命令来控制音乐播放器。

我遇到了同样的问题,所以我决定开发自己的应用程序。实际上,它是一个 Mac 应用程序,它使用 AppleScript 连接到您的 Spotify 桌面应用程序并获取 Spotify API 以便将灯光与音乐完美同步。它很基本但超级准确而且完全免费:

https://itunes.apple.com/fr/app/lightshow/id1217138942?l=en&mt=12