VoxCommando Forum

VoxNastics (User Guides and Mods) => XML Exchange => Topic started by: nime5ter on August 02, 2014, 11:46:29 AM

Title: Customized light effects: Philips Hue + MediaMonkey
Post by: nime5ter 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:
<?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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: nime5ter 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: OklahomaGreyBeard 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?



Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: nime5ter 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: jitterjames 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: OklahomaGreyBeard 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: nime5ter on May 13, 2015, 11:20:33 AM
Quote from: OklahomaGreyBeard 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.

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?


QuoteIt 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: OklahomaGreyBeard 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)
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: nime5ter 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

<?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:

<?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>
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: jitterjames on May 13, 2015, 01:00:32 PM
Quote from: OklahomaGreyBeard 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.


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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: OklahomaGreyBeard 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.

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?
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: jitterjames 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.

<?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>
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: nime5ter 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.

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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: jitterjames 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: OklahomaGreyBeard 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.
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: jitterjames on May 13, 2015, 05:44:00 PM
I decided to try recreating this command using no Python.  I think I managed to do it using a single command, with no Python, and it should not have a problem with the quotes any more because that error was introduced when trying to call the python function which didn't like the quotes.

Only this command is required, but you'll still need to have the payload file: huePayloads\PhHues.xml so that it can look up the colour names to get values for hue and saturation.

<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.5-->
<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>Results.SetLastResult</cmdType>
    <params>
      <param>{1} {2} {3}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>(red|green|purple|yellow|blue|white|pink|orange|black)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>LastActionSuccess</ifType>
    <ifParams>&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>PayloadXML.GetValue</cmdType>
        <params>
          <param>huePayloads\PhHues.xml</param>
          <param>{Match.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Hue.Group</cmdType>
        <params>
          <param>0</param>
          <param>"on":true, {LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>Hue.Light</cmdType>
        <params>
          <param>{i}</param>
          <param>"on":true,"hue":{Rnd.1.65000},"bri":210,"sat":{Rnd.150.250}</param>
        </params>
        <cmdRepeat>3</cmdRepeat>
      </action>
    </else>
  </if>
  <event>MM.Playing</event>
</command>


Although I have no problem with using python scripts in VC, it always makes me happy when I can do it all in a regular macro!
Title: Re: Customized light effects: Philips Hue + MediaMonkey
Post by: OklahomaGreyBeard on May 13, 2015, 06:57:05 PM
Worked great for me. I changed the group to 3 for my lights and in my case had to change it to change the three lights individually rather than a loop because the lights are numbered 1,4,5 on the hub.

At this point I have 26 lights on this hub with only 9 of them actual hue full color lights. There's no reason to have the hallway lights turn on and purple when a song plays.  :biglaugh 

I have those as full color and use  motion detectors so if anyone gets up in the middle of the night for the bathroom, it turns on red as low as they will go so you can see but it doesn't kill your eyes and wake you up any more than you already are.  They also come in handy here in Oklahoma when my weather radio gets triggered for a storm or tornado and the external trigger now fires the Red Alert command in VC.