Misterhouse CBUS Gateway Code V2.0

 

Contents

Misterhouse CBUS Gateway Code V2.0. 1

Contents. 1

Forward. 2

Project Status. 2

Distribution Package. 2

cbus.pl 2

cbus_dat.csv. 2

Cbus_Item.pm.. 3

cgate.pl 3

lighting.pl 3

rc_units.pl 3

mh.private.ini 3

cbus.pl.safe. 3

How Cgate integrates with MH.. 4

MH CBUS Data Flow.. 5

Installation. 5

Installation. 6

Running RUN_BUILDER and RELOAD.. 8

Web Interface. 8

TK Interface. 8

Running C-BUS Monitor & Talker 9

Web Interface. 9

TK Interface. 9

Appendix 1 – Hex to Decimal 10

 


Forward

·         Special Thanks to Greg McCall for his valuable effort in testing for Windows, TK and his valuable documentation help.  Thanks Greg.

·         Updates will be available at http://www.killara.net/mh/  or from time to time in the MH release kit.

·         Please send all comments, complaints, praises to the author at richard@webcom.com.au

 

Project Status

 

Distribution Package

The distribution package should contain the following files

cbus.pl

Is the output file created by cgate_builder().  It is a proper MH perl file, and contains all the objects and properties for all the CBUS units. NEVER EVER edit this file. Make changes to cbus_dat.csv, and then run cgate_builder.  Put this file in your code directory.

cbus_dat.csv

Is the input file for cgate_builder().  It is a simple CSV file that defines all the CBUS units and there names, properties etc. You will need to edit this for your own site, remember that CBUS used the GROUP addresses not the unit ID’s. Put this file in your code directory.

Cbus_Item.pm

This is a simple file that creates the Cbus_Item object, which is just an inheritance of the Generic_Item.  Put this file in your code directory.

cgate.pl

This file contains all the main CBUS interface routines to talk to the Clipsal cgate server.  Put this file in your code directory.

It contains;

lighting.pl

This sample file contains my own houses lighting controls, it demonstrates well how to use the CBUS objects.

rc_units.pl

This sample file contains some examples of how my own houses uses Radio Control key fobs, connected via the CBUS.  Irrelevant application I know, but a good example of using CBUS input triggers.

mh.private.ini

Is the MH private config file, it contains all the required config parameters.  Add these directives to your own config file.

cbus.pl.safe

This is a working, tested safe version of cbus.pl.  Rename this file  to cbus.pl, if the one you have built with cgate_builder() has corruptions or is causing MH to crash.

 

 

 


How Cgate integrates with MH

All CBUS objects are defined in a standard CSV file (cbus_dat.csv), this file is read in  at $Reload, and a large Hash-of-Hash is created to store the CBUS objects for MH.  To ensure that MH can use the CBUS objects properly, they are mapped into a MH object called Cbus_Item (actually an alias for a Generic_Item)  This allows all the good stuff in MH to work on CBUS items, as if they were an X10 (sort off). (I tried to map the CBUS devices into the existing X10 support in MH, but the X10 support is just too limited, and CBUS has too many new features.  Eventually I hope to migrate cbus_dat.csv into a XML specification.)

To do this mapping, that is create the CBUS $objects and matching tied Voice_cmds a sub in this file make_cbus_file() reads through the CBUS hash and creates the Perl directive We are in effect using MH to write its own code, this was inspired from the X!0 methods. The output file of the builder, cbus.pl is a valid MH code module and is then read in at the next reload. 

So..  Remember to RUN_BUILDER, then RELOAD code, to make a CBUS object change. (see following chapters  for information on how to run RUN_BUILDER and RELOAD)

The $v_objects are all voice commands and they are used to control a CBUS device from the web.  Each $v_object is tied to its respective $object. In program control (testing the state of an $object, or setting a $object) are all performed against the $object, although you can set the $v_object, its state will not reflect any updates from the actual CBUS.

Remember, the CBUS is interactive, it can receive as well as issue commands, at the same time.  So, its best to always use the $object in your code.

Moving on.  Each $object is tied to an event trigger that calls the cgate_set subroutines,, notice how the last 'set_by'  directive was also passed, this is to ensure that we do not create endless message loops.

When the cgate_set() sub is called the actual CBUS device is set to that state assuming it was not the CBUS that actually initiated this set in the first place, get it ?

As Cgate itself repeats all commands received to it, back to MH, via  cgate_monitor.pl MH listens for these commands and then sets the appropriate non $object, but this is ignore if MH was in fact the source of the set.

 

If you understand this you are now an expert on MH objects, and a true CBUS wizard.

 


MH CBUS Data Flow

 

Installation

Instructions assume a Misterhouse directory structure as follows:

(adjust depending on your own environment and operating system)

   c:--+

       +--misterhouse--+        <--- mh.private.ini lives here

                       +--code      <--- my code

                       +--data      <--- my data

                       +--sounds    <--- my sounds

                       +--mh----+   <--- mh installed here

                                +--bin

                                +--code

                                +--data

                                +--docs

                                +--lib

                                +--sounds

                                +--web

(for info on the above directory layout, see “Coding your own events” at the end of the install.html included in MH docs at c:\misterhouse\mh\docs)

 

  1. You will need either a Windows or Linux machine that match the min specs for Clipsal C-Gate and Misterhouse packages. This machine will need an IP interface and software installed as well as the interface being configured with an IP address.  Instructions are for Windows users,  Linux users should be able to work this out for themselves.
  2. Ensure Perl & Misterhouse is installed.
  3. Ensure that CGATE is installed, running and listening on the correct ports.
  4. Unzip this package to a temporary directory
  5. Copy all the files from the code directory in your temporary directory into your main MH code directory
    C:\>copy \tmp\code\*   \misterhouse\code
  6. Add the following lines to the mh.private.ini in your \misterhouse directory. This text may be copied from the file mh.private.ini in your cbus temporary directory. 

#  Category = C-Bus

Cbus_Item_module                    = Cbus_Item

cgate_mon_address                   = 192.168.200.5:20024

cgate_talk_address                    = 192.168.200.5:20023

cbus_dat_file                             = cbus_dat.csv

cbus_categories_prefix               = cbus_

cbus_ramp_speed                      = 0

  1. The IP address will need modifying to suit you own environment;
    i.e. Replace the
    192.168.200.5 above with your own IP address.
  2. If you have modified the default port number in the C-Gate server, you will also need to modify the port numbers after the “:” following the IP address.
  3. Modify the cbus_dat.csv in the code directory to reflect your CBUS devices. See the comments within the cbus_dat.csv file for more details
  4. See following chapters  for information on how to run RUN_BUILDER and RELOAD)
  5. Check for log errors
  6. Ensure that the cgate_talker and cgate_listener both started, this should be announced via the speech synthesizer (see following chapters for information on how to manually  start the cgate_talker and cgate_listener)

Running RUN_BUILDER and RELOAD

These commands can either be run from the MH web interface or the MH TK interface.

Web Interface

  1. From the home page, select the “MrHouse Home” icon
  2. then click on “Browse Categories”
  3. then click on “CGATE”
  4. Now click on the link “RUN_BUILDER”
  5. Now, click on the “Browse MrHouse” icon
  6. Click on the “Force Reload Code” icon

TK Interface

  1. Select the menu

CommandsCGATEcgate_builder: cgate Builder RUN_BUILDER

  1. Click on the button “Reload (F1)

 

Note: If the TK Interface is not running, you might not have all the code. Include the following lines in a script and run it while connected to the internet:

 

c:

cd \perl\bin

perl ppm.bat install Win32-API

perl ppm.bat install Tk

perl ppm.bat install Tk-JPEG

perl ppm.bat install DB_File

perl ppm.bat install GD

 


Running C-BUS Monitor & Talker

These commands can either be run from the MH web interface or the MH TK interface.

Web Interface

  1. From the home page, select the “MrHouse Home” icon
  2. then click on “Browse Categories”
  3. then click on “CGATE”
  4. Use the web links to ensure CBUS Monitor & C-Gate Talker are active.

TK Interface

  1. Select the menu

CommandsCGATEcgate_monitor: CBUS Monitor START

CommandsCGATEcgate_talker: C-Gate Talker START

  1. Click on the button “Reload (F1)

 

Note: If the TK Interface is not running on a Windows machine, you might not have all the code. Include the following lines in a script and run it while connected to the internet:

 

c:

cd \perl\bin

perl ppm.bat install Win32-API

perl ppm.bat install Tk

perl ppm.bat install Tk-JPEG

perl ppm.bat install DB_File

perl ppm.bat install GD

 


Appendix 1 – Hex to Decimal

This chart can be useful when editing the cbus_dat.csv

 

    0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F.

0  000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015

1  016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031

2  032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047

3  048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063

4  064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079

5  080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095

6  096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111

7  112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

8  128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

9  144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159

A  160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

B  176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

C  192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

D  208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223

E  224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

F  240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

 

Hex 41 (written as 0x41 ) is equivalent to decimal 65