added scene event to mqtt
This commit is contained in:
parent
ec624c6773
commit
3aa69d0930
2 changed files with 12 additions and 2 deletions
|
|
@ -32,6 +32,10 @@ async function main() {
|
|||
client.updateState(deviceId, command);
|
||||
});
|
||||
|
||||
plejd.on('sceneTriggered', (scene) => {
|
||||
client.sceneTriggered(scene);
|
||||
});
|
||||
|
||||
// subscribe to changes from HA
|
||||
client.on('stateChanged', (deviceId, command) => {
|
||||
if (command.state === 'ON') {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ const getPath = ({ id, type }) =>
|
|||
const getConfigPath = plug => `${getPath(plug)}/config`;
|
||||
const getStateTopic = plug => `${getPath(plug)}/state`;
|
||||
const getCommandTopic = plug => `${getPath(plug)}/set`;
|
||||
const getSceneEventTopic = () => `plejd/event/scene`;
|
||||
|
||||
const getDiscoveryPayload = device => ({
|
||||
schema: 'json',
|
||||
|
|
@ -147,13 +148,18 @@ class MqttClient extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
logger(JSON.stringify(payload));
|
||||
|
||||
this.client.publish(
|
||||
getStateTopic(device),
|
||||
JSON.stringify(payload)
|
||||
);
|
||||
}
|
||||
|
||||
sceneTriggered(scene) {
|
||||
this.client.publish(
|
||||
getSceneEventTopic(),
|
||||
JSON.stringify({ scene: scene })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { MqttClient };
|
||||
Loading…
Add table
Add a link
Reference in a new issue