| Controlling Rako lights with the TSU9600 scroll wheel
I decided that I would like to control my Rako lights directly from whatever device I'm in, without entering the Rako module. Note that this is not necessarily the best code in the world - the rotary counter should really be a state, and it would be better if I could restart timers (which I can do with my own timer module). But I just wanted something working quickly this evening so was only willing to spend half an hour on it.
When I mention "light button" below, I mean the icon on the display - not the hard button.
The prontoscript below will allow the following :
1) A brief press of the light button on the display switches the lights on to scene 3 if they are off - or switches them off if they are on. Holding the light button down will jump to the Rako module (this assumes you were using the light button to jump to the Rako module already). Note that this assumes all light control is via the pronto - if you use a real light switch the pronto will be out of sync, but that just means you'll need to press the button twice to get it back in sync.
2) The scroll wheel can be used to fade the lights up / down.
Before you can do this, you must understand prontoscript names. These are NOT labels. Each device / Activity can have a prontoscript name (in the Properties). Each page can have a prontoscript name. Each button can have a prontoscript name. Before you can use the prontoscript below, you must create buttons that send RS232 commands as follows. Note that you will need to use your own house number (mine assumes HO:1), your own room (mine assumes RO:4), your own channel (mine assumes CH:1).
Fade up - HO:1\rRO:4\rCH:1\rCOMMAND:1\r
Fade down - HO:1\rRO:4\rCH:1\rCOMMAND:2\r
Stop fade - HO:1\rRO:4\rCH:1\rCOMMAND:15\r
Off - HO:1\rRO:4\rCH:1\rOFF\r
Scene 3 - HO:1\rRO:4\rCH:1\rSC:3\r
Obviously you can choose a different scene if you wish - this is the scene that will be selected if you press the lights button briefly when the lights are off.
You need to give each of these buttons a prontoscript name. They need to be created on a page with a prontoscript name. The page must belong to a device with a prontoscript name. You will see in the prontoscript examples below that I placed my buttons on the RESOURCE_PAGE of my SKY_DEVICE and the prontoscript names for the buttons I used should be obvious.
Now - to be able to use the lights button to toggle the lights on and off you need to track the state of the lights. In the properties page of your Home device, add the following prontoscript : if (!System.getGlobal ("lights"))
{
System.setGlobal ("lights", "off");
}
Now - for the lights button / icon on the System page add the following prontoscript. The onHoldInterval of 300 means you have to press the button for 300ms before it would jump to the Rako module - you can increase or decrease this period as you wish : var button_held = false;
onHoldInterval = 300;
onHold = function ()
{
button_held = true;
onHoldInterval = 0;
}
onRelease = function ()
{
if (!button_held)
{
if (System.getGlobal ("lights") == "on")
{
CF.widget ("RAKO_OFF_BUTTON", "RESOURCE_PAGE", "SKY_DEVICE").executeActions ();
System.setGlobal ("lights", "off");
}
else
{
CF.widget ("RAKO_SCENE_3_BUTTON", "RESOURCE_PAGE", "SKY_DEVICE").executeActions ();
System.setGlobal ("lights", "on");
}
}
else
{
executeActions ();
}
Note the prontoscript names in capitals - you must use your own names (or name your buttons / pages / device the same as mine).
Now - in the properties page of each device where you want to use the scroll wheel to control the Rako lights add the following prontoscript :
var rotary_count = 0;
onRotary = function(clicks)
{
if ( clicks > 0 ) // Rotated right
{
if (rotary_count == 0)
{
/* Start fading up */
CF.widget ("RAKO_FADE_UP_BUTTON", "RESOURCE_PAGE", "SKY_DEVICE").executeActions ();
rotary_count = 1;
}
}
else if ( clicks < 0 ) // Rotated left
{
if (rotary_count == 0)
{
/* Start fading down */
CF.widget ("RAKO_FADE_DOWN_BUTTON", "RESOURCE_PAGE", "SKY_DEVICE").executeActions ();
rotary_count = 1;
}
}
else /* clicks must be zero - scrolling has stopped */
{
CF.widget ("RAKO_STOP_BUTTON", "RESOURCE_PAGE", "SKY_DEVICE").executeActions ();
rotary_count = 0;
}
System.setGlobal ("lights", "on");
}
Note that if you are using the Rako module, you will need to add the following line of prontoscript code to the fade up / fade down / scenes 1-4 buttons : System.setGlobal ("lights", "on");
And the following line of code to the Off button : System.setGlobal ("lights", "off");
Last edited by Dave964; 18-11-2009 at 5:10 PM.
|