diff --git a/plejd/main.js b/plejd/main.js index 3130fc7..855037e 100644 --- a/plejd/main.js +++ b/plejd/main.js @@ -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') { diff --git a/plejd/mqtt.js b/plejd/mqtt.js index 5898525..40e6440 100644 --- a/plejd/mqtt.js +++ b/plejd/mqtt.js @@ -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 }; \ No newline at end of file