' Light_Control.txt 2000/01/23 Glenn Reimche (control@corpacc.com)'' One script to handle voice command of ON/OFF and DIM/BRIGHT of all lights, through parameter passing.'' 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)' BRIGHT 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' BRIGHT FLOOR LAMP 66 (or any other number between 1 and 99) - brightens the device the spoken value'' How to use:'' Create an event for the device'' In the voice command property for the event, create this entry:' [opt] (BRIGHT|DIM) Floor Lamp [opt] (10|11|12|13|14|15|16|17|18|19|20|30|40|50|60|70|80|90) [opt] (1|2|3|4|5|6|7|8|9)' ' 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!'' acknowledge - Random spoken acknowlegements of give command.' Requires my script, acknowledge.txt' This is optional, and may be removed from the code.' To Remove, delete these two lines:' #include acknowledge.txt' acknowledge()#include acknowledge.txtsub main() dim command, devicecode, devicename, action, word dim say1, percent, default, vars percent = 0' Call random acknowledgement of command acknowledge()' 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 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 = "bright" or action = "dim" 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 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' Turn On or Off IF action = "TOGGLE" THEN ' Set the new state based on the current state if ah.ison(devicecode) then action = "off" else action = "on" end if say1 = devicename + " " + action END IF' Say what is about to happen hs.speak say1' Perform the action ah.execx10 devicecode,action,percentend sub ' ' getParms - Fake parameter reading - 2/29/00 Rick LaBanca, http://www.homeautomationforum.com ' ' Due to no parameter passing by homeseer, here's a hack! ' ' - Put your parameters into the mail subject as: ' firstkey=hello ' secondkey=swell ' - include this in your script(s) to run ' - Call getParms to get a dictionary with your settings ' ' The main() here is for a sample and for you to test with. #include ut_readline.txt sub main() dim vars set vars = CreateObject("Scripting.Dictionary") getParms(vars) MsgBox("firstkey = " + vars("firstkey")) MsgBox("secondkey = " + vars("secondkey")) end sub sub getParms(byref dict) dim src ev_count = hs.EventCount for i=1 to ev_count set ev=hs.GetEvent(i) if ev.name = hs.GetLastEvent then src = ev.ev_mail_message exit for end if next dim line ptr = 1 do while ptr <= len(src) line = readLine(src, ptr) dict.add trim(hs.stringItem(line, 1, "=")), trim(hs.stringItem(line, 2, "=")) loop end sub