' Light_Control2_Quiet.txt 2000/01/31 Paul Fielding (paul.fielding@home.com) ' based on a most excellent script by Glenn Reimche (control@corpacc.com) ' ' One script to handle voice command of ON/OFF and DIM/BRIGHT of all lights, through parameter passing. ' Also allows of absolute setting of DIM level, in addition to more flexible grammar. ' ' With this script and the right voice command (see below) you can say (Assume the device name is FLOOR LAMP): ' ' FLOOR LAMP - toggles the current ON/OFF state of the device ' DIM FLOOR LAMP - dims the device the default percentage (passed as a parameter, see below) ' BRIGHTEN FLOOR LAMP - brightens the device to 100% ' DIM FLOOR LAMP 33 (or any other number between 1 and 99) - dims the device the spoken value ' BRIGHTEN FLOOR LAMP 66 (or any other number between 1 and 99) - brightens the device the spoken value ' SET FLOOR LAMP 50 (Sets the device to 50% DIM level, regardless of where it currently is) ' ' If you set the voice command property as shown below, you can also be quite flexible in how you request the ' command. For example, you can say "Turn on the floor lamp", or "Turn the floor lamp on", "Turn on floor lamp", ' or "Floor lamp off". You can also use phrases like "Dim the floor lamp 20 percent", or "Set the floor lamp ' to 40 percent". The word percent is of course optional. ' As a catch-all, you can say "Dim the floor lamp **TO** 75 percent" to set an absolute value as well, though ' you're probably better off using SET, as it makes for easier VR. ' ' Currently the script is in quiet mode, but if you like having the computer talk back, just uncomment the ' speak line near the bottom of the script. ' ' How to use: ' ' Create an event for the device ' ' In the voice command property for the event, create this entry: ' [opt] (brighten|dim|turn|set) [opt] (on | off) [opt] the floor lamp [opt] (on | off | to) [opt] (0|10|11|12|13|14|15|16|17|18|19|20|30|40|50|60|70|80|90|100) [opt] (1|2|3|4|5|6|7|8|9) [opt] percent ' ' This is one long entry, spacing is important. ' Your best bet is to copy and paste the above command (excluding the ' ) ' ' Change the name of the device you want to speak (eg. Change Floor Lamp to TABLE LAMP ) ' ' Set the event to run this script ' ' Under the App/Sound/Email tab: (THIS IS VERY IMPORTANT) ' In the mail message, enter one parameter per line as: ' devicecode=A6 ' devicename=Table Lamp ' percent=15 ' ' DeviceName is used only for speaking. ' percent is the default dim amount if none is explicitly spoken ' ' ' includes : ' ' getParms - Fake parameter reading - 11/15/99 Rick LaBanca, ' http://members.home.com/rickla1/ha ' ' You need Rick's excellent scripts (ut.zip) to make this work! ' #include ut_getparms.txt sub main() dim command, devicecode, devicename, action, word dim say1, percent, current, state, default, vars, orig percent = 0 ' Ricks's stuff to get the paramaters from the email message set vars = CreateObject("Scripting.Dictionary") getParms(vars) devicecode = vars("devicecode") devicename = vars("devicename") default = vars("percent") ' Get the status of the device state = hs.DeviceStatus(devicecode) current = hs.DeviceValue(devicecode) ' Get the voice command, which may include a DIM or BRIGHT command, plus up to two percentage parameters command = ah.LastVoiceCommand ' Get the first word action = LCASE(trim(hs.stringItem(command, 1, " "))) ' Determine optional Bright or Dim action IF action = "brighten" THEN action = "bright" End IF IF action = "bright" or action = "dim" or action = "set" THEN count = 1 ELSE count = 1 action = "TOGGLE" END IF ' Loop through all words in the command, looking for numbers ' All numbers are added to form the percentage value for a Bright/Dim command DO count = count + 1 word = trim(hs.stringItem(command, count, " ")) IF word = "to" THEN action = "set" END IF IF IsNumeric(word) THEN percent = percent + abs(word) END IF LOOP UNTIL word = "" ' Bright action IF action = "bright" THEN IF percent = 0 THEN percent = 100 say1 = devicename + " full brightness" ELSE say1 = "Brighten " + devicename + CStr(percent) + " percent." END IF END IF ' Dim action IF action = "dim" THEN IF percent = 0 THEN percent = default END IF say1 = devicename + " dimmed " + CStr(percent) + " percent." END IF ' Absolute dimming IF action = "set" then orig = percent if state = 2 or state = 3 then action = "dim" percent = 100 - percent elseif state = 4 and percent > current then action = "bright" percent = percent - current elseif state = 4 and current > percent then action = "dim" percent = current - percent elseif state = 4 and percent = current then action = "" percent = 0 end if say1 = devicename + " set to " + CStr(orig) + " percent." END IF ' Turn On or Off IF action = "TOGGLE" THEN ' Set the new state based on the current state if state = 3 then action = "on" else action = "off" end if say1 = devicename + " " + action END IF ' Perform the action ah.execx10 devicecode,action,percent ' Say what just happened ' hs.speak say1 end sub