Merge pull request #114 from thomasloven/status-topic
Listen for Home Assistant default birth message
This commit is contained in:
commit
594e6e214e
2 changed files with 5 additions and 13 deletions
10
README.md
10
README.md
|
|
@ -93,7 +93,7 @@ If you restore a backup from a 32bit system to a new 64bit system, use the Rebui
|
|||
|
||||
### Configuration
|
||||
|
||||
You need to add the following to your `configuration.yaml` file:
|
||||
You need to add the MQTT integration to Home Assistant either by going to Configuration -> Integrations and clicking the Add Integration button, or by adding the following to your `configuration.yaml` file:
|
||||
|
||||
```
|
||||
mqtt:
|
||||
|
|
@ -102,16 +102,8 @@ mqtt:
|
|||
password: !secret mqtt_password
|
||||
discovery: true
|
||||
discovery_prefix: homeassistant
|
||||
birth_message:
|
||||
topic: 'hass/status'
|
||||
payload: 'online'
|
||||
will_message:
|
||||
topic: 'hass/status'
|
||||
payload: 'offline'
|
||||
```
|
||||
|
||||
The above is used to notify the add-on when Home Assistant has started successfully and let the add-on send the discovery response (containing all devices).
|
||||
|
||||
The plugin needs you to configure some settings before working. You find these on the Add-on page after you've installed it.
|
||||
|
||||
| Parameter | Value |
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const EventEmitter = require('events');
|
|||
const mqtt = require('mqtt');
|
||||
const Logger = require('./Logger');
|
||||
|
||||
const startTopic = 'hass/status';
|
||||
const startTopics = ['hass/status', 'homeassistant/status'];
|
||||
|
||||
const logger = Logger.getLogger('plejd-mqtt');
|
||||
|
||||
|
|
@ -74,9 +74,9 @@ class MqttClient extends EventEmitter {
|
|||
this.client.on('connect', () => {
|
||||
logger.info('Connected to MQTT.');
|
||||
|
||||
this.client.subscribe(startTopic, (err) => {
|
||||
this.client.subscribe(startTopics, (err) => {
|
||||
if (err) {
|
||||
logger.error(`Unable to subscribe to ${startTopic}`);
|
||||
logger.error(`Unable to subscribe to status topics`);
|
||||
}
|
||||
|
||||
self.emit('connected');
|
||||
|
|
@ -100,7 +100,7 @@ class MqttClient extends EventEmitter {
|
|||
? JSON.parse(message.toString())
|
||||
: message.toString();
|
||||
|
||||
if (topic === startTopic) {
|
||||
if (startTopics.includes(topic)) {
|
||||
logger.info('Home Assistant has started. lets do discovery.');
|
||||
self.emit('connected');
|
||||
} else if (topic.includes('set')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue