rfxcom depends on the serialport module.
npm install rfxcom
The only dependency is serialport 1.0.6+.
var rfxcom = require('rfxcom'), pg = require('pg').native, conString = "pg://user:password@localhost/user", client = new pg.Client(conString); var rfxtrx = new rfxcom.RfxCom("/dev/ttyUSB0", {debug: true}); /* * This reports security updates from X10 security devices. */ rfxtrx.on("security1", function (evt) { if (evt.deviceStatus === rfxcom.security.MOTION) { console.log("Device %s %s detected motion.", evt.subtype, evt.id); } else if (evt.deviceStatus === rfxcom.security.NOMOTION) { console.log("Device %s %s reported motion stopped.", evt.subtype, evt.id); } }); rfxtrx.on("elec2", function (evt) { // Requires a PostgreSQL table // CREATE TABLE energy (recorded_time timestamp DEFAULT NOW(), // device_id VARCHAR, current_watts FLOAT) client.query("INSERT INTO energy(device_id, current_watts) values($1, $2)", [evt.id, evt.currentWatts]); }); rfxtrx.initialise(function () { console.log("Device initialised"); });
There's a specialised Lighting5 prototype, which uses an RfxCom object.
var rfxcom = require('rfxcom'); var rfxtrx = new rfxcom.RfxCom("/dev/ttyUSB0", {debug: true}), lightwaverf = new rfxcom.Lighting5(rfxtrx, rfxcom.lighting5.LIGHTWAVERF); rfxtrx.initialise(function () { console.log("Device initialised"); lightwaverf.switchOn("0xF09AC8/1", {mood: 0x03}); lightwaverf.switchOn("0xF09AC8/2", {level: 0x10}); });
I've tested it with both LightwaveRf lights, and the relay switch.
LightwaveRf lights get their identity from the remote used to pair, if you don't have a remote, or if you want to specify the address manually, you can pair the device by putting the device into pairing mode and turning on a device id, lightwaverf.switchOn("0xFFFFFF/1").
The device ids don't have to be unique, but it's advisable.
There's a specialised Lighting2 prototype, which uses an RfxCom object.
var rfxtrx = new rfxcom.RfxCom("/dev/ttyUSB0", {debug: true}), lighting2 = new rfxcom.Lighting2(rfxtrx, rfxcom.lighting2.HOMEEASY_EU); lighting2.switchOn("0xF09AC8AA/1"); lighting2.switchOff("0xF09AC8AA/1");
The lighting2 message controls one of three subtypes, you need to specify the subtype to the constructor, the options are in rfxcom.lighting2.
The events are named from the message identifiers sent by the RFXtrx device.
Emitted when the RFXcom has successfully opened the serial port.
Emitted when a response message is received from the RFXtrx 433, sends the status (from the RFXtrx433) and the sequence number of the message the response is for.
Emitted when a "status" message is received from the RFXtrx 433.
Emitted when any message is received from the RFXtrx 433, sends the raw bytes that were received.
Emitted when data is received from OWL electricity monitoring devices CM119/CM160.
Emitted when an X10 security device reports a status change.
Emitted when a message is received from LightwaveRF type devices.
Emitted when a message is received from Oregon Scientific Temperature/Humidity sensors.
Emitted when a message is received from an Oregon Scientific temperature sensor.
Emitted when a message is received from AC/HomeEasy type devices.