SLIMP3 integration in Indigo 2

Posted on
Tue Sep 12, 2006 1:24 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

SLIMP3 integration in Indigo 2

After submitting a picture of my Control Page for my SLIMP3, JohnConrader and morps asked how I did it.
So here's a "small" tutorial for SLIMP3 integration in Indigo.
This will probably work for the SqueezeBox as well, but as I don't have one of these, I can't tell for sure. However, donations are welcome... :wink:

The end result wil be a control page like this:

Image

What do you need?
- Indigo 2.0
- SlimServer 6.x
- A SLIMP3 (or SqueezeBox) player
- The SlimServer script
- A couple of action groups, variables and a time/date action
- A control page and some extra buttons

Indigo 2.0, SlimServer 6.x and the SLIMP3 need to be up and running and fully functional. Indigo and the SlimServer do not need to run on the same machine. As long as Indigo can connect to the IP adress of the computer where the SlimServer is running.

Installing the SlimServer script
The SLIMP3 will be controled by Indigo via AppleScript. To do this, you will need the SlimServer script posted below. This script is based upon the original SlimServer script posted here by Andrew Turner.

Code: Select all
--SlimServer control attachment
--
-- This script provides functions for easily controlling
-- a SlimDevices SLIMP3 or Squeezebox from IndigoActions
--
-- Author: Andrew Turner (software at highearthorbit dot com)
-- Changes: Paul Roomberg (paul at pasaro dot nl)
--
-- Examples:
-- SlimServerCommand("play")
-- SlimServerDisplay("Security", "Security Alarm Set")
--
-- Available commands: play, pause, stop, sleep

property defaultHost : "<IP>"
property defaultPort : "9000"
(* How long to display text *)
property defaultSeconds : "10"

property responseText : ""

using terms from application "IndigoServer"
   
   on SlimServerCommand(theCommand)
      SendToSlimServer(theCommand, 0, 0, 0)
   end SlimServerCommand
   
   on SlimServerDisplay(displayString1, displayString2)
      set lineOne to searchReplaceText(" ", "%20", displayString1)
      set lineTwo to searchReplaceText(" ", "%20", displayString2)
      SendToSlimServer("display", lineOne, lineTwo, defaultSeconds)
   end SlimServerDisplay
   
   on SlimServerVolume(volume)
      SendToSlimServer("mixer", "volume", volume, 0)
   end SlimServerVolume
   
   on SlimServerPlaySong(songName)
      SendToSlimServer("playlist", "play", songName, 0)
      getSlimStatus()
   end SlimServerPlaySong
   
   on SlimServerSkipFwd()
      SendToSlimServer("button", "jump_fwd", 1, 0)
      getSlimStatus()
   end SlimServerSkipFwd
   
   on SlimServerSkipRew()
      SendToSlimServer("button", "jump_rew", 0, 0)
      getSlimStatus()
   end SlimServerSkipRew
   
   on SlimServerPower(onOff)
      SendToSlimServer("power", onOff, 0, 0)
      getSlimStatus()
   end SlimServerPower
   
   on SlimServerGetStatus()
      SendToSlimServer("status", 0, 0, 0)
      getSlimStatus()
   end SlimServerGetStatus

   on getSlimStatus()
      set value of variable "SlimStatus1" to the first paragraph of responseText
      set value of variable "SlimStatus2" to the last paragraph of responseText
   end getSlimStatus
   
end using terms from

on SendToSlimServer(p0, p1, p2, p3)
   set h to "http://" & defaultHost & ":" & defaultPort & "/status.txt"
   set d to h & "?p0=" & p0
   if p1 is not equal to 0 then
      set d to d & "&p1=" & p1
   end if
   if p2 is not equal to 0 then
      set d to d & "&p2=" & p2
   end if
   if p3 is not equal to 0 then
      set d to d & "&p3=" & p3
   end if
   set responseText to do shell script "curl --get -d --url \"" & d & "\" "
   --alert("Server says: " & responseText)
end SendToSlimServer

(*
searchReplaceText(searchTerm, replaceTerm, theText)
Replaces a string found in a text by another string.
This handle supports lists of search/replace terms.

Parameters:
searchTerm: the text to search for
replaceTerm: the text to use as replacement
theText: the text to search/replace

Examples:
searchReplaceText("foo", "bar", "You are a foo") --> "You are a bar"
searchReplaceText({"foo", " a "}, {"bar", " one "}, "You are a foo") --> "You are one bar"
*)

to searchReplaceText(searchTerm, replaceTerm, theText)
   set searchTerm to searchTerm as list
   set replaceTerm to replaceTerm as list
   set theText to theText as text
   
   set oldTID to AppleScript's text item delimiters
   repeat with i from 1 to count searchTerm
      set AppleScript's text item delimiters to searchTerm's item i
      set theText to theText's text items
      set AppleScript's text item delimiters to replaceTerm's item i
      set theText to theText as text
   end repeat
   set AppleScript's text item delimiters to oldTID
   
   return theText
end searchReplaceText


Open the ScriptEditor. You can find it in the AppleScript folder inside your Programs folder.
Copy the code above and paste it into the empty script window.
Change the property defaultHost so it containts the IP address of the computer where your SlimServer is running. If you changed the default port to something else than 9000, change that property also.
Save the script as "SlimServer.scpt" into the Indigo Scripts folder. It's in Library>Application Support>Perceptive Automation>Indigo 2>Scripts>Attachments on the Mac where the Indigo Server is running.

Start an Indigo Client and select Reload Attachments from the Scripts menu.
You'll see a list of scripts being loaded in the log window. Your SlimServer script should appear in this list.

At this point, everything is in place for the integration of the SLIMP3 with Indigo.
So now it's time to let Indigo control the SLIMP3.

Create actions groups, variables and the time/date action
For the control page to work, Indigo must be able to:
- Start playing a song on the SLIMP3
- Forward to a new song
- Rewind to a previous song
- Change the volume
- Power Off the SLIMP3

For each of these actions, an action group will be made.

Start playing a song on the SLIMP3
Create a new Action Group and name it "SlimServer On".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
SlimServerCommand("play")
SlimServerVolume(value of variable "SlimVolume")
set value of variable "SlimPower" to "on"


Power Off the SLIMP3
Create a new Action Group and name it "SlimServer Off".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
SlimServerPower(0)
set value of variable "SlimPower" to "off"


Skip to the previous song
Create a new Action Group and name it "SlimServer Rew".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
SlimServerSkipRew()


Skip to the next song
Create a new Action Group and name it "SlimServer Fwd".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
SlimServerSkipFwd()


Raise the volume
Create a new Action Group and name it "SlimServer VolumeUp".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
set newVol to ((value of variable "SlimVolume") + 10)
if newVol > 100 then set newVol to 100
SlimServerVolume(newVol)
set value of variable "SlimVolume" to newVol


Lower the volume
Create a new Action Group and name it "SlimServer VolumeDown".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
set newVol to ((value of variable "SlimVolume") - 10)
if newVol < 0 then set newVol to 0
SlimServerVolume(newVol)
set value of variable "SlimVolume" to newVol


Get the status as displayed on the SLIMP3
Create a new Action Group and name it "SlimServer Status".
Give it a type of AppleScript and enter the following embedded code:

Code: Select all
SlimServerGetStatus()


The next step is to create the four variables which are used in the code above.
The first one is named "SlimVolume". Give it a value of 100.
The second is named "SlimPower". Give it a value of "off".
Then define "SlimStatus1" and "SlimStatus2" and leave their values empty.

Now it's time to define the time/date action. This will retrieve the SLIMP3 status every minute so it can be displayed in the control page.

Define a new Time/Date Action and name it "SlimServer Status".
Enter Every 0 hours 1,00 minutes in the Time section.
Enter Every 1 days in the Date section.

Go to the Actions tab and change the Type to Execute AppleScript.
Enter the following embedded code:

Code: Select all
if value of variable "SlimPower" = "on" then
    SlimServerGetStatus()
else
    set value of variable "SlimStatus1" to ""
    set value of variable "SlimStatus2" to ""
end if


From now on, everytime you turn on your SLIMP3 using Indigo, the contents on the display will be available in the variables SlimStatus1 and SlimStatus2. If you want a more up-to-date reading of the display, lower the interval. But keep in mind that this might affect the way Indigo responds to other events.

And now it's time to draw the picture!

Define the control page
To define the control page as shown at the beginning of this tutorial, you need three extra buttons.
Ctrl-Click on these buttons and save them to the folder where Indigo stores it's images.
This is Library>Application Support>Perceptive Automation>Indigo 2>IndigoWebServer>images>controls>static.

Image Image Image

Define a new Control Page and name it "SLIMP3".

Add a new item to the page and set Display to "Static Image / Caption".
Choose "iTunesFace.png" for the image and clear the Caption field.
Set the Click Action to "None".

Add another new item the page. Keep the Display to "Static Image / Caption".
Choose "iTunesPlay_small.png" for the image and position it on the iTunes Face.
Clear the Caption field.
Set the Click Action to "Execute Action Group" and select the Action Group "SlimServer On" in the pop-up window.

Repeat this step to add the following images to the iTunes Face and connect them to their Action Groups:

Power_small.png => SlimServer Off
iTunesRW_small.png => SlimServer Rew
iTunesFF_small.png => SlimServer Fwd
VolumeDownLeft.png => SlimServer VolumeDown
VolumeUpRight.png => SlimServer VolumeUp

To get some info on the "LCD display", we need to display the variables SlimStatus1 and SlimStatus2.

Add a new item to the page and set Display to "Variable Value".
Choose SlimStatus1 for the variable to display.
Display as text with centered alignment, font Verdana, size 10.
Change the color to gray 50%.
Clear the caption field and set the Click Action to "None".

Drag this field on top of the iTunesFace so it fits in the top half of the "LCD display".
Make it as wide as possible using the control in the lower right corner.

Duplicatie this item and make it display the variable SlimStatus2.
Drag this field down, so it fits in the lower half of the "LCD display".

Click the Updat button to save your Control Page.

That's it!

I did not completely test this tutorial, so if you find any errors or ommisions, please send a PM and I'll fix as soon as possible.
Last edited by macpro on Thu Sep 14, 2006 7:39 am, edited 4 times in total.

Posted on
Tue Sep 12, 2006 1:26 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: SLIMP3 integration in Indigo 2

Awesome! Thanks for posting this!

Matt

Posted on
Tue Sep 12, 2006 1:33 pm
pwfletcher offline
Posts: 179
Joined: Jul 19, 2006

(No subject)

Hey ... great script. I just created a new thread just for scripts. Will you post it there as well?

Thanks :)
http://www.humanovation.com
Last edited by pwfletcher on Mon Dec 05, 2011 12:34 am, edited 1 time in total.

Posted on
Tue Sep 12, 2006 1:36 pm
JohnConrader offline
Posts: 54
Joined: Dec 16, 2004
Location: Florida

(No subject)

Thanks a lot for this. I will be trying it out later today.

-john

Posted on
Wed Sep 13, 2006 7:42 am
morps offline
Posts: 122
Joined: Nov 01, 2003

(No subject)

Thanks for posting this one... but I'm having some bad experiences. After placing the script in the path defined, I tried to run the script from the Scripts menu item it kills the Indigo 2.0 server:

Here is a dump from the Console:
2006-09-13 06:32:21.626 Indigo 2[749] syncScriptMenu() caught exception: ServerCommunicationError -- timeout waiting for server response
2006-09-13 06:34:25.456 IndigoServer[259] ProcessPacketStream() caught exception: ShuttingDownError -- Indigo Server shutting down

I then moved the script to the Attachments folder, reloaded and tried Running the SlimServer on Action (hitting the Run button in the script). Then here is what happened:

