From ef39f77d28d5e131d021382ac5c780090b865bf2 Mon Sep 17 00:00:00 2001 From: ka-vaNu Date: Mon, 1 May 2023 18:54:22 +0200 Subject: [PATCH 1/2] Add role, read, write to setObject --- lib/tools.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tools.js b/lib/tools.js index 590fd03..55fa686 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -70,6 +70,9 @@ async function initIobStates (name, datapoints) { iob.setObject(path, { type: iobObject.type, common: iobObject.common, + role: iobObject.role, + read: iobObject.read, + write: iobObject.write, native: {} }); } From bf3f5fccaca32dda879d2cbef8abd4a3c132ed82 Mon Sep 17 00:00:00 2001 From: ka-vaNu Date: Fri, 13 Oct 2023 22:20:55 +0200 Subject: [PATCH 2/2] =?UTF-8?q?multisensor=20unterst=C3=BCtzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + admin/jsonConfig.json | 4 ++ lib/multisensor.js | 160 ++++++++++++++++++++++++++++++++++++++++++ lib/tools.js | 5 +- main.js | 15 ++++ 5 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 lib/multisensor.js diff --git a/README.md b/README.md index 3b492ab..f51e033 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Aktuell werden folgende Geräte unterstützt: * tempsensor * gatebox * tvlift +* multisensor - nicht mit realer Hardware getestet, es werden bis zu 4 Sensoren unterstützt ## Changelog diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 4480b36..cf99aee 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -88,6 +88,10 @@ "label": "tempsensor", "value": "tempsensor" }, + { + "label": "multisensor", + "value": "multisensor" + }, { "label": "tvlift", "value": "tvlift" diff --git a/lib/multisensor.js b/lib/multisensor.js new file mode 100644 index 0000000..dea78a7 --- /dev/null +++ b/lib/multisensor.js @@ -0,0 +1,160 @@ +const datapoints = { + "multisensor#device.deviceName": { + path: "device.deviceName", type: "state", common: { name: "Devicename", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.type": { + path: "device.type", type: "state", common: { name: "Type", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.product": { + path: "device.product", type: "state", common: { name: "Product", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.fv": { + path: "device.fv", type: "state", common: { name: "Firmwareversion", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.hv": { + path: "device.hv", type: "state", common: { name: "Hardwareversion", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.apiLevel": { + path: "device.apiLevel", type: "state", common: { name: "ApiLevel", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.id": { + path: "device.id", type: "state", common: { name: "ID", type: "string", role: "text", read: true, write: false } + }, + "multisensor#device.ip": { + path: "device.ip", type: "state", common: { name: "IP-Adress", type: "string", role: "text", read: true, write: false } + }, + "multisensor#upTimeS": { + path: "upTimeS", type: "state", common: { name: "Uptime in seconds", type: "number", role: "value", read: true, write: false } + }, + "multisensor#settings.deviceName": { + path: "settings.deviceName", type: "state", common: { name: "Device name.", type: "string", role: "text", read: true, write: false } + }, + "multisensor#settings.statusLed.enabled": { + path: "settings.statusLed.enabled", type: "state", common: { name: "Status led enabled (0 - disabled, 1 - enabled)", type: "number", role: "value", read: true, write: false } + }, + "multisensor#settings.tunnel.enabled": { + path: "settings.tunnel.enabled", type: "state", common: { name: "Tunnel enabled (0 - disabled, 1 - enabled)", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].elapsedTimeS": { + path: "multiSensor.sensors.0.elapsedTimeS", type: "state", common: { name: "Time in seconds that has elapsed since last valid measurement occurred, where -1 = Error, 0 = Fresh data", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].state": { + path: "multiSensor.sensors.0.state", type: "state", common: { name: "Status of sensor, where 1 = Measure in progress, 2 = Active Mode, 3 = Error", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].trend": { + path: "multiSensor.sensors.0.trend", type: "state", common: { name: "Trend of measured data, where 0 = no data, 1 = sidewave, 2 = Downward, 3 = Upward", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].value": { + path: "multiSensor.sensors.0.value", factor: 0.01, type: "state", common: { name: "Value of measured data, where null = Error and Temperature in Celsius degrees.", type: "number", role: "value.temperature", read: true, write: false, unit: "°C" } + }, + "multisensor#multiSensor.sensors[0].type": { + path: "multiSensor.sensors.0.type", type: "state", common: { name: "Type of measured value", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].id": { + path: "multiSensor.sensors.0.id", type: "state", common: { name: "ID of internal sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].iconSet": { + path: "multiSensor.sensors.0.iconSet", type: "state", common: { name: "Type of icon", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[0].name": { + path: "multiSensor.sensors.0.name", type: "state", common: { name: "Personalized name of the sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].elapsedTimeS": { + path: "multiSensor.sensors.1.elapsedTimeS", type: "state", common: { name: "Time in seconds that has elapsed since last valid measurement occurred, where -1 = Error, 0 = Fresh data", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].state": { + path: "multiSensor.sensors.1.state", type: "state", common: { name: "Status of sensor, where 1 = Measure in progress, 2 = Active Mode, 3 = Error", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].trend": { + path: "multiSensor.sensors.1.trend", type: "state", common: { name: "Trend of measured data, where 0 = no data, 1 = sidewave, 2 = Downward, 3 = Upward", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].value": { + path: "multiSensor.sensors.1.value", factor: 0.01, type: "state", common: { name: "Value of measured data, where null = Error and Temperature in Celsius degrees.", type: "number", role: "value.temperature", read: true, write: false, unit: "°C" } + }, + "multisensor#multiSensor.sensors[1].type": { + path: "multiSensor.sensors.1.type", type: "state", common: { name: "Type of measured value", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].id": { + path: "multiSensor.sensors.1.id", type: "state", common: { name: "ID of internal sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].iconSet": { + path: "multiSensor.sensors.1.iconSet", type: "state", common: { name: "Type of icon", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[1].name": { + path: "multiSensor.sensors.1.name", type: "state", common: { name: "Personalized name of the sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].elapsedTimeS": { + path: "multiSensor.sensors.2.elapsedTimeS", type: "state", common: { name: "Time in seconds that has elapsed since last valid measurement occurred, where -1 = Error, 0 = Fresh data", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].state": { + path: "multiSensor.sensors.2.state", type: "state", common: { name: "Status of sensor, where 1 = Measure in progress, 2 = Active Mode, 3 = Error", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].trend": { + path: "multiSensor.sensors.2.trend", type: "state", common: { name: "Trend of measured data, where 0 = no data, 1 = sidewave, 2 = Downward, 3 = Upward", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].value": { + path: "multiSensor.sensors.2.value", factor: 0.01, type: "state", common: { name: "Value of measured data, where null = Error and Temperature in Celsius degrees.", type: "number", role: "value.temperature", read: true, write: false, unit: "°C" } + }, + "multisensor#multiSensor.sensors[2].type": { + path: "multiSensor.sensors.2.type", type: "state", common: { name: "Type of measured value", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].id": { + path: "multiSensor.sensors.2.id", type: "state", common: { name: "ID of internal sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].iconSet": { + path: "multiSensor.sensors.2.iconSet", type: "state", common: { name: "Type of icon", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[2].name": { + path: "multiSensor.sensors.2.name", type: "state", common: { name: "Personalized name of the sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].elapsedTimeS": { + path: "multiSensor.sensors.3.elapsedTimeS", type: "state", common: { name: "Time in seconds that has elapsed since last valid measurement occurred, where -1 = Error, 0 = Fresh data", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].state": { + path: "multiSensor.sensors.3.state", type: "state", common: { name: "Status of sensor, where 1 = Measure in progress, 2 = Active Mode, 3 = Error", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].trend": { + path: "multiSensor.sensors.3.trend", type: "state", common: { name: "Trend of measured data, where 0 = no data, 1 = sidewave, 2 = Downward, 3 = Upward", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].value": { + path: "multiSensor.sensors.3.value", factor: 0.01, type: "state", common: { name: "Value of measured data, where null = Error and Temperature in Celsius degrees.", type: "number", role: "value.temperature", read: true, write: false, unit: "°C" } + }, + "multisensor#multiSensor.sensors[3].type": { + path: "multiSensor.sensors.3.type", type: "state", common: { name: "Type of measured value", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].id": { + path: "multiSensor.sensors.3.id", type: "state", common: { name: "ID of internal sensor", type: "string", role: "text", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].iconSet": { + path: "multiSensor.sensors.3.iconSet", type: "state", common: { name: "Type of icon", type: "number", role: "value", read: true, write: false } + }, + "multisensor#multiSensor.sensors[3].name": { + path: "multiSensor.sensors.3.name", type: "state", common: { name: "Personalized name of the sensor", type: "string", role: "text", read: true, write: false } + } +}; + +function init () { + +} + +// eslint-disable-next-line no-unused-vars +function getApiUrl (type, value) { + switch (type) { + case "deviceState": + return "/api/device/state"; + case "deviceUptime": + return "/api/device/uptime"; + case "settingsState": + return "/api/settings/state"; + case "multisensorExtendedState": + return "/state/extended"; + default: + break; + } +} + +module.exports = { + datapoints, + init, + getApiUrl +}; diff --git a/lib/tools.js b/lib/tools.js index eaaab8f..ae0398d 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -70,6 +70,9 @@ async function initIobStates (name, datapoints) { iob.setObject(path, { type: iobObject.type, common: iobObject.common, + role: iobObject.role, + read: iobObject.read, + write: iobObject.write, native: {} }); } @@ -100,7 +103,7 @@ async function setIobStates (device, values) { } } } else { - if (iob.extLog) iob.log.info("setIobStates search: " + search + " not found"); + if (iob.extLog) iob.log.warn("setIobStates search: " + search + " not found"); } } } diff --git a/main.js b/main.js index f4a366b..e74168b 100644 --- a/main.js +++ b/main.js @@ -9,6 +9,7 @@ const gatebox = require("./lib/gatebox"); const shutterbox = require("./lib/shutterbox"); const switchbox = require("./lib/switchbox"); const tempsensor = require("./lib/tempsensor"); +const multisensor = require("./lib/multisensor"); const saunabox = require("./lib/saunabox"); const tvlift = require("./lib/tvlift"); @@ -100,6 +101,15 @@ class Blebox extends utils.Adapter { tools.getBleboxData(device, "deviceUptime"); }); break; + case "multisensor": + multisensor.init(); + tools.getBleboxData(device, "deviceState"); + tools.getBleboxData(device, "multisensorExtendedState"); + schedule.scheduleJob("*/10 * * * * *", function () { + tools.getBleboxData(device, "multisensorExtendedState"); + tools.getBleboxData(device, "deviceUptime"); + }); + break; case "saunabox": saunabox.init(); tools.getBleboxData(device, "deviceState"); @@ -425,6 +435,9 @@ class Blebox extends utils.Adapter { case "tempsensor": locationUrl = tempsensor.getApiUrl(type, val); break; + case "multisensor": + locationUrl = multisensor.getApiUrl(type, val); + break; default: break; @@ -452,6 +465,8 @@ class Blebox extends utils.Adapter { return switchbox.datapoints; case "tempsensor": return tempsensor.datapoints; + case "multisensor": + return multisensor.datapoints; case "saunabox": return saunabox.datapoints; default: