{"data-align":"none","data-attachmentid":"1401556","data-size":"thumb"} Has anyone used the feature to run a script whenever a device changes using the ScriptName and ScriptFunc properties in the DeviceClass object?
I am trying to trigger a script from a device change using the ScriptName and ScriptFunc properties in the DeviceClass object to save having to put in a bunch of events (for a bunch of devices). I wrote the following little script as a test with one device:
Sub SetDevices(Parm as Object)
Dim hsdev As Scheduler.Classes.DeviceClass
Dim devType
Dim Devrf = ZMDev
hsdev = CType(hs.GetDeviceByRef(Devrf), Scheduler.Classes.DeviceClass)
devType = hsdev.DeviceType_Get(hs)
devType.Device_API = HomeseerAPI.DeviceTypeInfo.eDeviceAPI.Script
devType.Device_Type = 1 ; run on any change
hsdev.DeviceType_Set(hs) = devType
hsdev.ScriptName(hs) = "StatusScript.vb"
hsdev.ScriptFunc(hs) = "DevUpdate"
hs.SaveEventsDevices
end sub
And then I ran it. Based on the screenshot below it appears to have worked (the device type says it is to run a script on any change). But when the device changes, I am not getting into the script and there is nothing in the log except the normal message saying there was a device change from the CAPI handler. (I also but the full path in the ScriptName but stil no luck.
DevUpdate, for now, is a very simple script just so I can see it is working (or not in this case):
Public Sub DevUpdate( Parm as object)
hs.writelog("test", "In DevUpdate")
hs.writelog("DevUpdate", "Parm(0)="&parm(0))
hs.writelog("DevUpdate", "Parm(1)="&parm(1))
hs.writelog("DevUpdate", "Parm(2)="&parm(2))
hs.writelog("DevUpdate", "Parm(3)="&parm(3))
end sub
Nothing shows up inthe log when I change the device from the Homeseer UI nor when the device is changed programmatically from a script. I have a bunch of devices that all need to run the same schript whern they change---this seemed so much simpler than having events for each device. Is there something simple I am doing wrong
I am trying to trigger a script from a device change using the ScriptName and ScriptFunc properties in the DeviceClass object to save having to put in a bunch of events (for a bunch of devices). I wrote the following little script as a test with one device:
Sub SetDevices(Parm as Object)
Dim hsdev As Scheduler.Classes.DeviceClass
Dim devType
Dim Devrf = ZMDev
hsdev = CType(hs.GetDeviceByRef(Devrf), Scheduler.Classes.DeviceClass)
devType = hsdev.DeviceType_Get(hs)
devType.Device_API = HomeseerAPI.DeviceTypeInfo.eDeviceAPI.Script
devType.Device_Type = 1 ; run on any change
hsdev.DeviceType_Set(hs) = devType
hsdev.ScriptName(hs) = "StatusScript.vb"
hsdev.ScriptFunc(hs) = "DevUpdate"
hs.SaveEventsDevices
end sub
And then I ran it. Based on the screenshot below it appears to have worked (the device type says it is to run a script on any change). But when the device changes, I am not getting into the script and there is nothing in the log except the normal message saying there was a device change from the CAPI handler. (I also but the full path in the ScriptName but stil no luck.
DevUpdate, for now, is a very simple script just so I can see it is working (or not in this case):
Public Sub DevUpdate( Parm as object)
hs.writelog("test", "In DevUpdate")
hs.writelog("DevUpdate", "Parm(0)="&parm(0))
hs.writelog("DevUpdate", "Parm(1)="&parm(1))
hs.writelog("DevUpdate", "Parm(2)="&parm(2))
hs.writelog("DevUpdate", "Parm(3)="&parm(3))
end sub
Nothing shows up inthe log when I change the device from the Homeseer UI nor when the device is changed programmatically from a script. I have a bunch of devices that all need to run the same schript whern they change---this seemed so much simpler than having events for each device. Is there something simple I am doing wrong
Comment