Get dp from NSPanelSendTopic

This commit is contained in:
ticaki
2024-01-08 22:23:06 +01:00
parent 2621b22ffd
commit aa3e90ef98

View File

@@ -204,7 +204,6 @@ let Debug: boolean = false;
// EN: Adapt to the MQTT adapter instance directories // EN: Adapt to the MQTT adapter instance directories
const NSPanelReceiveTopic: string = 'mqtt.0.SmartHome.NSPanel_1.tele.RESULT'; const NSPanelReceiveTopic: string = 'mqtt.0.SmartHome.NSPanel_1.tele.RESULT';
const NSPanelSendTopic: string = 'mqtt.0.SmartHome.NSPanel_1.cmnd.CustomSend'; const NSPanelSendTopic: string = 'mqtt.0.SmartHome.NSPanel_1.cmnd.CustomSend';
NSPanelStateTopic = 'mqtt.0.SmartHome.NSPanel_1.stat'
// DE: nur ändern, falls der User im Tasmota vor dem Kompilieren umbenannt wurde (Standard Tasmota: admin) // DE: nur ändern, falls der User im Tasmota vor dem Kompilieren umbenannt wurde (Standard Tasmota: admin)
// EN: only change if the user was renamed in Tasmota before compiling (default Tasmota: admin) // EN: only change if the user was renamed in Tasmota before compiling (default Tasmota: admin)
@@ -972,9 +971,6 @@ let weatherForecast: boolean;
let pageCounter: number = 0; let pageCounter: number = 0;
let alwaysOn: boolean = false; let alwaysOn: boolean = false;
var NSPanelStateTopic = NSPanelStateTopic !== undefined ? NSPanelStateTopic : ''
const axios = require('axios'); const axios = require('axios');
const dayjs = require('dayjs'); const dayjs = require('dayjs');
const moment = require('moment'); const moment = require('moment');
@@ -1730,18 +1726,17 @@ on({id: [String(NSPanel_Path) + 'Config.Dateformat.Switch.weekday',
} }
}); });
//Set Relays from Tasmota //Set Relays from Tasmota
if (NSPanelStateTopic != '') { const NSPanelStatTopic = NSPanelSendTopic.replace('.tele.','.stat.').replace('.CustomSend','.');
on({id: [String(NSPanelStateTopic) + '.POWER1',String(NSPanelStateTopic) + '.POWER2'], change: "ne"}, (obj) => { on({id: [String(NSPanelStatTopic) + 'POWER1',String(NSPanelStatTopic) + 'POWER2'], change: "ne"}, (obj) => {
if (!obj || !obj.id) return if (!obj || !obj.id) return
const n = obj.id.substring(obj.id.length-1); const n = obj.id.substring(obj.id.length-1);
if ( n === '1' || n === '2') { if ( n === '1' || n === '2') {
if (getState(NSPanel_Path + 'Relay.' + n).val != obj.state.val) { if (getState(NSPanel_Path + 'Relay.' + n).val != obj.state.val) {
setState(NSPanel_Path + 'Relay.' + n, obj.state.val == 'ON' ? true : false, true); setState(NSPanel_Path + 'Relay.' + n, obj.state.val == 'ON' ? true : false, true);
}
} }
}) }
} })
//Control Relays from DP's //Control Relays from DP's
on({id: [String(NSPanel_Path) + 'Relay.1',String(NSPanel_Path) + 'Relay.2'], change: "ne", ack: false}, async function (obj) { on({id: [String(NSPanel_Path) + 'Relay.1',String(NSPanel_Path) + 'Relay.2'], change: "ne", ack: false}, async function (obj) {
try { try {