Nice work Mark. I'll have to finish looking everything over this week.
Everything I'm using still functions as expected. Since I was testing things again, I noticed one case my code under sys://Schema/Modules/Leviton/Classes/Switch/OnChangePowerState wasn't handling correctly: when a user dims to 0 brightness, then turns a lamp back on, NxxxON was being sent instead of NxxxLxx (which is needed for the brightness in Premise to match that of the light since a dimmer will default to minimum brightness defined within the dimmer itself).
Code is below, but I'm also attaching a txt file with the code for you to paste into your version since I think the tabs will be messed up otherwise. The flow is getting a little confusing, but vbscript doesn't have a support go to statements
EDIT: I cleaned up the code a little more.
Everything I'm using still functions as expected. Since I was testing things again, I noticed one case my code under sys://Schema/Modules/Leviton/Classes/Switch/OnChangePowerState wasn't handling correctly: when a user dims to 0 brightness, then turns a lamp back on, NxxxON was being sent instead of NxxxLxx (which is needed for the brightness in Premise to match that of the light since a dimmer will default to minimum brightness defined within the dimmer itself).
Code is below, but I'm also attaching a txt file with the code for you to paste into your version since I think the tabs will be messed up otherwise. The flow is getting a little confusing, but vbscript doesn't have a support go to statements
EDIT: I cleaned up the code a little more.
Code:
'
dim sCmd, iLevel
if this.ReceivingUpdate = false then
'debugout "SourceElementName: " & sysevent.srcElement.Name & ", SourcePropertyName: " & sysevent.srcProperty.name
' Handle dimmer type
' Ignore requests from Brightness changes because OnChangeBrightness will handle
' the task of turning a dimmer on or off.
if this.IsOfExplicitType("sys://Schema/Modules/Leviton/Classes/Dimmer") then
this.PowerStateChanging = true
' Use brightness changing flag to avoid using sysevent.srcproperty since "trigger" is src property for macros
if this.BrightnessChanging = false then
iLevel = round(this.Brightness * 100)
sCmd = ">N" & this.NodeID
' Handle special case of iLevel = 0 by defaulting brightness to 99%
if sysevent.newVal then
if iLevel = 0 then
' Transfer control to brightness
this.PowerStateChanging = false
this.Brightness = 1
end if
end if
' Handle special case of iLevel = 100
if iLevel = 100 then
this.Brightness = 1
end if
' If control wasn't transferred to brightness, send the powerstate command
if this.PowerStateChanging <> false then
if this.PowerState = true then
this.Parent.Parent.SendCommand sCmd & "ON", true, this.NodeID ' High-priority
else
this.Parent.Parent.SendCommand sCmd & "OF", true, this.NodeID ' High-priority
end if
end if
end if
this.PowerStateChanging = false
else
' Handle switch type
sCmd = ">N" & this.NodeID
if this.PowerState = true then
sCmd = sCmd & "ON"
else
sCmd = sCmd & "OF"
end if
this.Parent.Parent.SendCommand sCmd, true, this.NodeID ' High-priority
end if
end if