This project will take an existing MQTT based MySensors network and act as its controller.
It will expose the network via the Homie convention, again on MQTT.
This provides bidirectional access, and auto detection via the Homie convention for automation servers that support Homie, but do not support MySensors via the MQTT gateway.
MySensors - https://www.mysensors.org/ Homie - https://homieiot.github.io/
Download this repo.
Edit the configuration file config.json
to set your MQTT broker.
Currently, this is the same one that your MySensors gateway is connected, and the one where a matching Homie network will be created by the adatper.
> yarn
> yarn start
Then, (re) start your MySensors nodes to have them detected and republished using the Homie convention
You will need an automation server of some sort that understand Homie.
I have used this successfully with OpenHab 3 and the MQTT Binding, which has Homie support built in.
An example S_BINARY/ relay control arduino sketch that runs with a RF-NANO/ RF24 based MySensor setup is in the examples folder.
See mysensors-homie.json
[
{
"nodeId": "2",
"repeater": true,
"name": "TestDevice",
"sensors": [
{
"id": "1",
"type": "S_BINARY"
}
]
},
{
"nodeId": "1",
"repeater": true,
"name": "Relay+button",
"sensors": [
{
"id": "1",
"type": "S_BINARY"
}
]
}
]
As below, not all MySensors types are fully supported.
The full list of MySensors types is at https://www.mysensors.org/download/serial_api_20
Create a new handler in src/type-handler/[name_of_type].ts
(for example s_binary.ts
)
export function setupSBinary(homieNode: HomieNode, node: MSNode, sensor: Sensor) {
sensor.handler = async cmd => { (1)
homieNode.setProperty(sensor.type + "_" + sensor.id).setRetained(true).send(cmd.payload == "1" ? "true" : "false");
}
(2)
homieNode.advertise(sensor.type + "_" + sensor.id).setName('on/off').setDatatype('boolean').settable(function (range: any, value: any) {
console.log(`[homie] NODE ${node.nodeId}: Switching ${sensor.id} on/ off ` + value)
return sendMySensorsCommand({ (3)
nodeId: node.nodeId,
childSensorId: sensor.id,
command: "SET",
ack: "0",
type: "V_STATUS",
payload: value == "true" ? "1" : "0"
}, client)
});
}
-
Register a handler against the sensor. All MySensors commands that are received for this sensor will be passed to this handler.
-
Advertise the sensor on the Homie network against the auto created Homie Node. This is the API - https://github.com/microclimates/homie-device
-
When a
settable
Homie property is set, you will receive messages for it. These can be translated to MySensors commands here.
This is Work In Progress
Stores the current MySensors network in a local state file (mysensors-homie.json), will re-advertise it on startup.
Controller will give out new MySensors IDs, and register the existence of static/ existing IDs.
All values below are the same as in the MySensors Serial API 2.0 https://www.mysensors.org/download/serial_api_20
ID |
TYPE |
SUPPORTED |
0 |
PRESENT |
✅ |
1 |
SET |
✅ |
2 |
REQ |
✅ |
3 |
INTERNAL |
✅ |
4 |
STREAM |
❌ |
ID |
TYPE |
SUPPORTED |
0 |
S_DOOR |
❌ |
1 |
S_MOTION |
❌ |
2 |
S_SMOKE |
❌ |
3 |
S_BINARY |
✅ |
4 |
S_DIMMER |
❌ |
5 |
S_COVER |
❌ |
6 |
S_TEMP |
✅ |
7 |
S_HUM |
✅ |
8 |
S_BARO |
❌ |
9 |
S_WIND |
❌ |
10 |
S_RAIN |
❌ |
11 |
S_UV |
❌ |
12 |
S_WEIGHT |
❌ |
13 |
S_POWER |
❌ |
14 |
S_HEATER |
❌ |
15 |
S_DISTANCE |
❌ |
16 |
S_LIGHT_LEVEL |
❌ |
17 |
S_ARDUINO_NODE |
❌ |
18 |
S_ARDUINO_REPEATER_NODE |
❌ |
19 |
S_LOCK |
❌ |
20 |
S_IR |
❌ |
21 |
S_WATER |
❌ |
22 |
S_AIR_QUALITY |
❌ |
23 |
S_CUSTOM |
❌ |
24 |
S_DUST |
❌ |
25 |
S_SCENE_CONTROLLER |
❌ |
26 |
S_RGB_LIGHT |
❌ |
27 |
S_RGBW_LIGHT |
❌ |
28 |
S_COLOR_SENSOR |
❌ |
29 |
S_HVAC |
❌ |
30 |
S_MULTIMETER |
❌ |
31 |
S_SPRINKLER |
❌ |
32 |
S_WATER_LEAK |
❌ |
33 |
S_SOUND |
❌ |
34 |
S_VIBRATION |
❌ |
35 |
S_MOISTURE |
❌ |
36 |
S_INFO |
❌ |
37 |
S_GAS |
❌ |
38 |
S_GPS |
❌ |
39 |
S_WATER_QUALITY |
❌ |
ID |
TYPE |
From Sensor |
To Sensor |
0 |
V_TEMP |
✅ |
➖ |
1 |
V_HUM |
✅ |
➖ |
2 |
V_STATUS |
✅ |
✅ |
3 |
V_PERCENTAGE |
❌ |
❌ |
4 |
V_PRESSURE |
❌ |
❌ |
5 |
V_FORECAST |
❌ |
❌ |
6 |
V_RAIN |
❌ |
❌ |
7 |
V_RAINRATE |
❌ |
❌ |
8 |
V_WIND |
❌ |
❌ |
9 |
V_GUST |
❌ |
❌ |
10 |
V_DIRECTION |
❌ |
❌ |
11 |
V_UV |
❌ |
❌ |
12 |
V_WEIGHT |
❌ |
❌ |
13 |
V_DISTANCE |
❌ |
❌ |
14 |
V_IMPEDANCE |
❌ |
❌ |
15 |
V_ARMED |
❌ |
❌ |
16 |
V_TRIPPED |
❌ |
❌ |
17 |
V_WATT |
❌ |
❌ |
18 |
V_KWH |
❌ |
❌ |
19 |
V_SCENE_ON |
❌ |
❌ |
20 |
V_SCENE_OFF |
❌ |
❌ |
21 |
V_HVAC_FLOW_STATE |
❌ |
❌ |
22 |
V_HVAC_SPEED |
❌ |
❌ |
23 |
V_LIGHT_LEVEL |
❌ |
❌ |
24 |
V_VAR1 |
❌ |
❌ |
25 |
V_VAR2 |
❌ |
❌ |
26 |
V_VAR3 |
❌ |
❌ |
27 |
V_VAR4 |
❌ |
❌ |
28 |
V_VAR5 |
❌ |
❌ |
29 |
V_UP |
❌ |
❌ |
30 |
V_DOWN |
❌ |
❌ |
31 |
V_STOP |
❌ |
❌ |
32 |
V_IR_SEND |
❌ |
❌ |
33 |
V_IR_RECEIVE |
❌ |
❌ |
34 |
V_FLOW |
❌ |
❌ |
35 |
V_VOLUME |
❌ |
❌ |
36 |
V_LOCK_STATUS |
❌ |
❌ |
37 |
V_LEVEL |
❌ |
❌ |
38 |
V_VOLTAGE |
❌ |
❌ |
39 |
V_CURRENT |
❌ |
❌ |
40 |
V_RGB |
❌ |
❌ |
41 |
V_RGBW |
❌ |
❌ |
42 |
V_ID |
❌ |
❌ |
43 |
V_UNIT_PREFIX |
❌ |
❌ |
44 |
V_HVAC_SETPOINT_COOL |
❌ |
❌ |
45 |
V_HVAC_SETPOINT_HEAT |
❌ |
❌ |
46 |
V_HVAC_FLOW_MODE |
❌ |
❌ |
47 |
V_TEXT |
❌ |
❌ |
48 |
V_CUSTOM |
❌ |
❌ |
49 |
V_POSITION |
❌ |
❌ |
50 |
V_IR_RECORD |
❌ |
❌ |
51 |
V_PH |
❌ |
❌ |
52 |
V_ORP |
❌ |
❌ |
53 |
V_EC |
❌ |
❌ |
54 |
V_VAR |
❌ |
❌ |
55 |
V_VA |
❌ |
❌ |
56 |
V_POWER_FACTOR |
❌ |
❌ |
ID |
TYPE |
SUPPORTED |
0 |
I_BATTERY_LEVEL |
❌ |
1 |
I_TIME |
❌ |
2 |
I_VERSION |
❌ |
3 |
I_ID_REQUEST |
✅ |
4 |
I_ID_RESPONSE |
✅ |
5 |
I_INCLUSION_MODE |
❌ |
6 |
I_CONFIG |
❌ |
7 |
I_FIND_PARENT |
❌ |
8 |
I_FIND_PARENT_RESPONSE |
❌ |
9 |
I_LOG_MESSAGE |
❌ |
10 |
I_CHILDREN |
❌ |
11 |
I_SKETCH_NAME |
✅ |
12 |
I_SKETCH_VERSION |
❌ |
13 |
I_REBOOT |
❌ |
14 |
I_GATEWAY_READY |
❌ |
15 |
I_SIGNING_PRESENTATION |
❌ |
16 |
I_NONCE_REQUEST |
❌ |
17 |
I_NONCE_RESPONSE |
❌ |
18 |
I_HEARTBEAT_REQUEST |
❌ |
19 |
I_PRESENTATION |
❌ |
20 |
I_DISCOVER_REQUEST |
❌ |
21 |
I_DISCOVER_RESPONSE |
❌ |
22 |
I_HEARTBEAT_RESPONSE |
❌ |
23 |
I_LOCKED |
❌ |
24 |
I_PING |
❌ |
25 |
I_PONG |
❌ |
26 |
I_REGISTRATION_REQUEST |
❌ |
27 |
I_REGISTRATION_RESPONSE |
❌ |
28 |
I_DEBUG |
❌ |
29 |
I_SIGNAL_REPORT_REQUEST |
❌ |
30 |
I_SIGNAL_REPORT_REVERSE |
❌ |
31 |
I_SIGNAL_REPORT_RESPONSE |
❌ |
32 |
I_PRE_SLEEP_NOTIFICATION |
❌ |
33 |
I_POST_SLEEP_NOTIFICATION |
❌ |
Stream is not supported
Homie device code derived from this - https://github.com/microclimates/homie-device
-
Converted to typescript
-
Shared MQTT connection