Indigo 2.0 log:
Error (client) scriptRunHit() caught exception: ServerCommunicationError -- timeout waiting for server response

Finally: I have also noticed that I am getting an error with the SlimServer Status Time/Date action. I am getting:

Time/Date Action SlimServer Status
Error script error: The variable SlimPower is not defined.

...however it is in fact defined in the Variables list.

Any ideas?

Posted on
Wed Sep 13, 2006 8:17 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

morps wrote:
Thanks for posting this one... but I'm having some bad experiences. After placing the script in the path defined, I tried to run the script from the Scripts menu item it kills the Indigo 2.0 server...

A few notes.

First, you are correct -- the script goes in the scripts/attachments/ folder, not the scripts/ folder (MacPro -- can you correct the instructions?).

You might want to try commenting or removing this line from the attachment script:

   SlimServerDisplay("Indigo", "Up and running")

A better place for that line might be in a startup Trigger Action.

The error "The variable SlimPower is not defined" means that you probably don't have quotes around SlimPower inside one of your scripts. Instead of this:

   set value of variable SlimPower to "on"

you should have:

   set value of variable "SlimPower" to "on"

Lastly, try running an example from the Script Editor instead of Indigo. Something like this:

  tell app "IndigoServer"
     SlimServerCommand("play")
  end tell

Does the above work?

Regards,
Matt

Posted on
Wed Sep 13, 2006 8:36 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

support wrote:
First, you are correct -- the script goes in the scripts/attachments/ folder, not the scripts/ folder (MacPro -- can you correct the instructions?).

Done! Sorry for that.

Posted on
Thu Sep 14, 2006 7:03 am
morps offline
Posts: 122
Joined: Nov 01, 2003

(No subject)

support wrote:
You might want to try commenting or removing this line from the attachment script:

   SlimServerDisplay("Indigo", "Up and running")

A better place for that line might be in a startup Trigger Action.


It seems that was the trick. I now have it working. I went through all the scripts and everything was setup correct. Well, I'm good now. Thanks Matt for the help!

Posted on
Thu Sep 14, 2006 7:40 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

I've removed the display line from the script, so future users will not run into this problem.

Posted on
Thu Sep 14, 2006 9:12 am
gmusser offline
Posts: 290
Joined: Feb 12, 2005
Location: New Jersey

(No subject)

This is great!

Out of curiosity, has anyone gone the other direction and used a Squeezebox to control lights via Indigo?

George

Posted on
Thu Sep 14, 2006 9:17 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Shameless plug for FunForGeeks.com

With all of this talk about using the SliMP3 (latest version is called the Squeezebox) with Indigo, I thought now would be a great time to put in a shameless plug for FunForGeeks.com our primary Indigo reseller and Mac centric home automation store. They have the Squeezebox in stock now. It *really* is the an awesome (and sexy) solution for streaming music from your Mac to your A/V equipment.

Image

Regards,
Matt

Posted on
Thu Sep 28, 2006 8:38 am
ajturner offline
Posts: 160
Joined: Jul 10, 2005
Location: Washington, DC

(No subject)

gmusser wrote:
This is great!

Out of curiosity, has anyone gone the other direction and used a Squeezebox to control lights via Indigo?


Started to write a plugin for doing this - but never quite got it finished. I'll dig up what I had going and put it up here or on the wiki.

Control Indigo from anywhere in the world:
http://highearthorbit.com/software/indigowidget

Posted on
Mon Nov 20, 2006 2:47 pm
nsosnicki offline
Posts: 168
Joined: Nov 14, 2004
Location: Boston, MA, US

(No subject)


Posted on
Wed Feb 04, 2009 11:15 am
editordz offline
Posts: 67
Joined: Dec 01, 2006
Location: Sherman Oaks, CA

SqueezeCenter/SqueezePlay

Thanks for this script! I'm happy to report it works like a charm on my SqueezeCenter/SqueezePlay Beta setup.

Cheers,
Dan

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 22 guests