Friday, April 25, 2014

Home Automation - Bypassing a DSC zone

Read on, if you have a zone that you would like to monitor just for automation purpose and not for securing your premises. For eg, a garage door that you do want to include in your DSC panel, but not be trigger and set off your alarm when the system is armed and this zone is tripped and also be able to create scenes in your automation system  by checking if the door is open or closed.

If you are have automation setup, you also have the option of just using a standard door sensor (z wave or x10). But if you are using a DSC door/window sensor on this zone, the zone has to be bypassed everytime you arm your system (bypassing zone only works for one cycle i..e one cycle of arm/disarm).

Another option is to define the zone as zone definition type = 26 (24 hour non-alarm type). By setting this zone type using zone definition sections (001-004), the zone will not trigger your alarm when its tripped. But at the same time, you can still query for the sensor's status (tripped or not) by querying for it.

On how you define a zone definition type for a zone, check my other post on "programming DSC panels"

Friday, March 14, 2014

Home Automation - Programming DSC panels

I assume you already read my previous 2 posts on Home Automation which was about what DSC components you need to buy and how to wire the components. Here I will be writing about the next step that is registering the components (door and motion sensors) to the panel.

Note that my setup is all wireless and the assumption is that I am programming using DSC keypad - 5501. If you decided to spend the extra $ and get the 5500, programming components is as easy as triggering the components and registering them. I will speak about it at the end.

All components represent a zone in your panel. All wired zones go into the first 8 zones in the panel. Even if you are not planning to have wired connection, I would suggest that you start registering your components from zone 9 so that later if you decide to wire some new components, you do not need to reprogrammed. There are 3 basic steps that you need to follow for each zone. If your component is wireless, you will also need to enable it and that is an additional step. The basic steps are that the zone needs to be
  1. enabled
  2. assigned
  3. enrolled
  4. attribute changed (if component is wireless)
I would recommend that you create a reference table as shown below for all the components you have. If you do not know what to fill for some of the columns, you will soon be clear as you read further and you can come back and fill them up

Description:
Label
Type of Delay:
Zone #
Zone Type
#/ESN #
Enrollment codes
Front Door Sensor
Front door
Delay
09
01
2987F1
*8 5555 804 09 2987*6*1
Main Floor Motion
Main floor motion
Interior Stay/Away
10
05
44E1B0
*8 5555 804 10 44*5*1*2*0

Please note the following as you read ahead
  • The assumption is that you have not changed the default installer code. which is "5555".
  • If you are using PK5501 keypad, then you will just hear beeps as you type in the keys and not see anything on the screen. Listen to the beeps as you type. For eg, to start programming, you have to type *8 5555. But when you type *8, you will just hear beeps as you type in each number, when you finish typing *8 5555, you will hear multiple beeps. This means it accepted your input and its ready to accept the next value in which case its waiting for the "section number".
  • The section number is 3 digit number and you can read about all section numbers in the manual you get with PC1864NK
  • ### can be entered anytime to exit programing. This helps while you are programming and you do not know where you are and would like to exit without making any changes that you would not know.
  • Be very careful as you type in the keys because if you enter the wrong section and enter something, its very difficult to revert back as you would probably not know what you have changed.

Step 1 - Enable the zone
You need to enable each zone you are registering. To enable the zone what you need to remember is that each section starting from 202 is used to enable only 8 zones.
So section 202 represents zones 1 to 8, 203 represents zones 9 to 16, 204 represents zones 17 to 24, and so on ..
As in the table above, I have only two sensors to be registered and I plan to start from Zone 9, I have to program section 203.
The keys I will enter to enable the two zones 9 and 10 are
          *8 5555 203 1 2 # # #
If I also had another component to be registered in Zone 11, then I would have entered
          *8 5555 203 1 2 3 # # #
Step 2 - Assign Zone type definition
Now we define what each of these zone are going to do i.e. whether these are door sensors that need to activated immediately when a door alarm is triggered or whether you need a delay so that you have time to enter the "pin" to disarm your alarm or whether its a motion sensor that is not triggered when you enable your alarm in "Stay" mode, etc. The most common definitions used with their codes are

01 - delay 1
02 - delay 2
03 - instant
04 - Interior
05 - interior stay/away for motion sensors
06 - Delay stay/Away
13 - Gas
14 - heating
16 - Panic
17 - Emergency
19 - Water
20 - Freeze

In the above table listing my components, you will notice that I have decided to setup my zone type for front door sensor as 01 and for the main floor motion sensor as 05.
Now to set these zone type in the panel, you need to key in
          *8 5555 001 00 00 00 00 00 00 00 00 01 05 00 00 00 00 00 00 ###where 001 = section for assigning zone definition
