Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
feat: Publish all magnet statuses.
Browse files Browse the repository at this point in the history
The combined status of all open magnets is now published to extra topic.
This enables you to use this new topic for easier security monitoring.
  • Loading branch information
Stephan van Rooij committed Jul 1, 2018
1 parent 2718fc7 commit 889e6bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ Each status message is retained, so if you subscribe after a status message, you

The statuses of the devices are multicasted over the network if you enbaled this (you SHOULD!!). So all the updates to mqtt are near instant.

### Security message

The total count of magnet sensors with the `open` state will be emitted to: `xiaomi/status/magnets` as a JSON object containing the following fields.

- `name` Either `All closed` or comma seperated list of magnet names with open status.
- `ids` the ids of the magnets with the status `open` as array.
- `val` number of open devices

### Setting the gateway light

You can control the gateway light (if you've set-up the gateway password) by sending a message to `xiaomi/set/gateway_id/light`, send one of these:
Expand Down
15 changes: 15 additions & 0 deletions src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ function publishMagnetState (device, newState) {
magnets.push({id: device.getSid(), state: newState})
}
publishDeviceData(device, newState)
publishOpenMagnetCount()
}

function publishOpenMagnetCount () {
const openMagnets = magnets.filter(m => m.state === 'open')
let data = {
val: openMagnets.length,
name: 'All closed',
ts: Date.now()
}
if (openMagnets.length > 0) {
data.ids = openMagnets.map(m => m.id)
data.name = openMagnets.map(m => getFriendlyName(m.id)).sort().join(', ')
}
mqttClient.publish(`${config.name}/status/magnets`, JSON.stringify(data), {qos: 0, retain: true})
}

function publishHTSensor (sensorDevice) {
Expand Down

0 comments on commit 889e6bc

Please sign in to comment.