Floorplan Scripts5

From XAP Automation
Jump to: navigation, search

This is based upon Scripts4 but ramps the lights up. It is linked to the Squeezebox xPL device and relies upon a global flag to indicate whether we are in 'night' mode which is set by a Timer in xAP Florplan.

Sub Main()

'----xAP Name of device(s) to ramp (you may be able to use wildcards)
DeviceName1="mmwave.dmx512.g8kmh_hapc1:House.Upperfloor.Bedroom1.Ceiling.Window"
DeviceName2="mmwave.dmx512.g8kmh_hapc1:House.Upperfloor.Bedroom1.Ceiling.Main"
'----Number of steps
RampFinished=50
'----Delay Between Steps in seconds
Delay=10
'----Settings for start level and final levels
RampLevelStart=5
RampLevelMax=55



'----Check Squeezebox is on and we aren't in daylight
Power=xap.getfromraw(rawmessage, "stat.basic,power")
if ((GetGlobal("DuskDawnState") <> "night") OR (Power="0")) then exit sub

'----If either device is on then exit, as there is no point in ramping (up early?)
x=xap.getstate(DeviceName1)
y=xap.getstate(DeviceName2)

if ((x="on") OR (y="on")) then exit sub

'Turn on at minimum level
xap.sendbsc DeviceName1,"on",RampLevelStart & "%", ""
xap.sendbsc DeviceName2,"on",RampLevelStart & "%", ""


'---The scripts that will be added to make the timers
scriptlevel1="Sub Main()" & vbcrlf &  "x=xap.sendbsclevel(""" &  DeviceName1 & ""","""
scriptlevel2="Sub Main()" & vbcrlf &  "x=xap.sendbsclevel(""" &  DeviceName2 & ""","""
scriptend=""")" & vbcrlf & "End Sub"

RampDiffStep=(RampLevelMax-RampLevelStart)/RampFinished

for a=1 to RampFinished
   RampTo=RampLevelStart+a*RampDiffStep
   x=xap.addtimer("1Ramp to " & RampTo,dateadd("s",Delay*a,now),"",scriptlevel1 & RampTo & "%" & scriptend)	
   x=xap.addtimer("2Ramp to " & RampTo,dateadd("s",Delay*a,now),"",scriptlevel2 & RampTo & "%" & scriptend)	
next


End Sub