rest are all zones from 1 to 16. So you assign definition type only where applicable it applicable for a zone
Similarly if you had components in zones 16-24, you will define them using section 002. So your codes to assign zone types to zones 17, 18 and 19 will be
          *8 5555 002 01 05 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ###

Step 3 - Enable wireless atrribute (only for wireless components/sensors)
You have enable the attribute for each zone that has a wireless sensor like the door sensor and motion sensor I have listed in my first post (EV-DW4975 or WS4904P). To enable this attribute, you will need to type
           *8 5555 1xx 8
where xx is the zone number. So to enable wireless attribute for zone 9 and zone 10, I will enter
           *8 5555 109 8
           *8 5555 110 8
Do note that after you type the section nos (109 or 110), in the keypad, you will see some nos from 1 to 8 like this "1 2 3  6  7" or something like that. That means, attributes 1, 2, 3, 6, and 7 are enabled for that zone. After you enter 8, you will see that change to "1 2 3 6 7 8". So if 8 is seen that means that the wireless attribute is enabled for that zone. Do not change any other default attributes that might be enabled or disabled for that zone.

Step 4 - Enroll devices
To enroll devices, you need to understand what ESN number is. In all your sensors, you will see a number printed or stuck in a small piece of paper. This number is what is needed to enroll your devide to the panel. In my table above, for the door sensor's number is 2987F1. So to enroll the device, you need to enter

           * 8 5555 804 09 2987*6*1
where 804 = section to enroll wireless devices
09 = the zone number been enrolled
2987*6*1 = is the ESN number of the door sensor

What you might have noticed, while enrolling the device, the ESN is not the same as I had listed before and there are no alphabets. That is because there is no way to enter alphabets using the keypad. The alphabets are translated to numbers where A=1, B=2, C=3, D=4, ........., Z= 26. Also before and after you enter the number for the alphabet, you need to enter a "*". So in the above example, F=*6*.
If you have a ESN number like 398FA4, where there are 2 alphabets together, your translated number you would enter would be "398*61*4"

That is about it for enrolling the devices. Now all devices should be recognized by your panel.

But there are a few more steps you might be interested in.

Assign delays for entry and exit
This is to setup the delay you would need when you arm the device and before you leave the building so that you that when you open and close the main door, it does not trigger the alarm. The same way you would need an entry delay when you enter home so that you have time to disarm the device. To set the delay, you would enter
               *8 5555 005 01 010 045 020
where 005 = section for setting this up
01 = partition (assuming this is for partition 1)
010 = 10 second delay for delay1 zone definition types
045 = 45 second delay for delay2 zone definition types
020 = 20 second delay for exit delay (when you arm and want to exit the building)

Note that the seconds are entered as 3 digit nos and not 2 digits.

Setting up EVL3 and creating scenes in Vera is another post and hope to get to it soon.

Hope all this typing helps people out there. I had a tough time setting this up and once I got the hang of it, it looked pretty easy. When I was struggling to set it up, I would have loved to have an article like this one for reference .. :-)

Home Automation - Wiring the DSC panel

In my previous post, I mentioned about the basic DSC components you would need if you are planning to setup home security (DIY) using DSC powerseries panels. That post also details the functions of each of these components and so I will not be repeating them again.

Here I will talk about wiring the setting it up and I will write about programming it or what you might call it as "registering the components" in my next post.

There are various videos you can find in youtube for this process. I would highly recommend that you view them
https://www.youtube.com/watch?v=IfTdZ_xwGJk
https://www.youtube.com/watch?v=z-gYcU1s-kI

Note that these basic steps listed below are the same for all DSC powerseries panels
The steps are
  1.  Put in the clips into the metal enclosure which comes with the panel (PC1864NK)
  2.  Attach the main panel into the enclosure using these clips
  3.  Attach the AC transformer (XR-1640LED) to the panel using the 2 conductor wire. The 2 wires will go into the first 2 terminals maked "ac" in the panel
  4. Connect the keypad (PK5501 or PK5500) using the 4 conductor wire to the main panel using the 4 conductor wire. The 4 wires will go into the terminals marked as RED, BLK, YEL and GRN. The colors of the wire are not that important as long as you connect the same colored wire into the keypad and the panel
  5. Connect the Envisalink Internet Alert Module (EVL3) panel to the main panel using another piece of 4 conductor wire. This wire will go into the same terminals as the keypad in above step and will follow the same color codes. You could also attach EVL3 to the same enclosure of the main panel using the clips provided with EVL3. The panel will be attached to the  side walls of the metal enclosure.
  6. Connect the EVL3 ethernet port to your router.
  7. If all your components are wireless, you would have got the Wireless Transceiver (TR5164-433). Connect this to the same 4 terminals in the main panel as the keypad and EVL3. Again follow the same color codes for the wires in the main panel and TR5164. As you might need to move this transceiver to a more suitable location so that all your wireless components can communicate to it properly, remember that you might need some extra wire while cutting or selecting a wire for this connection.
  8. If you have any wired sensors, you will connect them using the 4 conductor or 2 conductor wires (if you use 4 conductor wire, then you will not be using 2 of those colored wires). The wires will be connected to the approriate zone (marked as zone1 and COM, zone2 and COM, zone3 and COM, etc) in the main panel
  9. If you have a battery backup, connect it using the wire that comes with (PC1864NK). These wires go into the pin on the lefmost side of the panel
  10. Ensure everything is connected properly and power up the system
 
If everything is connected properly, you will see the LEDs light up on the panel and EVL3.

Tuesday, March 4, 2014

Home Automation - DSC security components that work with Vera/Veralite

If you are just decided on setting up a DIY home automation system, like me, you might have decided on using a Vera system. On why I decided to use Vera instead of others like HomeSeer, Crestron, etc, thats an another discussion that I might post later.

If you are also planning to set up security, you might have decided on using DSC security system as Vera has a plugin that you could use to interface with. If yes, you too might be having a tough time deciding on what DSC components you need to purchase.

So here is a list of basic components you would need to setup DSC security system and interface it with Vera
  • Vera2, Vera3, Veralite - Any of the Vera controllers.
  • DSC plugin - This is a free plugin (http://code.mios.com/trac/mios_dscalarmpanel) you would install using the Vera's web site. I will not go into details on how you can set it up as there are lots of details about it in the plugin homepage and Micasaverde forums.
  • DSC Power Series 1864 Control Board & Enclosure (PC1864NK) - This is the main DSC panel with 64 zones. Depending on how many components (or zones) you are planning to connect to this panel, you could also get any of the other poweseries panels like the 1832 (32 zones) or 1616 (16 zones). I do not think the any other DSC panels work with Vera. Note that each door sensor, motion sensor, keypad, etc is considered as a zone.
  • 16.5 40VA Transformer (XR-1640LED) - This is the power adapter for the above panel.
  • DSC Fixed LCD Keypad (PK5501 or PK5500) - I would recommend the PK5500 as its easier to program with
  • Envisalink Internet Alert Module for DSC & Honeywell Security (EVL-3) - This is needed so that your DSC panel can talk to your Vera controller. You connect this component to your router (network) to which your Vera is connected to. You do not need to connect this component to Vera directly
  • 4 conductor wires - This a 18-22 guage 4 colored wire you could get from home depot or Lowes. You need this to connect the keypad, sirens (if you have one), EVL-3, etc to your main panel. You could buy a big spool and cut it as per your needs for each of the component. The 5 conductor sprinkler wires could also be used (you will just not use one of the wire out of the 5). If your sensors are all wireless, you will not need wires to connect the sensors to the panel. But if you plan to use wired sensors, then plan to get a large amount of this wire.
  • 2 conductor wire- This is a 18 guage wire that you would need to connect your power adapter to your security panel.
  • Ethernet wire - To connect EVL-3 to your router.
I preferred a wireless setup as I did not want to run wires all over my house. If you have the same preference, you would also need these additional items
  • DSC PowerSeries 2-Way Wireless Transceiver (TR5164-433) - This is the wireless receiver that transforms your DSC PowerSeries control panel into a wireless alarm system so that your wireless sensors can talk with your security panel.
  • Vanishing Wireless Door Window Sensor (EV-DW4975) - This is the door/windows sensor. I assume you will need at least one for your main door.
  • DSC Wireless Pet Immune PIR Motion Sensor (WS4904P) - This is a motion sensor (if you need one)
  • DSC 2-Way Wireless Touch-Screen Arming Station (WTK5504) - This is in addition to the wired keypad mentioned above. You can get this if you are also interested in having a wireless keypad that you probably want to setup near to main entrance or in your bedroom. Note, you cannot just use this Keypad to program/setup your sensors and other components. You will need at least one wired keypad (mentioned above) for setup.
  • Other components you might want to get are a siren, strobe light, key fob, etc. But they are not mandatory and depends on whether you really need them or not. When your alarm is triggered, you could use a sonos system (if you have one) that can be used as a siren, turn on your home lights (if they are Zwave and connected to Vera) instead of strobe lights, use VeraAlerts to send messages/make calls. You could also use your Vera phone app instead of keyfob.
 I will soon be publishing another post on how to setup all these components.

Hide the START button and taskbar in Windows 7 or Windows XP

I had to develop a windows desktop application in Windows XP that consumed the entire desktop space. Yes, like the windows apps in the Windows 8 world. The application had to hide the taskbar and all other desktop features and open the application window in maximized state with no borders. As there was no easy way to get it done using .Net, I resorted to calling Windows API. Here is the sample code to hide and show the task bar and the START button

public static void TaskBarHide(bool pHideTaskbar)
{
      IntPtr lTaskBarHandle = FindWindow("Shell_traywnd", "");
      IntPtr lStartButton = FindWindowEx(IntPtr.Zero, IntPtr.Zero, (IntPtr)0xC017, "Start"); 

      if (pHideTaskbar == true)
      {
           ShowWindow(lStartButton, SW_HIDE);
           //SetWindowPos(lTaskBarHandle, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);   // Hide Taskbar
           ShowWindow(lTaskBarHandle, SW_HIDE);
       }
       else
       {
          ShowWindow(lStartButton, SW_SHOW);
          //SetWindowPos(lTaskBarHandle, 0, 0, 0, 0, 0, SWP_SHOWWINDOW); // Show Taskbar
          ShowWindow(lTaskBarHandle, SW_SHOW); 
                 }
              }

Open MS Office documents within a desktop application

Have you ever had to develop an application where you had to open MS office documents within your desktop form (as a child form)? If yes, you would have found that it almost seems to be an impossible task. A long time back, I too had a similar problem. I do not know with newer technology and versions of Windows and VS, maybe there is an easy way to get it done. But at that time, I had a tough time figuring how to get it done.

What I had to do was
- open a office document
- position the office document as a child window within another windows form so that I can control the parent windows form for closing it, positioning it, etc

If you have already searched the internet, you would see various suggestions like using activex controls and some other solutions that his own issues and limitations.

The way I finally got it done was using Windows API. This worked in Windows XP and I think there must be similar APIs for Windows 7 (may even be the same). I am sorry, but I haven't tried whether it works on it or not on Windows 8.

const UInt32 WS_OVERLAPPED = 0x0;
const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;
const UInt32 WS_MINIMIZE = 0x20000000;
const UInt32 WS_VISIBLE = 0x10000000;
const UInt32 WS_DISABLED = 0x8000000;
const UInt32 WS_CLIPSIBLINGS = 0x4000000;
const UInt32 WS_CLIPCHILDREN = 0x2000000;
const UInt32 WS_MAXIMIZE = 0x1000000;
const UInt32 WS_CAPTION = 0xC00000; //'/* WS_BORDER | WS_DLGFRAME */
const UInt32 WS_BORDER = 0x800000;
const UInt32 WS_DLGFRAME = 0x400000;
const UInt32 WS_VSCROLL = 0x200000;
const UInt32 WS_HSCROLL = 0x100000;
const UInt32 WS_SYSMENU = 0x80000;
const UInt32 WS_THICKFRAME = 0x40000;
const UInt32 WS_GROUP = 0x20000;
const UInt32 WS_TABSTOP = 0x10000;
const UInt32 WS_MINIMIZEBOX = 0x20000;
const UInt32 WS_MAXIMIZEBOX = 0x10000;

[DllImport("user32.dll", SetLastError = true)] static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex); 
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
 
[DllImport("user32.dll")]
private static extern int ShowWindow(IntPtr hwnd, uint command); 
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter,
string className, string windowTitle);

[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(
IntPtr parentHwnd,
IntPtr childAfterHwnd,
IntPtr className,
string windowText); 
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); 
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); 
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
        [StructLayout(LayoutKind.Sequential)]
public struct RECT
{public int Left;
public int Top;
public int Right; 
public int Bottom;
} 
public static void InitializeWindow(IntPtr pProcessHandle, IntPtr pCurrentHandle, int pLeft, int pTop, int pWidth, int pHeight) //, bool bRepaint)
{  //postion the window
   MoveWindow(pProcessHandle, pLeft, pTop, pWidth, pHeight, true);
   //set the parent as current application
   SetParent(pProcessHandle, pCurrentHandle)    
   int lStyle = GetWindowLong(pProcessHandle, GWL_STYLE); 
   lStyle = lStyle - (int)(WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
   // Put the modified style back:
   SetWindowLong(pProcessHandle, GWL_STYLE, lStyle);
}
Call "InitializeWindow" to position and setup the application's (MS office application) window as a child window of the current form
 using System.Diagnostics;ProcessStartInfo psInfo = new ProcessStartInfo(FilePath of the MS document);
psInfo.WindowStyle = ProcessWindowStyle.Normal;
 //open the external application
Process ApplicationProcess = Process.Start(psInfo);
ApplicationProcess.WaitForInputIdle(1000);//Initialize the application window
InitializeWindow(ApplicationProcess.MainWindowHandle, this.Handle, 100, 0, 300, 200, true);