'// Automatiserar.se '// This script changes device status of your vera devices or sends value to sensors. '// '// Example of how to use it, turning the device #42 on: '// VeraDevice "42", "1" '// Example of turning device #42 off: '// VeraDevice "42", "0" '// '// Example of sending value 200 to a light sensor with de DeviceID 119. '// 'VeraLightSensor "119", "200" '// '// Example of how to use the script from the commandline to turn on device numer 42. '// cscript.exe vera.vbs 42 1 1 '// '// Example of how to use the script from the commandline to send the value 300 to a lightsensor with device number 119. '// cscript.exe vera.vbs 119 300 2 on error resume next Dim VeraIP, ObjHttp, ArgDeviceID, ArgValue, ArgType VeraIP = "192.168.1.24" Startup 'Function for creating variables and handle commandline arguments 'VeraDevice "42", "0" 'VeraLightSensor "119", "200" '---- Functions below this line ---- Sub StartUp on error resume next Set ObjHttp = CreateObject("MSXML2.XMLHTTP") if WScript.Arguments.Count = 0 then 'No command line was found. elseif WScript.Arguments.Count = 3 then ArgDeviceID = WScript.Arguments.Unnamed.Item(0) ArgValue = WScript.Arguments.Unnamed.Item(1) ArgType = WScript.Arguments.Unnamed.Item(2) if ArgType = 1 then VeraDevice ArgDeviceID, ArgValue end if if ArgType = 2 then VeraLightSensor ArgDeviceID, ArgValue end if end if end sub Sub VeraDevice (deviceid, status) on error resume next ObjHttp.open "GET", "http://" & VeraIP & ":3480/data_request?id=lu_action&output_format=xml&DeviceNum=" & DeviceID & "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=" & Status, False ObjHttp.send if err.number <> 0 then 'Found an error wscript.echo "Error when sending command to IP: " & veraip & " with the status: " & Status & " to the deviceid: " & deviceid & ". Error code: " & err.number & " " & err.description end if end sub Sub VeraLightSensor (deviceid, SensorValue) on error resume next 'ObjHttp.open "GET", "http://" & VeraIP & ":3480/data_request?id=lu_action&output_format=xml&DeviceNum=" & DeviceID & "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=" & Status, False ObjHttp.open "GET", "http://" & VeraIP & ":3480/data_request?id=variableset&DeviceNum=" & DeviceID & "&serviceId=urn:micasaverde-com:serviceId:LightSensor1&Variable=CurrentLevel&Value=" & SensorValue, False ObjHttp.send if err.number <> 0 then 'Found an error wscript.echo "Error when sending command to IP: " & veraip & " with the value: " & SensorValue & " to the deviceid: " & deviceid & ". Error code: " & err.number & " " & err.description end if end sub