Script 1

From XAP Automation
Jump to: navigation, search

This is the script which turns on the lights.

Sub Main()
' Lehane Kellett lehane@mm-wave.com
' Lighting Carousel - each press gives a different 'scene' after 10 seconds
' of no activity then a press turns all off
' In this scenario scenes build on top of each other
' Extend as required
CurrState=GetState("phaedrus.netiom.node0-1:lightswitch1.3")
' Button to ground - hence status "off" when pressed
if CurrState="off" then
    	PrevState=GetGlobal("KitchenLight1State")	
    	LogDebug ("LSW1 SW3 " & CurrState & " " & PrevState)
'
' -1 is Reset/Idle State
' ****** First press after starting Floorplan will cause all off *****
' Set Global KitchenLight1State to -1 in startup script.
'
    	if PrevState = -1 then
      		PrevState = 0
' Set to Off
    	else
'
' Must be running Floorplan 1.1 for the following to work (Timer Fix)
'
		select case PrevState
		case 0
    			SendBSCState "mmwave.dmx512.g8kmh_hapc1:House.Groundfloor.Kitchen.*","off"
		case 1
		    	level ="60/255"
		    	SendBSC "mmwave.dmx512.g8kmh_hapc1:House.Groundfloor.Kitchen.Table","on",level, ""
		case 2
		    	level ="80/255"
		    	SendBSC "mmwave.dmx512.g8kmh_hapc1:House.Groundfloor.Kitchen.Table","on",level, ""
		case 3
		    	level ="150/255"
		    	SendBSC "mmwave.dmx512.g8kmh_hapc1:House.Groundfloor.Kitchen.Table","on",level, ""
		case 4
		    	level ="180/255"
		    	SendBSC "mmwave.dmx512.g8kmh_hapc1:House.Groundfloor.Kitchen.Window","on",level, ""
' Extend here - you get the idea!
		end select
		PrevState=PrevState+1
	end if
    	SetGlobal "KitchenLight1State", PrevState
' If was 'on' command then setup toggle timer
	if PrevState > 0 then
	DeleteTimer ("Kitchen1Toggle")
	AddTimer "Kitchen1Toggle", DateAdd("s", 10, Now()), "Kitchen1ToggleOff"
	end if
else
	' debug - sometimes see unknown
	LogDebug("LSW1 SW3 ?" & CurrState)
end if
End Sub

Script 2