Control Bathroom Fan Using INSTEON
Scott/Chicago
Posts: 8
Have you ever wanted to automatically turn on your bathroom fan? One of our·bathrooms has a shower and my children·routinely forget to turn on the fan. So I created a Javelin demo program that automatically turns on the fan after they're done. It also... ahh, umm, provides ventilation after someone's been in the bathroom for a while.
In addition to the bathroom fan control it·automatically dims our stairway lights after they've been turned on, giving enough time for someone to walk up/down the stairs.
The·demo program is at http://www.cls01.com/insteon/demo1·and has two main functions:
1. Automatically turn on the bathroom fan 2 minutes for every 1 minute the bathroom light is on. Fan turns on 5 seconds after the bathroom lights are turned off.
2. Dim the stairway lights 10 seconds after they're turned on and turn on entryway lights at the same time.
This uses the Javelin Insteon.java class that I've been developing. This class can·be used to allow a Javelin Stamp to control INSTEON or X10 devices and respond to INSTEON events. The Javelin.java class is at http://www.cls01.com/insteon.
Regards,
Scott
In addition to the bathroom fan control it·automatically dims our stairway lights after they've been turned on, giving enough time for someone to walk up/down the stairs.
The·demo program is at http://www.cls01.com/insteon/demo1·and has two main functions:
1. Automatically turn on the bathroom fan 2 minutes for every 1 minute the bathroom light is on. Fan turns on 5 seconds after the bathroom lights are turned off.
2. Dim the stairway lights 10 seconds after they're turned on and turn on entryway lights at the same time.
This uses the Javelin Insteon.java class that I've been developing. This class can·be used to allow a Javelin Stamp to control INSTEON or X10 devices and respond to INSTEON events. The Javelin.java class is at http://www.cls01.com/insteon.
Regards,
Scott
Comments
I especially appreciate the use of the ScaledTimer16 class.
Your program clarity really benefits from this class.
I was able to understand your Demo1 class without much trouble.
The only thing that is a bit unclear are the constants 0x28 and 0x38,
······· rtnCode = PLC.sendInsteonCmd(Insteon.CMDTYPE_DIRECT,
········· stairsLightSwitch,Insteon.CMD_ON,(char)0x28);
······· if (rtnCode < 0) Format.printf("Send error %d\n",rtnCode);
······· else············ Format.printf("Stairway reset to level 0x28...\n");
······· rtnCode = PLC.sendInsteonCmd(Insteon.CMDTYPE_DIRECT,
········· entryLightSwitch,Insteon.CMD_ON,(char)0x38);
what do these constants represent?
regards peter
The 0x28 and 0x38 represent the brightness level for the "Insteon.CMD_ON" command and can range from 0x00 (off) to 0xff (full on). What's the best way to make this clearer in the program?
By the way, I was very happy to find the ScaledTimer16 class that you had written. It was very easy to use for the relatively long timers that I needed.
Regards,
Scott
//Set dimvalue to 0x28 of 0xFF fullscale (15.7%)
Or you could define a logical dim method that accepts a 0.1% dimvalue (0-1000)
static int dim(int dimvalue) {
· //dimvalue*255/1000 = dimvalue*0.255 = dimvalue*16712/65536
· return UnsignedIntMath.umulf(dimvalue,16712);
}
and then put in (char)dim(157) instead of (char)0x28
The class UnsignedIntMath is already used by the ScaledTimer16 class,
just import stamp.math.*; in your demo class.
I wrote the ScaledTimer16 class for two reasons:
To have longer delays and having just 16bit values. You make nicely use
of both, as you calculate the longer delays (minutes!!) with simple math.
(Imagine you had to do that using 32bit values)
The timeout() method of the ScaledTimer16 class executes in far less time
than the timeout(value) method of the Timer class. And since the timeout method
is called frequently, that saves time.
regards peter