简体   繁体   English

结合Philips Hue,HomeKit和音乐(iTunes或Spotify)

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

First time using HomeKit here. 第一次在这里使用HomeKit。

I have Philips Hue and using Siri (HomeKit) I activate different scenes/ambients with my voice, which is really cool. 我有Philips Hue,并使用Siri(HomeKit)用声音激活了不同的场景/环境,这真的很酷。

I'd like to go one step further... 我想再走一步...

In WWDC I see that regarding HomeKit we can use termostats, fans, lights, doors, curtains, swithches, alarms, sensors... But I see a key element to create ambient is missing: Music. 在WWDC中,我看到关于HomeKit,我们可以使用恒温器,风扇,灯,门,窗帘,弯头,警报器,传感器...但是我看到缺少创建环境的关键要素:音乐。

I know using Hue it is possible to create ambients, like a beach sunset, using red and orange colors for lights, but at the same time I would like to play a specific playlist, for example sea or waves sounds, or just hawaiian music. 我知道使用色相可以创建环境,例如海滩日落,使用红色和橙色作为灯光,但是与此同时,我想播放特定的播放列表,例如海声或海浪声或夏威夷音乐。 The possibilities could be endless and super cool. 可能性可能是无止境的,而且非常酷。

What do I have to do? 我需要做什么?

Do I have to create my own app that uses HomeKit and Spotify API or Apple Music API? 我是否必须创建使用HomeKit和Spotify API或Apple Music API的自己的应用程序?

My idea is to start the ambient using Siri (that is, lights and music), but I don't know if what I want is technically possible. 我的想法是使用Siri(即灯光和音乐)启动环境,但是我不知道我想要的技术是否可行。

Any suggestion? 有什么建议吗? That would be awesome. 那将是真棒。

You can pretty easily do this with AppleScript (if you use a Macintosh, that is...) Here's some sample AppleScript code you could start with. 您可以使用AppleScript轻松完成此操作(如果使用Macintosh,那就是...)。这是您可以从中开始的一些示例AppleScript代码。 (Paste this code into a Script Editor 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/"

Edit the baseUrl to include the real IP of your hub and one of the keys in the whitelist (users) from your hub's JSON file. 编辑baseUrl以包括集线器的真实IP以及集线器JSON文件中白名单(用户)中的键之一。

Then script the curl command to get or send JSON to the hub, which changes your lights. 然后编写curl命令脚本以获取或发送JSON到集线器,这将改变您的灯光。

Finally, both Spotify and iTunes are scriptable, so you can tell them to play songs, playlists, etc. See http://dougscripts.com/ to learn more about scripting iTunes. 最后,Spotify和iTunes均可编写脚本,因此您可以告诉它们播放歌曲,播放列表等。请访问http://dougscripts.com/了解有关编写iTunes脚本的更多信息。

You can do this in other languages and platforms also, depending on what your hardware and skill are. 您还可以使用其他语言和平台来执行此操作,具体取决于您的硬件和技能。 The syntax will be different, but the strategy will be similar: send the commands to control the hue hub and then send other commands to control the music player. 语法会有所不同,但是策略将是相似的:发送命令来控制色调中心,然后发送其他命令来控制音乐播放器。

I was facing the same issue, so I decided to develop my own app. 我遇到了同样的问题,因此我决定开发自己的应用程序。 Actually, it's a Mac App that connects to your Spotify desktop app using AppleScript and fetches the Spotify API in order to sync the lights perfectly with the Music. 实际上,这是一个Mac App,它使用AppleScript连接到您的Spotify桌面应用,并获取Spotify API,以使灯光与Music完美同步。 It's basic but super accurate and totally free: 它是基本的,但超级准确且完全免费:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM