- Notifications
You must be signed in to change notification settings - Fork0
License
AlanDThiessen/cm11a-js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Node.js module for controlling X10 devices through a serial CM11A interface. It allows NodeJe applications to conrol X10 devices through the serial interface of the CM11A, and monitors status of X10 devices.
npm install cm11a-js
// Import the moduleconstCM11A=require('cm11a-js');// Create an CM11 objectletcm11=CM11A();// Start the service, connecting to the Serial Portcm11.start('/dev/ttyUSB0');// Issue Commandsletunits=['A1','A2'];cm11.turnOn(units);cm11.dim(units,11);cm11.bright(units,11);cm11.turnOff(units);// Close the connection to the CM11Acm11.stop();
cm11.start(port);
Opens serial communications with the CM11A on the specified serial port, and begins monitoring for unit status.
port
is the serial port to open, e.g./dev/ttyUSB0
on Linux, andCOM1
on Windows.
cm11.stop();
Close serial communications with the CM11A, and stops monitoring device status.
cm11.turnOn(addresses);
Turns on the specified unit addresses.
addresses
is an array of X10 device addresses. e.g. ['A1', 'A3']
cm11.turnOff(addresses);
Turns off the specified unit addresses.
addresses
is an array of X10 device addresses. e.g. ['A1', 'A3']
cm11.bright(addresses, level);
Brightens the the specified unit addresses by the specfied level.
addresses
is an array of X10 device addresses. e.g. ['A1', 'A3']level
is a value between 0 and 22, indicating how much to brighten the device. Note: this is a relative value, not an absolute value.
cm11.dim(addresses, level);
Dims the the specified unit addresses by the specfied level.
addresses
is an array of X10 device addresses. e.g. ['A1', 'A3']level
is a value between 0 and 22, indicating how much to dim the device. Note: this is a relative value, not an absolute value.
cm11.setClock();
Sets the clock of the CM11A controller to the current time provided by the PC.
cm11.status();
Reads the status from the CM11A returns the status through the status callback event below.
Calling modules can subscribe to the following events on cm11a-js interface.
Provides the status of X10 devices when the CM11A detects a change on the power line.
cm11a.on('unitStatus',callback);
When the status of a device changes, the callback function will be called with the following object:
{// An array of unit codes for which status is being reported.units:array,// The X10 Function that was called on the devicex10Function:string,// The level of the function is DIM or BRIGHTlevel:number}
Provides the status of the CM11A as read from the device with thestatus()
function.
cm11a.on('status',callback);
After the status has been read from the CM11A, the specified callback function will be called with the following object:
See section 9 in theInterface Communication Protocol on theHeyu website for more details.
{// Time since last battery changebatteryTimer:value,// CM11A Firmware RevisionfirmwareRev:value,// An object containing values of the CM11A's clocktime:{// Day of the yeardayOfYear:value,// Hour of the dayhours:value,// Minute of the hourminutes:value,// Second of the minuteseconds:value},// An object containing the status of monitored devicesmonitoredDevices:{// House code being monitoredhouseCode:value,// Currently addressed devicesaddresed:value,// On/Off status of monitored devicesonOffStatus:value,// Dim status of the monitored devicesdimStatus:value},// A bitmask indicating Which day it is (SMTWTFS)dayMask:value}
Notifies the calling software when communications with the CM11A have been closed.
cm11a.on('close',callback);
When the serial port has been closed, the specified callback function will be called with no parameters.
Kudos to theHeyu project. Heyu provides a complete interface to the CM11A (and other devices). The documentation and research they have done has been priceless! Heyu ran my house for many years!