Author Topic: Customized light effects: Philips Hue + MediaMonkey  (Read 7252 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Customized light effects: Philips Hue + MediaMonkey
« on: August 02, 2014, 11:46:29 AM »
My latest wee fun experiment:

When a new track starts playing in MediaMonkey, it triggers a Python script that checks whether the song title, artist name, or album name includes a colour (e.g. Purple Rain, Blues Traveler, Yellow Submarine, etc.).

If it finds a colour, the Python script triggers a special Hue.Song event. This event has 2 payloads: {1} -> the colour, {2} the song, artist, or album name containing the colour. This event can be used to do whatever we want.

In my command group below, I have a command that turns a particular Hue group to said colour, just as a very simple example. It uses the payload XML file PhHues.xml, which comes with the Hue preset configuration (as of VC 2.0.0.5). I'll include it here as well, though.

My VC command group:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.5-->
<commandGroup open="False" name="Hue meets MediaMonkey" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="292" name="++Colour trigger" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Passes song title, artist name, and album name to Python script. Stores the current Hue state first, so you can choose to restore lights to previous state after executing the hueTunes lighting change (I don't do that here.)">
    <action>
      <cmdType>Hue.Store</cmdType>
      <params />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <params>
        <param>200</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>hueTunes("{1}","{2}","{3}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>MM.Playing</event>
  </command>
  <command id="265" name="Moody tunes" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Turns Hue group 1 to the song colour. Uses the PhHues payload xml file to retrieve the desired colour. Customize this command as you like.">
    <action>
      <cmdType>PayloadXML.GetValue</cmdType>
      <params>
        <param>huePayloads\PhHues.xml</param>
        <param>{1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Hue.Group</cmdType>
      <params>
        <param>1</param>
        <param>"on":true, {LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Hue.song</event>
  </command>
  <command id="267" name="Load python MM Hue script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\hueTunes-events.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

If you want to try this, be sure to put the attachments in the correct subdirectories, or change the file paths in the commands.

Plugins you need enabled: MediaMonkey, Hue, Python.
« Last Edit: August 02, 2014, 12:36:31 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #1 on: August 02, 2014, 11:55:53 AM »
Forgot to say: The Python code above is a simple script that prioritizes the colours according to the order they appear in my Python list. If there is more than one colour in the data, it will ignore the other colours.

Why? Because I'm lazy!

That said, if you like some Hue colours more than others, change the order that they appear in the Python script and it will prioritize your colour effects accordingly (so if a song is "Orange Alert" and the artist is "Purple Nurple", currently it will prioritize purple effects over orange effects).

... And here I am attaching an alternative Python script that instead prioritizes: colour in a song title, then colour in an artist's name, then colour in the album title.

In other words, it will prioritize orange effects (the song) over purple effects (the artist).

Take your pick.
« Last Edit: August 02, 2014, 12:27:50 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #2 on: May 12, 2015, 11:34:33 PM »
I know this is an old topic, but I'd really like it to work... :)

I've had it installed for a while and it never really worked but I got sidetracked on a few other ideas and am just now looking at it again. It just sits there and runs and I see the notifications in the log, but I have ignored them.

I told it to play the song Purple Rain. I had been using my climate controls previously and when the song played I got the following entries.

PayloadXML.GetValue:huePayloads\PhHues.xml&&purple
HueGroup:1&&"on":true,https://mutotalconnectcomfort... (full url of the robobrowser window)

I ask what song is playing it says Purple Rain. I restart the song and get the following

PayloadXML.GetValue:huePayloads\PhHues.xml&&purple
HueGroup:1&&"on":true,Purple Rain

I tell it to play Yellow Submarine and get the following entries

PayloadXML.GetValue:huePayloads\PhHues.xml&&yellow
HueGroup:1&&"on":true,Purple Rain

again ask what song is playing, get Yellow Submarine, stop start and get

PayloadXML.GetValue:huePayloads\PhHues.xml&&yellow
HueGroup:1&&"on":true,YellowSubmarine

It seems like there is a variable somewhere that isn't getting set right.

any ideas?




nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #3 on: May 13, 2015, 07:53:53 AM »
It's been a long time since I looked at it. I could very well have uploaded commands with mistakes in them. Wouldn't be the first time. :)

I'll take a look when I get a chance.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #4 on: May 13, 2015, 08:22:12 AM »
My guess is that it can't find phHuesXml, but that would be very obvious if you looked at the history window because that action would be shown with an orange background to show an error.

If that's not the problem then please send us a complete log.

The command is tested and working fine for us.

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #5 on: May 13, 2015, 11:05:58 AM »
This was a great exercise in reading the log to find an error. With your guess I knew what to look for and found that I had put the phhues.xml in the payloads directory and not the huePayloads directory. Moved it over and it works fine. It did not however have an orange background on that action. It still shows the OSD hue settings a song behind as well which is not rally an issue since "Alexander" is headless and only accessed remotely for programming.

 Little by little I'll get more self sufficient with the program but love that you guys are here actively supporting it.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #6 on: May 13, 2015, 11:20:33 AM »
This was a great exercise in reading the log to find an error. With your guess I knew what to look for and found that I had put the phhues.xml in the payloads directory and not the huePayloads directory. Moved it over and it works fine. It did not however have an orange background on that action.

The line wouldn't be orange in the text log (VoxLog.txt), if that's what you mean here. It should be orange in the history panel as per the image below, unless perhaps you have some kind of special monitor situation/screen share going on when you need to view what your "headless" PC is up to?


Quote
It still shows the OSD hue settings a song behind as well which is not rally an issue since "Alexander" is headless and only accessed remotely for programming.

My commands above do not include any OSD messages, so I'm not sure what this is referring to. Again, if you want to post your log or show what changes you've made to the commands in order to get an OSD message, maybe we can help with that.
« Last Edit: May 13, 2015, 11:37:38 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #7 on: May 13, 2015, 12:16:48 PM »
The orange issue could very well be from using VNC. It certainly wouldn't be the first display oddity I've seen in it.

I just found the OSD is coming from the built in MM command tree undern MM Basic control. If I say start playback it plays MM and does an OSD of {LastResult}

MM Play Song by Name - Play Song {1} does the same thing. I got a clue when the OSD showed one thing, but the TTS said the correct thing. The OSD is using {LastResult} while the TTS is using {1}. It sounds like the MM.LoadBySQL is not putting it's results in {LastResult}

Just did a quick test.

"Alexander Play song Purple Rain" (really getting tired of that song now)
TTS Now Playing Purple Rain. OSD Great Gig in the Sky (last song playing when I asked what song is this)

"Alexander What song is this"
TTS and OSD - Purple Rain

"Alexander Play song Enola Gay"
TTS Now playing song Enola Gay OSD "sat":255, "Hue"55000 (since it had just played purple rain and changed the lights)

I can repeat the last command and it will start the song over with the same results but once I ask what song is this it will show Enola Gay on the OSD. (or Orchestral Manoeuveres in the Dark if I ask who is this instead)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #8 on: May 13, 2015, 12:47:08 PM »
OK, I see now what you mean. Funny no one has mentioned this before. I'll make sure we update the MM config for the next release.

You can replace {LastResult} with {1} if you want, in the MM Play Song By Name, but that simply means it will show the title you've requested -- not necessarily what MM plays (though these should amount to the same thing for the most part).

For your Music Play command, if you want to get info about the track that it starts playing, you can simply add an MM.CurrentSongData > title action above your feedback actions that take {LastResult}.

http://voxcommando.com/mediawiki/index.php?title=Plugin_MM

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<command id="5" name="Music Play" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>MM.Play</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>MM.CurrentSongData</cmdType>
    <params>
      <param>title</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Music Play, Start Playback, Press Play</phrase>
</command>

And:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<command id="90" name="Play Song {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>MM.LoadBySQL</cmdType>
    <params>
      <param>SongTitle ='{1}'</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>MM.Play</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>MM.CurrentSongData</cmdType>
    <params>
      <param>artist</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>Playing song {1}, by {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>Playing song, {1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Play</phrase>
  <phrase optional="true">the</phrase>
  <phrase>song, track</phrase>
  <payloadFromXML phraseOnly="True" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">mmPayloads\mmSongs.xml</payloadFromXML>
</command>
« Last Edit: May 13, 2015, 12:50:10 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #9 on: May 13, 2015, 01:00:32 PM »
The orange issue could very well be from using VNC. It certainly wouldn't be the first display oddity I've seen in it.


In VNC you can specify the number of colours to use, or put it on auto...

https://www.realvnc.com/products/open/4.1/winvncviewer.html#ColorEncoding

If you are running on a LAN with decent speed you can usually set it to full colour.

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #10 on: May 13, 2015, 03:12:17 PM »
ok, hopefully I'm not driving you nuts by now. I'm using this on a specific set of three lights in a group I call my entertainment wash which is the wall behind the TV. I tried to modify this to load a set of random colors to those three lights if no color is found using my limited and dangerous python and google searching skills. Here is my modified hueTunes-events.py file.

Code: [Select]
import re
from System.Collections.Generic import *

def hueTunes(song,artist,album):

    palette=["red","green","purple","yellow","blue","white","pink","orange"]
   
    for colour in palette:
        #checks if song title has one of the colours in it. The 1st colour found generates event "Hue.song", w/ payloads {1}:colour, {2}:title
        if re.search(colour,song,re.I):
            vc.triggerEvent("Hue.song", List[str]([colour, song]))
            return
        #if no colour in song, checks if artist name has one of the colours in it. If so, generates event "Hue.song", w/ payloads {1}:colour, {2}:artist
        elif re.search(colour,artist,re.I):
            vc.triggerEvent("Hue.song", List[str]([colour, artist]))
            return
        elif re.search(colour,album,re.I):
            vc.triggerEvent("Hue.song", List[str]([colour, album]))#same thing, w/ album name. Put this above artist if you want it checked first.
            return
        else:
            vc.triggerEvent("Hue.song",List[str](["random", artist]))#trigger random if no colors in song.
            return       

only difference is the added else statement that instead of a colour it sends random in the payload which I have already modified the command for and it loads those random colors perfectly. The problem is no matter what I play now, it sends the variable random instead of purple for purple haze (purple rain is banned for the day) or yellow, yellow submarine, etc.

Can you tell me where I screwed up, or if there is a better way of doing this?

Also I have it now showing orange on lines that error. In this case it will error on PY.huetunes if the song, album, or artist contains one of the following characters " [  ie Purple Rain - 12" version or Purple Haze [black label mono wax 45]. perhaps a regex to strip those out would work?
« Last Edit: May 13, 2015, 03:23:14 PM by OklahomaGreyBeard »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #11 on: May 13, 2015, 04:21:37 PM »
The default Hue config that we provide includes a command called "Mix it up (Random colours)" that randomizes colours for the first 3 lights.  No python is required.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="372" name="Mix it up (Random colours)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Sets each light (total 3) to its own random colour, and semi-random saturation, with medium brightness.">
  <action>
    <cmdType>Hue.Light</cmdType>
    <params>
      <param>{i}</param>
      <param>"hue":{Rnd.1.65000},"bri":127,"sat":{Rnd.150.250}</param>
    </params>
    <cmdRepeat>3</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>How about this? | Does this work? | Here's a random mix | A bit of this, and a splash of that</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Mix it up, random colours, surprise me</phrase>
</command>

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #12 on: May 13, 2015, 04:37:53 PM »
@jitterjames - Yes, but he wants to have his Hue switch to random colours at the beginning of a song *only* if the track does not include a colour term. If it has a colour term, he wants to set his lights to that colour using the Python script in this thread. Hence his attempt to alter the script.

@OK - You're on the right track but you can't do it quite like that in the case of the script that I posted.

The following should work. There are other ways too. I don't have time to spend on it now though, sorry.

Code: [Select]
import re
from System.Collections.Generic import *

def hueTunes(song,artist,album):

    palette=["red","green","purple","yellow","blue","white","pink","orange"]
   
    for colour in palette:
        #checks if song title has one of the colours in it. The 1st colour found generates event "Hue.song", w/ payloads {1}:colour, {2}:title
        if re.search(colour,song,re.I):
            vc.triggerEvent("Hue.song", List[str]([colour, song]))
            return
        #if no colour in song, checks if artist name has one of the colours in it. If so, generates event "Hue.song", w/ payloads {1}:colour, {2}:artist
        elif re.search(colour,artist,re.I):
            vc.triggerEvent("Hue.song", List[str]([colour, artist]))
            return
        elif re.search(colour,album,re.I):
            vc.triggerEvent("Hue.song", List[str]([colour, album]))#same thing, w/ album name. Put this above artist if you want it checked first.
            return
           
        else:
            colour = False

    if colour is False:
        vc.triggerEvent("Hue.song",List[str](["random"]))#if no colour, trigger Hue.song event passing "random" as a colour.
        return

wrt your weird character problem. Yes, there's probably a way to strip out the offending characters or whatnot. Again, I don't have time to help with that right now, but maybe someone else can suggest some solutions. If not, no biggee, the script will return an error and so nothing will change. When the next track plays, the python script will run again.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #13 on: May 13, 2015, 04:58:04 PM »
The quotes would need to be removed from all three payloads  before calling the Python action.  Probably not worth the trouble.

OklahomaGreyBeard

  • Contributor
  • ***
  • Posts: 54
  • Karma: 3
    • View Profile
Re: Customized light effects: Philips Hue + MediaMonkey
« Reply #14 on: May 13, 2015, 05:22:22 PM »
Thank you very much. This not only gave me exactly what I was after, it let me see where I went wrong in my own attempts to change it.

And you're probably right, other than for my own personal giggles, this will only come into play during a party in which case I would have created a pre-set playlist and could have them all cleaned up ahead of time.  The only place I seem to be running into them is in my attempts to possibly over-tag my music as I convert it from Vinyl to FLAC to play from MM.