From 9cf3b3bdd650b9673af81b9462bd37f96df91df5 Mon Sep 17 00:00:00 2001 From: faanskit Date: Thu, 20 May 2021 07:24:22 +0200 Subject: [PATCH 1/2] Fix for issue discussed im #198. Scene device triggers were not unique from Scenes and device_trigger /config topic was too long --- plejd/MqttClient.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plejd/MqttClient.js b/plejd/MqttClient.js index 47c7d92..5be9434 100644 --- a/plejd/MqttClient.js +++ b/plejd/MqttClient.js @@ -36,7 +36,7 @@ const getTopicName = ( ) => `${getBaseTopic(uniqueId, mqttDeviceType)}/${topicType}`; const getButtonEventTopic = (/** @type {string} */ deviceId) => `${getTopicName(deviceId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`; -const getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trigger`; +const getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trig`; const getSceneEventTopic = (/** @type {string} */ sceneId) => `${getTopicName(getTriggerUniqueId(sceneId), MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`; const getSubscribePath = () => `${discoveryPrefix}/+/${nodeId}/#`; @@ -110,13 +110,13 @@ const getSceneDeviceTriggerhDiscoveryPayload = ( /** @type {import('./types/DeviceRegistry').OutputDevice} */ sceneDevice, ) => ({ automation_type: 'trigger', - '~': getBaseTopic(sceneDevice.uniqueId, MQTT_TYPES.DEVICE_AUTOMATION), + '~': getBaseTopic(`${sceneDevice.uniqueId}_trig`, MQTT_TYPES.DEVICE_AUTOMATION), qos: 1, topic: `~/${TOPIC_TYPES.STATE}`, type: 'scene', subtype: 'trigger', device: { - identifiers: `${sceneDevice.uniqueId}`, + identifiers: `${sceneDevice.uniqueId}_trigger`, manufacturer: 'Plejd', model: sceneDevice.typeName, name: sceneDevice.name, From 93eca16639e6a6bd1098d061cf6cd8e2da46d568 Mon Sep 17 00:00:00 2001 From: faanskit Date: Thu, 20 May 2021 13:49:44 +0200 Subject: [PATCH 2/2] Added support to report back to HA via MQTT when a Scene is executed, so that following device_automations gets executed. This will make Plejd Scene execution behave the same from Plejd App, Plejd Hardware and Home Assistant Scene triggered - in the eyes of Home Assistant --- plejd/PlejdAddon.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plejd/PlejdAddon.js b/plejd/PlejdAddon.js index 89e8310..323678b 100644 --- a/plejd/PlejdAddon.js +++ b/plejd/PlejdAddon.js @@ -76,6 +76,15 @@ class PlejdAddon extends EventEmitter { // we're triggering a scene, lets do that and jump out. // since scenes aren't "real" devices. this.sceneManager.executeScene(uniqueId); + + // since the scene doesn't get any updates on whether it's executed or not, + // we fake this by directly send the sceneTriggered back to HA in order for + // it continue to acto on the scene (for non-plejd devices). + try { + this.mqttClient.sceneTriggered(uniqueId); + } catch (err) { + logger.error('Error in PlejdService.sceneTriggered callback', err); + } return; }