I was asked to post them from a topic in another forum, so here they are...
All the programs are contained inside my Garage/GDM folder to better organize them. GDM=Garage Door Middle.
I am not responsible for your garage door being open when you think it should be closed! I have tried every possible combination and have not seen the scene status fail to be correct. If you try these programs please make sure to check the actual status of the IOLinc sensor! For me this is easy in Mobilinc, where I make the scene a favorite, then I can check the status of the sensor when I click on that scene. Otherwise just look out your door to make sure it is closed
Notes:
[*:2e2f5bax]The scene being controlled is 'Garage / GarageDoorMiddle' [*:2e2f5bax]The object 'Garage / GarageDoorMiddle-Sensor' is the IOLinc sensor for that door, and is in the scene as a controller. [*:2e2f5bax]The object 'Garage / GarageDoorMiddle-Relay' is the IOLinc relay and is not in any scene, and it is in ‘Momentary B’ mode. [*:2e2f5bax]The object 'ZZ-Buttons / Front House D (GDM)' is one of my KPL buttons in the scene as a responder. [*:2e2f5bax]The KPL buttons must be in toggle mode, which is the default. [*:2e2f5bax]My setup uses the magnetic switch which is NO (Normally Open), which is NOT what the current smarthome kits come with. But, a few changes to the logic would make a NC switch work as well. [*:2e2f5bax]The text below each program is from the 'Comment' section... Would be nice if the UDI copy to clipboard function said that. [*:2e2f5bax]I have removed all the ‘Else’ sections since they are not used anywhere. [*:2e2f5bax]I hope I copy and pasted everything correct... Sure would be nice if the UDI admin console could spit all this out for a folder... This has been requested a couple times, but seems to have no or very low priority [*:2e2f5bax]I guess I could attach the 'exported' xml for the folder, but I have no idea how that would work for someone else since it contains my device specific information.
Again, feel free to comment or critique! I want these to work the best possible way so any input is ok.
Program: 000 ButtonOff
If
$i.GDM_DontWatch is 0
And Status 'ZZ-Buttons / Front House D (GDM)' is Off
Then
$i.GDM_RequestedStatus = 0
$s.GDM = 1
Function:
When the button state is changed, remember if it was changed
to on or off and start up the state machine.
Details:
All the '000' programs monitor the status of the KPL that is tied
to the GDM Scene. We only have to monitor one of them, since when the
scene is changed by any of KPL or Mobilinc it will affect all of them.
The main state variable for all GDM programs is s.GDM, which tells
us where in this state machine we are. We do not monitor that
state variable in the 000 programs because other programs within
this state machine will toggle the scene on and off, which in turn
changes the button state, so while the state machine is running we
ignore running the 000 programs using the i.GDM_DontWatch integer variable.
The i.GDM_RequestedStatus stores if the request was to close (0) or
open (1).
Program: 000 ButtonOn
If
$i.GDM_DontWatch is 0
And Status 'ZZ-Buttons / Front House D (GDM)' is not Off
Then
$i.GDM_RequestedStatus = 1
$s.GDM = 1
See '000 ButtonOff' for a description.
Program: 001 DoorStateFalse
If
$s.GDM is 1
And (
(
$i.GDM_RequestedStatus is 0
And Status 'Garage / GarageDoorMiddle-Sensor' is On
)
Or (
$i.GDM_RequestedStatus is 1
And Status 'Garage / GarageDoorMiddle-Sensor' is Off
)
)
Then
$s.GDM += 1
Function:
We have just entered the state machine from a KPL button changing
state. If the requested door status does not match the door sensor
status then go to the next state.
Info:
It seems that we could tie the check of the sensor status into
the 000 Button* states, but that does not work correctly because
it would trigger the 000 state when the sensor status changes
but the button status has not changed yet. This is because I
have the sensor as a controller for the GD scene because I want to
see the sensor as part of the scene in Mobilinc.
Program: 001 DoorStateTrue
If
$s.GDM is 1
And (
(
$i.GDM_RequestedStatus is 0
And Status 'Garage / GarageDoorMiddle-Sensor' is Off
)
Or (
$i.GDM_RequestedStatus is 1
And Status 'Garage / GarageDoorMiddle-Sensor' is On
)
)
Then
$s.GDM = 10
Function:
We have just entered the state machine from a KPL button changing
state. If the requested door status matches the door sensor status
then we are done.
Info:
See DoorStateFalse for info.
Program: 002 Init
If
$s.GDM is 2
Then
$i.GDM_DontWatch = 1
$s.GDM_Counter = 10
$s.GDM += 1
Function:
The door was requested to move, so initialize variables used in
the state machine and go to the next state.
i.GDM_DontWatch: 1=Don't watch the state changes of the KPL's
s.GDM_Counter: Loop counter for '002 Loop' program
s.GDM: Main state variable, go to state 2
Program: 002 Trigger
If
$s.GDM is 2
Then
Set 'Garage / GarageDoorMiddle-Relay' On
Function:
The door was requested to move, so trigger it.
Note:
This could have been done in the Init program, but that delays
the flashing of the scene for longer than I like...
The IOLinc relay is in Momentary B mode so it is triggered
by both on and off. I think this is important since I don't
turn it off, although I could, but I don't care what state
the relay is in.
Program: 003 DoorStatusClosed
If
$s.GDM is 3
And $i.GDM_RequestedStatus is 0
And Status 'Garage / GarageDoorMiddle-Sensor' is Off
Then
Set Scene 'Garage / GarageDoorMiddle' Off
$s.GDM = 10
Function:
While in the state and the door was requested to close, when
the door is closed we are done. Make sure the scene is
off and go to the cleanup state.
Program: 003 DoorStatusOpen
If
$s.GDM is 3
And $i.GDM_RequestedStatus is 1
And Status 'Garage / GarageDoorMiddle-Sensor' is On
Then
Set Scene 'Garage / GarageDoorMiddle' On
$s.GDM = 10
See DoorStatusClosed for a description.
Program: 003 Loop
If
$s.GDM is 3
And $s.GDM_Counter > 0
Then
Set Scene 'Garage / GarageDoorMiddle' Off
Wait 1 second
Set Scene 'Garage / GarageDoorMiddle' On
Wait 1 second
$s.GDM_Counter -= 1
Function:
Toggle the scene on and off so the KPL buttons and Mobilinc icon change
state. This gives visual feedback that we are waiting for the door.
Decrement the counter s.GDM_Counter each time, which tracks our timeout
function, and causes this program to restart until the counter reaches
zero.
We could have made the counter be the s.GDM... Oh well...
(I wish the 'Wait' could use a variable!)
Program: 003 Timeout
If
$s.GDM_Counter is 0
And $s.GDM is 3
Then
$s.GDM += 1
Function:
If the s.GDM_Counter has reached zero while we are in the
waiting state, then the door did not reach the state that
was requested! So go into state 3 which handles the failures.
(I had a reason for not handling them in this state, but can't
remember why...)
Program: 004 FailedClose
If
$s.GDM is 4
And $i.GDM_RequestedStatus is 0
Then
Set Scene 'Garage / GarageDoorMiddle' On
Resource 'Pushover-GDM-Close-Error'
$s.GDM = 10
Function:
There was a request to close the door, but we timed out waiting.
Make sure the scene is on since this state machine toggles the
scene we are not sure where it ended up. Send a notification to
tell us that there was a problem! Go to state 10 which does
the cleanup.
Note:
I wonder if there could be a race condition... If the door sensor
status happens to change after TimeOut and before this is triggered?
But I really don't think that will happen...
Program: 004 FailedOpen
If
$s.GDM is 4
And $i.GDM_RequestedStatus is 1
Then
Set Scene 'Garage / GarageDoorMiddle' Off
Resource 'Pushover-GDM-Open-Error'
$s.GDM = 10
See FailedClose for a description.
Program: 010 Done
If
$s.GDM is 10
Then
$i.GDM_DontWatch = 0
$s.GDM = 0
State machine is all done so start watching again.