Created
January 26, 2024 21:31
-
-
Save pyrou/5457db184bdbd281a340b089aef539f2 to your computer and use it in GitHub Desktop.
Super simple rfxcom mqtt bridge that support Somfy RTS (RFY) and lighting2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mqtt = require("mqtt"); | |
const rfxcom = require('rfxcom') | |
const rfxtrx = new rfxcom.RfxCom("/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1YVC00T-if00-port0", {debug: true}); | |
const lighting2 = new rfxcom.Lighting2(rfxtrx, rfxcom.lighting2.HOMEEASY_EU); | |
const rfy = new rfxcom.Rfy(rfxtrx, rfxcom.rfy.RFY, {venetianBlindsMode: "EU"}); | |
const onJsonMessage = (topic, payload) => { | |
const path = topic.split('/') | |
if (path[0] !== 'rfxcom') { return; } | |
switch (path[1]) { | |
case 'rfy': { | |
const deviceId = path[2] | |
const unitCode = path[3] | |
const command = payload.state; | |
if (["stop", "down", "up"].includes(command)) { | |
rfy.doCommand([deviceId, unitCode], command); | |
} | |
break; | |
} | |
case 'lighting2': { | |
const houseCode = path[2] | |
const unitCode = path[3] | |
const command = payload.state; | |
if (command === "on") { | |
lighting2.switchOn(houseCode + '/' + unitCode) | |
} | |
if (command === "off") { | |
lighting2.switchOff(houseCode + '/' + unitCode) | |
} | |
break; | |
} | |
} | |
} | |
rfxtrx.initialise(function () { | |
console.log("Device initialised"); | |
const client = mqtt.connect("mqtt://127.0.0.1"); | |
client.on("message", (topic, message) => { | |
try { | |
const payload = JSON.parse(message.toString()); | |
onJsonMessage(topic, payload) | |
} catch (e) { | |
console.log(e) | |
} | |
}); | |
client.on("connect", () => { | |
client.subscribe("rfxcom/#", (err) => { | |
if (!err) { | |
console.log('waiting commands') | |
// client.publish("rfxcom/status", "ok"); | |
} | |
}); | |
}); | |
// mosquitto_pub -h localhost -t rfxcom/rfy/0x0FA2EE/1 -m '{"state": "up"}' | |
// mosquitto_pub -h localhost -t rfxcom/lighting2/0x001A6F4/4 -m '{"state": "on"}' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment