The following script works to control lighting and some of the appliances in my sitting room using a form of logic. It actually takes more key presses this way than switching on/off each appliance but is fun, and can impress. you can also control a number of devices in one sentence.
I created a voice input variable, extract key control words by compairing lists (this allows a form of naturally speaking), convert that data back into a variable and then check the contents of that variable to undertake actions.
A button on the control page opens a variable text input box, you then tap the box so that it has focus, tap the keyboard microphone, dictate commands, tap the microphone to stop, and then hit done on the keyboard.
The number of key presses could be reduced if the variable box gained focus when it pops up, and the second press of the microphone could action "done" on the keyboard. I think this would need an update to the app though.
It will need adjusting to your particular set up, but i thought i would post incase anyone else fancies playing. I have a set of dmx led's and found it useful to extract out the colour control into a separate variable. The speed is great.
it allows you to say "please switch the tv off" or "turn the telly off, i'm going to bed" etc with the same result.
- Code: Select all
if value of variable "voicecontrol" = "" then stop
set tempvoice to (value of variable "voicecontrol")
--set variable to list
set AppleScript's text item delimiters to " "
set voicelist to every text item of tempvoice
--replace slang for command words in list
repeat with i from 1 to count voicelist
if voicelist's item i is "tv" then set item i of voicelist to "television"
if voicelist's item i is "telly" then set item i of voicelist to "television"
if voicelist's item i is "half" then set item i of voicelist to "30"
if voicelist's item i is "big" then set item i of voicelist to "main"
if voicelist's item i is "coloured" then set item i of voicelist to "colour"
end repeat
--extract key words from voice variable equal to the flollowing list
set itemstoretain to {"on", "off", "television", "lamp", "kitchen", "10", "15", "20", "30", "main", "colour"}
set voicefinal to {""}
repeat with i from 1 to count voicelist
if {voicelist's item i} is in itemstoretain then set voicefinal's end to voicelist's item i
end repeat
set voicefinal to voicefinal as string
-separate list for coloured LED lights
set itemscolourretain to {"pink", "orange", "purple", "yellow", "red", "green", "blue"}
set voicecolour to {""}
repeat with i from 1 to count voicelist
if {voicelist's item i} is in itemscolourretain then set voicecolour's end to voicelist's item i
end repeat
set voicecolour to voicecolour as string
if voicefinal contains " television on" or voicefinal contains " on television" then
turn on "Sitting room TV"
say "The television has been switched on"
end if
if voicefinal contains " television off" or voicefinal contains " off television" then
turn off "Sitting room TV"
say "The television has been switched off"
end if
if voicefinal contains " lamp on" or voicefinal contains " on lamp" then
turn on "Sitting room lamp"
say "The lamp has been switched on"
end if
if voicefinal contains " lamp off" or voicefinal contains " off lamp" then
turn off "Sitting room lamp"
say "The lamp has been switched off"
end if
if voicefinal contains " colour on" or voicefinal contains " on colour" then
turn on "Coloured lights"
say "The coloured lights have been switched on"
end if
if voicefinal contains " colour off" or voicefinal contains " off colour" then
turn off "Coloured lights"
say "The coloured lights have been switched off"
end if
if voicecolour = " green" then
turn on "Coloured lights"
execute group "DMX100"
say "The coloured lights are now green"
end if
if voicecolour = " yellow" then
turn on "Coloured lights"
execute group "DMX51"
say "The coloured lights are now yellow"
end if
if voicecolour = " red" then
turn on "Coloured lights"
execute group "DMX1"
say "The coloured lights are now red"
end if
if voicecolour = " orange" then
turn on "Coloured lights"
execute group "DMX26"
say "The coloured lights are now orange"
end if
if voicecolour = " blue" then
turn on "Coloured lights"
execute group "DMX192"
say "The coloured lights are now blue"
end if
if voicecolour = " purple" then
turn on "Coloured lights"
execute group "DMX235"
say "The coloured lights are now purple"
end if
if voicecolour = " pink" then
turn on "Coloured lights"
execute group "DMX304"
say "The coloured lights are now pink"
end if
if voicefinal contains " kitchen off" or voicefinal contains " off kitchen" then
turn off "Kitchen lights"
say "The kitchen lights have been switched off"
enable trigger action "kitchen light off"
end if
if voicefinal contains " kitchen on 30" or voicefinal contains " on kitchen 30" then
turn on "Kitchen lights"
brighten "Kitchen lights" to 100
disable trigger action "kitchen light off" for 30
say "The kitchen lights have been switched on for 30 minutes"
end if
if voicefinal contains " kitchen on 20" or voicefinal contains " on kitchen 20" then
turn on "Kitchen lights"
brighten "Kitchen lights" to 100
disable trigger action "kitchen light off" for 20
say "The kitchen lights have been switched on for 20 minutes"
end if
if voicefinal contains " kitchen on 15" or voicefinal contains " on kitchen 15" then
turn on "Kitchen lights"
brighten "Kitchen lights" to 100
disable trigger action "kitchen light off" for 15
say "The kitchen lights have been switched on for 15 minutes"
end if
if voicefinal contains " kitchen on 10" or voicefinal contains " on kitchen 10" then
turn on "Kitchen lights"
brighten "Kitchen lights" to 100
disable trigger action "kitchen light off" for 10
say "The kitchen lights have been switched on for 10 minutes"
end if
if voicefinal contains " kitchen on" or voicefinal contains " on kitchen" then
turn on "Kitchen lights"
brighten "Kitchen lights" to 100
disable trigger action "kitchen light off" for 10
say "The kitchen lights have been switched on for 10 minutes"
end if
if voicefinal contains " main off" or voicefinal contains " off main" then
turn off "sitting room ceiling sofa"
turn off "sitting room ceiling tv"
say "The sitting room main lights have been switched off"
end if
if voicefinal contains " main on" or voicefinal contains " on main" then
brighten "sitting room ceiling sofa" to 100
brighten "sitting room ceiling tv" to 100
say "The sitting room main lights have been switched on"
end if
set value of variable "voicecontrol" to ""