No announcement yet.

Off by Location Script for HS3

  • Filter
  • Time
  • Show
Clear All
new posts

    Off by Location Script for HS3

    I am not going to try to say this script is pretty or even well written, but thought some others might be interested in it anyway.

    Basically, this is a vb script called with 2 parameters:
    - the first is the case sensitive location
    - the second is True if you want it to speak the actions taken

    One note, this script looks for Device Types with specific keyword in that string to determine if they are a switch/light or something else like a thermostat. You may need to update that near line 31 or so.

    If anyone want to clean it up some or add other features, I am cool with that...just repost your code for others.

    Sub Main(ByVal Parms As object)
    '*** Off by Location script
    '*** Version 1.00  - Mike Israels
    'Parameter 0 - Location2 value, case sensitive
    'Parameter 1 - if True, script will speak actions when turning off a light
    	Dim ParmArray() as String
    	ParmArray = parms.tostring.split(",")
    	Dim loc = ParmArray(0)
    	Dim speak = ParmArray(1)
    	Dim logName = "Off by Loc"
    	Dim debug = False
    	Dim dev_switch as Boolean
    	Dim isOffCAPI as Boolean
    	Dim CallCAPI, dv, dev_type, dev_stat
    	Dim intValue, intDevRef, objDev, devName
    	Dim en = hs.GetDeviceEnumerator
    	hs.writelog (logName, "Checking for any lights that are not OFF for location2= " & loc & ", Speak= " & speak)
    		dv = EN.GetNext
    		If dv Is Nothing Then Continue Do
    			if dv.Location2(nothing) = loc then
    				intDevRef = dv.ref(nothing)
    				devName = dv.Location2(nothing) & " " & dv.Location(nothing) & " " & dv.Name(nothing)
    				dev_type = dv.Device_Type_String(nothing)
    				' --- check to see if the device type contains some word that makes us realize it is a switch of sorts
    				dev_switch = False
    				if dev_type.contains("Switch") or dev_type.contains("Dimmer") or dev_type.contains("LampLinc") then
    					dev_switch = True
    					if debug then hs.writelog (logName, devName & " is a Switch")
    					if debug then hs.writelog (logName, devName & " is NOT a Switch")
    				end if
    				intValue = hs.DeviceValueEx(intDevRef)
    				objDev = hs.GetDevicebyRef(intDevRef)
    				'--- check to see if the device is off only if it is a switch
    				if dev_switch = True then
    					IsOffCAPI = False
    					For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
    				   		If intValue = objCAPIControl.ControlValue Then
    							If LCase(objCAPIControl.Label) = "off" Then
    								IsOffCAPI = True
    							End If
    							Exit For
    						End If
    					if IsOffCAPI then
    						if debug then hs.writelog (logName, devName & " is already OFF")
    						hs.writelog (logName, devName & " is not off...sending OFF command.")
    						if speak="True" then hs.speak ("Turning off " & devName)
    						'--- turn the device off
    						CallCAPI = CAPIControlResponse.Indeterminate
    						For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
    							If LCase(objCAPIControl.Label) = "off" Then
    								CallCAPI = hs.CAPIControlHandler(objCAPIControl)
    								Exit For
    							End If
    					end if     'if IsOffCAPI
    				end if     'if dev_switch
    			end if     'if dv.Location2
    	Loop Until EN.Finished
    End Sub
    HS Install Date: Feb. 16, 2007

    HS3 Pro, Z-Wave, Insteon, BLStat, HS Touch Server, MyQ

    WeatherXML, BLBackup, BLLAN, BLLock, Restart, CaddX, OpenSprinkler