Haiku HaikuHelper and OmniPro II Announcements

cyerye

Member
I have an OmniPro II and my family uses Haiku as the main interface with it. I don't have anyway of making announcements in the house or whole house audio. I do have three stereos with airplay and use that to play music in the house. The next feature I would like to add is announcements through the OmniPro II in the main living areas.  Can HaikuHelper make announcements for OmniPro II through airplay and would I need 2-way voice module to do this? Also, can HaikuHelper integrate with Sonos to make announcements?
 
You can use the scripting functionality of HaikuHelper to say or speak things, I use this pretty heavily, using event triggers and various times of day to read the weather for the day, say the time, read my calendar appointments etc... I do all of this from a mac mini, that uses airplay connected to my whole house audio. Its pretty straight forward, I can share some examples if you need them. 
 
As far as integrating HH with Sonus, I don't use the Sonus product but if they have an API, you should be able to tap into that to do some various things. 
 
Let me know if you would like some samples or guidance. 
 
Thanks evanlifetv - Could you share some of your examples? I'm using an iMac to run HaikuHelper and I use two airport expresses and a receiver with airplay to play music in house through iTunes.  Using HaikuHelper to make announcements would eliminate my need for the 2 way voice module and the two microphone / speakers from HAI.
 
cyerye said:
Thanks evanlifetv - Could you share some of your examples? I'm using an iMac to run HaikuHelper and I use two airport expresses and a receiver with airplay to play music in house through iTunes.  Using HaikuHelper to make announcements would eliminate my need for the 2 way voice module and the two microphone / speakers from HAI.
 
Sure thing, a little background:
 
From PcAccess, I have a flag that resets at 2pm each day, and then an action that basically determines using this flag if its my first time home after 5:00, if that makes sense, it also turns some lights on, lights the fireplace if its cold outside and of course trips the flag for me and activates a button called "Evening Update" (pretty straight forward HAI programming)
 
At the same time as all of that stuff, Haiku does a simple 'If Zone trips Not Ready' Then I use this:
 

function onButtonActivate(button) {
if(button.name == 'Forecast') {
helper.executeAppleScript(controller, 'tell application "evening_update" to activate');
}
}


'evening_update' is just an applescript application containing the following:
 


--this is the city code. Search the code for your city on http://weather.yahoo.com/
set CityCode to 11111111
--temperature format
set t_format to "F"
--voiceover format
set v_format to "L"
--say present condition
set a_format to "Y"

set IURL to "http://weather.yahooapis.com/forecastrss?w=" & CityCode

--downloading the file using curl
set file_content to (do shell script "curl " & IURL)
--looking for the line with actual condition
set theText to text ((offset of "yweather:condition" in file_content) + 1) thru -1 of file_content
set sub_1 to text ((offset of "\"" in theText) + 1) thru -1 of theText

--today conditions found
set actual_condition to text 1 thru ((offset of "\"" in sub_1) - 1) of sub_1

--looking for actual temperature temperature
set sub_1a to text ((offset of "temp=" in sub_1)) thru -1 of sub_1
set sub_1b to text ((offset of "\"" in sub_1a) + 1) thru -1 of sub_1a
set actual_temp to text 1 thru ((offset of "\"" in sub_1b) - 1) of sub_1b

if t_format is equal to "C" then
set actual_temp to (5 / 9) * (actual_temp - 32) as integer
end if

--looking for today forecast
set theText to text ((offset of "yweather:forecast" in file_content) + 1) thru -1 of file_content
set sub_2 to text ((offset of "\"" in theText) + 1) thru -1 of theText

--maximum and minimum temperatures found
set today_min_temp to word 9 of sub_2
set today_max_temp to word 12 of sub_2
if t_format is equal to "C" then
set today_min_temp to (5 / 9) * (today_min_temp - 32) as integer
set today_max_temp to (5 / 9) * (today_max_temp - 32) as integer
end if

--looking for today forecast condition (a bit tricky)
set sub_3 to text ((offset of "text" in sub_2) + 1) thru -1 of sub_2
set sub_4 to text ((offset of "\"" in sub_3) + 1) thru -1 of sub_3
set today_forecast to text 1 thru ((offset of "\"" in sub_4) - 1) of sub_4

--looking for tomorrow forecast
set sub_5 to text ((offset of "yweather:forecast" in sub_4) + 1) thru -1 of sub_4
set sub_6 to text ((offset of "\"" in sub_5) + 1) thru -1 of sub_5

--maximum and minimum temperatures found
set tomorrow_min_temp to word 9 of sub_6
set tomorrow_max_temp to word 12 of sub_6
if t_format is equal to "C" then
set tomorrow_min_temp to (5 / 9) * (tomorrow_min_temp - 32) as integer
set tomorrow_max_temp to (5 / 9) * (tomorrow_max_temp - 32) as integer
end if

--looking for tomorrow forecast condition (a bit tricky)
set sub_7 to text ((offset of "text" in sub_6) + 1) thru -1 of sub_6
set sub_8 to text ((offset of "\"" in sub_7) + 1) thru -1 of sub_7
set tomorrow_forecast to text 1 thru ((offset of "\"" in sub_8) - 1) of sub_8

--Get current time and make it speakable
set myhour to get the (hours of (current date)) as string
set myminutes to get the (minutes of (current date)) as string

-- add a leading zero to minutes
set minuteslength to (length of myminutes)
if minuteslength < 2 then
set myminutes to "0" & myminutes
end if

-- say the time
-- the colon makes it say, eg, 20 : 45 instead of 2 thousand 45

set volume output volume 100
tell application "iTunes"
set the sound volume to 75
end tell

-- Announce Time of Day
say "The time is " & myhour & ":" & myminutes using "Serena"
delay 1

--says the weather
say "Just an update. The weather currently is " & actual_temp using "Serena"
-- say "The remainder of the day is" & today_forecast using "Serena"
delay 1
say "Tomorrows Forcast is" & tomorrow_forecast using "serena"
delay 1
say "Your Remaining Reminders are:" using "Serena"
--says notes
say (do shell script "cat '" & "/Users/username/Desktop/Notes.txt" & "'") using "Serena"
tell application "iTunes"
set the sound volume to 100
end tell

Most of that code was adapted or tweaked from the now 'retired' (I believe) ProjectJarvis... There are others out there like it to get ideas. 
 
 
I also have a button called "Romance" that when pushed dims all my lights, turns on the fireplace, and fires off an iTunes playlist with some nice tunes.  :)
 
You can do this type of stuff a dozen ways, just pick the way you are most comfortable with and start typing, I could probably do all of this from within Haiku, but I already had the HAI stuff programmed before I started messing with Haiku, so I just left those in there.  
 
 
 
Here are something that might help as you start the applescript journey, with airplay:
     http://dougscripts.com/itunes/  (basic iTunes scripting)
     http://rogueamoeba.com/airfoil/mac/ (allow system audio via airplay)
 
 
Let me know if you have any specific questions, I'll help out where I can!
 
CJW-PIC said:
Thank you so much, if I may ask what editor do you use. CJW-PIC
I typically just use the applescript editor thats built into OSX, it resides inside your /Applications/Utilities/ folder.
 
evanlifetv said:
I typically just use the applescript editor thats built into OSX, it resides inside your /Applications/Utilities/ folder.
Thanks evanlifetv.  I've started working with the script and have it playing messages on my computer, how do you activate the different airplay stations?
 
how do you avoid the "the application is not running" return error with the applescript above?
 
Thanks
 
jrob said:
how do you avoid the "the application is not running" return error with the applescript above?
 
Thanks
Hey Jrob, I don't have that issue, the only thing I can think of is maybe when you are saving or exporting the script you aren't choosing the file format "application" option... Thats a stretch and a guess, but I haven't run into that issue.  The only other thing I could think of would be maybe "iTunes" isn't running, my iTunes starts at login, so I don't have this particular file set to "Activate" (launch) it first. Try one of those two things and let me know what you learn, I can help adopt it for your needs if needed. 
 
Thanks for your response.  My issue is not with itune but jus a simple script to select speakers in airfoil.  Script runs fine from iMac desktop but when called from HH runs but throws the following error:   "executeAppleScript(): AppleScript error: page speakers got an error: Application isn't running."  The script executes when called from HH but returns this error.
 
helper.executeAppleScript(controller, 'tell application "page speakers" to activate');
 
I have tried this in multiple areas from a pushbutton to onSyncStart().  The result is always the same.
 
AppleScript looks like this:
 
If application "Airfoil" is not running then
     tell application "Airfoil" to run
     delay 2
end if
 
tell application "Airfoil"
     set aSpeaker to "2026"
     set (volume of every speaker whose name starts with aSpeaker) to .80
     connect to (every speaker whose name starts with aSpeaker)
end tell
 
Back
Top