Skip to content

Commit

Permalink
feat: move to zwavejs 7 (#864)
Browse files Browse the repository at this point in the history
bump [email protected] and @zwave-js/[email protected]

BREAKING CHANGE: Most changes are already documented [here](https://zwave-js.github.io/node-zwave-js/#/getting-started/migrating-to-v7):
- Corrected parsing of Node Information Frames (NIF), reworked node properties
- No automatic query of all node values when restarting from cache, `interview completed` event is no longer emitted on startup
- Reworked "notification" event, node notifications are mapped to mqtt using a different topic/payload
- This version is incompatible with HA versions before 2021.4.x
  • Loading branch information
robertsLando authored Mar 24, 2021
1 parent c2acda9 commit 0bff7a7
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 216 deletions.
131 changes: 78 additions & 53 deletions docs/guide/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,73 +232,98 @@ Payload:

## Special topics

- **App version**:
### App version

`<mqtt_prefix>/_CLIENTS/ZWAVE_GATEWAY-<mqtt_name>/version`
`<mqtt_prefix>/_CLIENTS/ZWAVE_GATEWAY-<mqtt_name>/version`

The payload will be in the time-value json format and the value will contain the app string version.
The payload will be in the time-value json format and the value will contain the app string version.

- **Mqtt status**:
### Mqtt status

`<mqtt_prefix>/_CLIENTS/ZWAVE_GATEWAY-<mqtt_name>/status`
`<mqtt_prefix>/_CLIENTS/ZWAVE_GATEWAY-<mqtt_name>/status`

The payload will be in the time-value json format and the value will be `true` when mqtt is connected, `false` otherwise.
The payload will be in the time-value json format and the value will be `true` when mqtt is connected, `false` otherwise.

- **Node status**:
### Node status

`<mqtt_prefix>/<?node_location>/<node_name>/status`
`<mqtt_prefix>/<?node_location>/<node_name>/status`

The payload will be `true` if node is ready `false` otherwise. If the payload is in JSON format it will also contain the node status string in `status` property (`Alive`, `Awake`, `Dead`)
The payload will be `true` if node is ready `false` otherwise. If the payload is in JSON format it will also contain the node status string in `status` property (`Alive`, `Awake`, `Dead`)

- **Node information**:
### Node information

`<mqtt_prefix>/<?node_location>/<node_name>/nodeinfo`
`<mqtt_prefix>/<?node_location>/<node_name>/nodeinfo`

Payload includes all node details except Discovered devices, values and properties.
Updates on every node change.
Payload includes all node details except Discovered devices, values and properties.
Updates on every node change.

A example of payload is:
A example of payload is:

```json
{
"id": 97,
"deviceId": "271-4098-2049",
"manufacturer": "Fibargroup",
"manufacturerId": 271,
"productType": 2049,
"productId": 4098,
"name": "Sensor",
"loc": "Hallway",
"neighbors": [29, 43, 63, 64, 65, 66, 67, 72, 74, 86],
"ready": true,
"available": true,
"failed": false,
"lastActive": 1610009585743,
"interviewCompleted": true,
"firmwareVersion": "3.3",
"isBeaming": true,
"isSecure": false,
"keepAwake": false,
"maxBaudRate": null,
"isRouting": true,
"isFrequentListening": false,
"isListening": false,
"status": "Asleep",
"interviewStage": "Complete",
"productLabel": "FGMS001",
"productDescription": "Motion Sensor",
"zwaveVersion": 4,
"deviceClass": {
"basic": 4,
"generic": 7,
"specific": 1
},
"hexId": "0x010f-0x1002-0x0801"
```json
{
"id": 97,
"deviceId": "271-4098-2049",
"manufacturer": "Fibargroup",
"manufacturerId": 271,
"productType": 2049,
"productId": 4098,
"name": "Sensor",
"loc": "Hallway",
"neighbors": [29, 43, 63, 64, 65, 66, 67, 72, 74, 86],
"ready": true,
"available": true,
"failed": false,
"lastActive": 1610009585743,
"firmwareVersion": "3.3",
"supportsBeaming": true,
"isSecure": false,
"keepAwake": false,
"maxBaudRate": null,
"isRouting": true,
"isFrequentListening": false,
"isListening": false,
"status": "Asleep",
"interviewStage": "Complete",
"productLabel": "FGMS001",
"productDescription": "Motion Sensor",
"zwaveVersion": 4,
"deviceClass": {
"basic": 4,
"generic": 7,
"specific": 1
},
"hexId": "0x010f-0x1002-0x0801"
}
```

### Node notifications

Node notifications are translated to valueIds based on the CC that is triggerig the notification and the notification args. Topic and payload depends on your gateway settings

#### Entry CC

ValueId:

```js
{
...
property: args.eventType
propertyKey: args.dataType
}
```
```

Data: `args.eventData`

- **Node notifications**:
#### Notification CC

`<mqtt_prefix>/<?node_location>/<node_name>/notification/<notificationLabel>`
ValueId:

```js
{
...
property: args.label
propertyKey: args.eventLabel
}
```

The payload will be the notification `parameters` (can be null or not based on the notification type)
Data: `args.parameters`
24 changes: 8 additions & 16 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,28 +332,20 @@ function onValueChanged (valueId, node, changed) {
}

/**
* Triggered when a notification is received from Zwave Client
* Triggered when a notification is received from a node in Zwave Client
*
* @param {import('../types').Z2MNode} node
* @param {string} notificationLabel
* @param {string|number} parameters
* @param {import('../types/index.js').Z2MValueId} valueId
* @param {any} data
*/
function onNotification (node, notificationLabel, parameters) {
const topic =
this.nodeTopic(node) +
'/notification/' +
utils.sanitizeTopic(notificationLabel, true)
let data

parameters = parameters ? parameters.toString() : null
function onNotification (node, valueId, data) {
const topic = this.valueTopic(node, valueId)

if (this.config.payloadType === 2) {
data = parameters
} else {
data = { time: Date.now(), value: parameters }
if (this.config.payloadType !== 2) {
data = { time: Date.now(), value: data }
}

this.mqtt.publish(topic, data)
this.mqtt.publish(topic, data, { retain: false })
}

/**
Expand Down
Loading

0 comments on commit 0bff7a7

Please sign in to comment.