mydomoathome
Version:
Imperihome ISS API gateway to Domoticz
1,414 lines (1,283 loc) • 98.6 kB
JavaScript
//##############################################################################
// This file is part of MyDomoAtHome - https://github.com/empierre/MyDomoAtHome
// Copyright (C) 2014-2016 Emmanuel PIERRE (domoticz@e-nef.com)
//
// MyDomoAtHome is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// MyDomoAtHome is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MyDomoAtHome. If not, see <http://www.gnu.org/licenses/>.
//##############################################################################
// dependencies
var http = require("http");
var express = require("express");
var _ = require("underscore");
var path = require('path');
var request = require("request");
var nconf = require('nconf');
var fs = require('fs');
var os = require("os");
var moment = require('moment');
var morgan = require('morgan');
var methodOverride = require('method-override');
var bodyParser = require('body-parser');
var basicAuth = require('basic-auth');
var errorHandler = require('errorhandler');
var requester = require('sync-request');
var winston = require('winston');
var pjson = require('./package.json');
var app = express();
global.logger = winston;
//working variaboles
var last_version_dt;
var last_version = getLastVersion();
var ver = pjson.version;
var device_tab = {};
var room_tab = [];
var domo_room_tab = [];
var device = {MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected:null};
var app_name = "MyDomoAtHome";
var domo_path = process.env.DOMO || "http://127.0.0.1:8080";
var port = process.env.PORT || '3002';
var passcode=process.env.SEC||'';
//configuration
app.set('port', port);
app.set('view engine', 'ejs');
var home = process.env.MDAH_HOME || path.resolve(__dirname + "/..");
app.use(express.static(path.join(__dirname + '/public')));
app.set('views', path.resolve(__dirname + '/views'));
app.use(morgan('combined'));
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
logger.add(winston.transports.File, {filename: '/var/log/mydomoathome/usage.log'});
// load conf file
if (fileExists('./config.json')) {
nconf.use('file', {file: './config.json'}, function (err) {
if (err) {
//logger.info("No local conf:" + err.message);
return;
}
});
} else {
//logger.info("No local conf");
}
if (fileExists('/etc/mydomoathome/config.json')) {
nconf.use('file', {file: '/etc/mydomoathome/config.json'}, function (err) {
if (err) {
logger.warn("No global conf in /etc/mydomoathome:" + err.message);
return;
}
});
} else {
logger.warn("No global conf in /etc/mydomoathome");
}
nconf.load(function (err) {
if (err) {
logger.warn("Conf load error:" + err.message);
return;
}
});
if (!nconf.get('domo_path')) {
logger.warn('/etc/mydomoathome/config.json not found, defaulting')
} else {
domo_path = process.env.DOMO || nconf.get('domo_path');
app.set('port', process.env.PORT || nconf.get('port'));
app_name = nconf.get('app_name') || "MyDomoAtHome";
passcode = nconf.get('passcode') || passcode;
}
function fileExists(filePath) {
try {
return fs.statSync(filePath).isFile();
}
catch (err) {
return false;
}
}
function versionCompare(v1, v2, options) {
var lexicographical = options && options.lexicographical,
zeroExtend = options && options.zeroExtend,
v1parts = v1.split('.'),
v2parts = v2.split('.');
function isValidPart(x) {
return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x);
}
if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) {
return NaN;
}
if (zeroExtend) {
while (v1parts.length < v2parts.length) v1parts.push("0");
while (v2parts.length < v1parts.length) v2parts.push("0");
}
if (!lexicographical) {
v1parts = v1parts.map(Number);
v2parts = v2parts.map(Number);
}
for (var i = 0; i < v1parts.length; ++i) {
if (v2parts.length == i) {
return 1;
}
if (v1parts[i] == v2parts[i]) {
continue;
}
else if (v1parts[i] > v2parts[i]) {
return 1;
}
else {
return -1;
}
}
if (v1parts.length != v2parts.length) {
return -1;
}
return 0;
}
function getLastVersion() {
var now = moment();
if ((last_version_dt) && (last_version_dt.isBefore(moment().add(2, 'h')))) {
return (last_version);
} else {
var options = {
url: "https://api.github.com/repos/empierre/MyDomoAtHome/releases/latest",
headers: {
'User-Agent': 'request'
}
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
last_version_dt = now;
last_version = data.tag_name;
logger.info("Refreshing version cache: "+data.tag_name);
return (data.tag_name);
} else {
return ("unknown");
}
});
}
}
function devSt(data) {
var rbl;
var dimmable;
if (data.HaveDimmer === 'true') {
dimmable = 1
} else {
dimmable = 0
}
var deviceId = data.deviceId;
switch (data.Status) {
case "On":
rbl = 1;
var mydev = device_tab[deviceId];
if (mydev) {
if (dimmable) {
mydev.Action = 0;
mydev.MaxDimLevel = data.MaxDimLevel;
} else {
mydev.Action = 1;
}
device_tab[deviceId] = mydev;
} else {
mydev = {MaxDimLevel: null, Action: 1, graph: null, Selector: null};
}
device_tab[deviceId] = mydev;
break;
case "Off":
rbl = 0;
var mydev = device_tab[deviceId];
if (mydev) {
if (dimmable) {
mydev.Action = 0;
mydev.MaxDimLevel = data.MaxDimLevel;
} else {
mydev.Action = 1;
}
device_tab[deviceId] = mydev;
} else {
mydev = {MaxDimLevel: null, Action: 1, graph: null, Selector: null};
}
device_tab[deviceId] = mydev;
break;
case "Open":
rbl = 1;
var mydev = device_tab[deviceId];
if (mydev) {
mydev.Action = 2;
device_tab[deviceId] = mydev;
} else {
mydev = {MaxDimLevel: null, Action: 2, graph: null, Selector: null};
}
device_tab[deviceId] = mydev;
break;
case "Closed":
rbl = 0;
var mydev = device_tab[deviceId];
if (mydev) {
mydev.Action = 2;
device_tab[deviceId] = mydev;
} else {
mydev = {MaxDimLevel: null, Action: 2, graph: null, Selector: null};
}
device_tab[deviceId] = mydev;
break;
case "Panic":
rbl = 1;
var mydev = device_tab[deviceId];
if (mydev) {
mydev.Action = 3;
device_tab[deviceId] = mydev;
} else {
mydev = {MaxDimLevel: null, Action: 3, graph: null, Selector: null};
}
device_tab[deviceId] = mydev;
break;
case "Normal":
rbl = 0;
var mydev = device_tab[deviceId];
if (mydev) {
mydev.Action = 3;
device_tab[deviceId] = mydev;
} else {
mydev = {MaxDimLevel: null, Action: 3, graph: null, Selector: null};
}
device_tab[deviceId] = mydev;
break;
default:
rbl = data.Status;
break;
}
return rbl;
}
function DevSwitch(data) {
var status = 0;
switch (data.Status) {
case 'On':
case 'Open':
case 'Panic':
case 'All On':
status = 1;
break;
case 'Normal':
case 'Off':
case 'Closed':
case 'All Off':
status = 0;
break;
default:
status = 0;
break;
}
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSwitch", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSwitch", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
params.push({"key": "Status", "value": status.toString()});
if(data.Energy) {
params.push({"key": "Energy", "value": data.Energy});
}
//TODO key Energy
myfeed.params = params;
return (myfeed);
}
function DevMultiSwitch(data) {
var ptrn4 = /[\s]+|/;
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevMultiSwitch", "room": "Switches"};
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevMultiSwitch", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevMultiSwitch", "room": "Switches"};
room_tab.Switches=1;
}
var params = [];
params.push({"key": "LastRun", "value": dt});
var status;
//console.log("L:"+data.Level);
var res = data.LevelNames.split('|').join(',');
if(data.LevelOffHidden) {
res = res.replace ("Off,","");
}
var ret = data.LevelNames.split('|');
var mydev = {MaxDimLevel: null, Action: null, graph: null, Selector: ret};
//console.log(mydev);
device_tab[data.idx] = mydev;
var lvl = (data.Level) / 10;
params.push({"key": "Value", "value": ret[lvl].toString()});
params.push({"key": "Choices", "value": res});
myfeed.params = params;
return (myfeed);
};
function DevPush(data) {
var status = 0;
switch (data.SwitchType) {
case 'Push On Button':
status = 1;
break;
case 'Push Off Button':
status = 0;
break;
default:
status = 0;
break;
}
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSwitch", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSwitch", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
//params.push({"key": "Status", "value": status.toString()});
params.push({"key": "pulseable", "value": "1"});
myfeed.params = params;
return (myfeed);
}
function DevRGBLight(data) {
var status = 0;
status = devSt(data);
switch (data.SwitchType) {
case 'Push On Button':
status = 1;
break;
case 'Push Off Button':
status = 0;
break;
default:
status = 0;
break;
}
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevRGBLight", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevRGBLight", "room": "Switches"};
room_tab.Switches=1;
}
if (data.Status.match(/Set Level/) || (data.HaveDimmer === 'true')) {
var mydev = {MaxDimLevel: null, Action: null, graph: null};
if (device_tab[data.idx]) {
mydev = device_tab[data.idx];
}
mydev.MaxDimLevel = data.MaxDimLevel;
mydev.Action = 0;
device_tab[data.idx] = mydev;
params = [];
params.push({"key": "Status", "value": "1"});//hyp: set level only when on
params.push({"key": "dimmable", "value": "1"});
params.push({"key": "Level", "value": data.Level.toString()});
if(data.Energy) {
params.push({"key": "Energy", "value": data.Energy});
}
//TODO whitechannel
//TODO color
//TODO Energy value unit
myfeed.params = params;
} else {
params = [];
params.push({"key": "Status", "value": status});
myfeed.params = params;
}
return (myfeed);
};
function DevDimmer(data) {
var status = 0;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDimmer", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDimmer", "room": "Switches"};
room_tab.Switches=1;
}
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
status = devSt(data);
if (data.Status.match(/Set Level/)) {
status = 1;
}
var mydev = {MaxDimLevel: null, Action: null, graph: null};
if (device_tab[data.idx]) {
mydev = device_tab[data.idx];
}
mydev.MaxDimLevel = data.MaxDimLevel;
mydev.Action = 0;
//console.log(mydev);
device_tab[data.idx] = mydev;
params = [];
params.push({"key": "Status", "value": status.toString()});
if(status == 0) {
params.push({"key": "Level", "value": "0"});
} else {
params.push({"key": "Level", "value": data.Level.toString()});
}
if(data.Energy) {
params.push({"key": "Energy", "value": data.Energy});
}
myfeed.params = params;
return (myfeed);
};
function DevShutterInverted(data) {
var status = 0;
status = devSt(data);
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
var lvl = 0;
var stoppable = 0;
var mydev = {MaxDimLevel: null, Action: null, graph: null};
if (device_tab[data.idx]) {
mydev = device_tab[data.idx];
}
mydev.Action = 5;
mydev.MaxDimLevel = data.MaxDimLevel;
device_tab[data.idx] = mydev;
//console.log(data.Status+" "+data.Level);
if (data.Status === 'Open') {
lvl = data.Level || 100;
status = 1;
} else if (data.Status.match(/Set Level/) || (data.HaveDimmer === 'true')) {
lvl = data.Level;
//console.log(data.status+" "+lvl);
if (lvl > 0) {
status = 1
} else {
status = 0
}
;
} else {
lvl = data.Level || 0;
status = 0;
}
;
//console.log(data.idx+" "+status+" "+lvl);
if ((data.SwitchType === 'Venetian Blinds EU') || (data.SwitchType === 'Venetian Blinds US') || (data.SwitchType === 'RollerTrol, Hasta new')) {
stoppable = 1;
}
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevShutter", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevShutter", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevShutter", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
params.push({"key": "Status", "value": status});
params.push({"key": "Level", "value": lvl.toString()});
params.push({"key": "stopable", "value": stoppable.toString()});
params.push({"key": "pulsable", "value": "0"});
myfeed.params = params;
//console.log(params);
return (myfeed);
};
function DevShutter(data) {
var status = 0;
status = devSt(data);
//Protected device
var mydev = device_tab[data.idx]||{MaxDimLevel: null, Action: null, graph: null, Selector: null, Protected: null};
if (! mydev && (data.Protected === 'true')) {
mydev.Protected = 1;
}
device_tab[data.idx] = mydev;
var lvl = 0;
var stoppable = 0;
var mydev = {MaxDimLevel: null, Action: null, graph: null};
if (device_tab[data.idx]) {
mydev = device_tab[data.idx];
}
mydev.Action = 6;
mydev.MaxDimLevel = data.MaxDimLevel;
device_tab[data.idx] = mydev;
//console.log(data.Status+" "+data.Level);
if (data.Status == 'Open') {
lvl = 100 || data.Level;
status = 1;
} else if ((data.Status.match(/Set Level/) || (data.HaveDimmer === 'true') )) {
lvl = data.Level;
//console.log(data.status+" "+lvl);
if (lvl > 0) {
status = 1
} else {
status = 0
}
} else {
lvl = data.Level || 0;
status = 0;
}
//console.log(data.idx+" "+status+" "+lvl);
if ((data.SwitchType === 'Venetian Blinds EU') || (data.SwitchType === 'Venetian Blinds US') || (data.SwitchType === 'RollerTrol, Hasta new')) {
stoppable = 1;
}
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevShutter", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevShutter", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevShutter", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
params.push({"key": "Status", "value": status});
params.push({"key": "Level", "value": lvl.toString()});
params.push({"key": "stopable", "value": stoppable.toString()});
params.push({"key": "pulsable", "value": "0"});
myfeed.params = params;
return (myfeed);
}
function DevMotion(data) {
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevMotion", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevMotion", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevMotion", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
//console.log(data.Status+" "+value);
params.push({"key": "Armable", "value": "0"});
params.push({"key": "ackable", "value": "0"});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevDoor(data) {//TODO
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDoor", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDoor", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDoor", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
params.push({"key": "armable", "value": "0"});
params.push({"key": "Ackable", "value": "0"});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevLock(data) {
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDoor", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevDoor", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
params.push({"key": "armable", "value": "0"});
params.push({"key": "Ackable", "value": "0"});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevSmoke(data) {
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var ackable = 0;
if (data.Type == 'Security') {
ackable = 1;
}
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSmoke", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSmoke", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevSmoke", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
params.push({"key": "Armable", "value": "0"});
params.push({"key": "ackable", "value": ackable.toString()});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevFlood(data) {
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var ackable = 0;
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevFlood", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevFlood", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevFlood", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
params.push({"key": "armable", "value": "0"});
params.push({"key": "Ackable", "value": ackable.toString()});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevCO2(data) {
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var ackable = 0;
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
params.push({"key": "armable", "value": "0"});
params.push({"key": "Ackable", "value": ackable.toString()});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevCO2Alert(data) {
var dt = moment(data.LastUpdate, 'YYYY-MM-DD HH:mm:ss').valueOf();
var ackable = 0;
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2Alert", "room": "Switches"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2Alert", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2Alert", "room": "Switches"};
room_tab.Switches=1;
}
params = [];
var value = devSt(data);
params.push({"key": "armable", "value": "0"});
params.push({"key": "ackable", "value": ackable.toString()});
params.push({"key": "Armed", "value": "1"});
params.push({"key": "Tripped", "value": value.toString()});
params.push({"key": "lasttrip", "value": dt.toString()});
myfeed.params = params;
return (myfeed);
}
function DevGenericSensor(data) {
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": "Utility"};
room_tab.Utility=1;
}
if (data.Status) {
params = [];
params.push({"key": "Value", "value": data.Status.toString()});
myfeed.params = params;
} else if (data.Data) {
params = [];
//console.log(data;)
params.push({"key": "Value", "value": data.Data.toString()});
myfeed.params = params;
}
return (myfeed);
}
function DevGenericSensorT(data) {
var ptrn = /([0-9]+(?:\.[0-9]+)?) ?(.+)/;
var res = data.Data.match(ptrn).slice(1);
var value = res[0];
var suffix = res[1];
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": "Utility"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": "Utility"};
room_tab.Utility=1;
}
params = [];
params.push({"key": "Value", "value": value.toString(), "unit": suffix.toString(), "graphable": "true"});
myfeed.params = params;
return (myfeed);
}
function DevElectricity(data) {
room_tab.Utility = 1;
var ptrn1 = /(\d+) Watt/;
var ptrn2 = /([0-9]+(?:\.[0-9]+)?) Watt/;
var ptrn3 = /[\s,]+/;
var ptrn4 = /([0-9]+(?:\.[0-9]+)?) kWh/;
var myfeed;
var params = [];
var combo = [];
if (data.UsageDeliv) {
//Energy pannel
//develectricity Usage/CounterToday
var myfeed1 = {"id": data.idx + "_L1", "name": data.Name, "type": "DevElectricity", "room": "Utility"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed1 = {"id": data.idx + "_L1", "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed1 = {"id": data.idx + "_L1", "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params = []
var res = ptrn2.exec(data.Usage);
var usage = 0;
if (res != null) {
usage = Math.ceil(Number(res[1]));
}
var res = ptrn4.exec(data.CounterToday);
var usageToday = 0;
if (res != null) {
usageToday = Math.ceil(Number(res[1]));
}
params.push({"key": "Watts", "value": usage, "unit": "W"});
params.push({"key": "ConsoTotal", "value": Math.ceil(usageToday), "unit": "kWh", "graphable": "true"});
myfeed1.params = params;
combo.push(myfeed1);
//develectricity UsageDeliv/CounterDelivToday
var params = [];
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed2 = {"id": data.idx + "_L2", "name": data.Name + "Deliv", "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed2 = {"id": data.idx + "_L2", "name": data.Name + "Deliv", "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var res = ptrn2.exec(data.UsageDeliv);
var usagedeliv = 0;
if (res != null) {
usagedeliv = Math.ceil(Number(res[1]));
}
var res = ptrn4.exec(data.CounterDelivToday);
var usageDelivToday = 0;
if (res != null) {
usageDelivToday = Math.ceil(Number(res[1]));
}
params.push({"key": "Watts", "value": usagedeliv, "unit": "W"});
params.push({"key": "ConsoTotal", "value": Math.ceil(usageDelivToday), "unit": "kWh", "graphable": "true"});
myfeed2.params = params;
combo.push(myfeed2);
//devgeneric for Counter/CounterDeliv
var params = [];
var myfeed3 = {
"id": data.idx + "_L3",
"name": data.Name + " CounterToday",
"type": "DevGenericSensor",
"room": "Utility"
};
CounterToday = Math.ceil(data.Counter);
params.push({"key": "Value", "value": CounterToday, "unit": "kWh", "graphable": "true"});
myfeed3.params = params;
combo.push(myfeed3);
var params = [];
var myfeed4 = {
"id": data.idx + "_L4",
"name": data.Name + " CounterDelivToday",
"type": "DevGenericSensor",
"room": "Utility"
};
var res = ptrn4.exec(data.CounterDelivToday);
var CounterDelivToday = 0;
CounterDelivToday = Math.ceil(data.CounterDeliv);
params.push({"key": "Value", "value": CounterDelivToday, "unit": "kWh", "graphable": "false"});
myfeed4.params = params;
combo.push(myfeed4);
return (combo);
} else {
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
if (data.Usage) {
var res = ptrn2.exec(data.Usage);
var usage = 0;
if (res != null) {
usage = res[1]
}
if (!usage) {
usage = 0;
}
params.push({"key": "Watts", "value": usage, "unit": "W"});
if (data.Data) {
var res = ptrn2.exec(data.Data);
var total = 0;
if (res != null) {
total = Math.ceil(Number(res[1]));
}
params.push({"key": "ConsoTotal", "value": total.toString(), "unit": "kWh", "graphable": "true"});
}
} else {
var res = ptrn2.exec(data.Data);
var total = 0;
if (res != null) {
total = Math.ceil(Number(res[1]));
}
params.push({"key": "Watts", "value": total.toString(), "unit": "W", "graphable": "true"});
}
myfeed.params = params;
return (myfeed);
}
}
function DevElectricityMultiple(data) {
var ptrn1 = /(\d+) Watt/;
var ptrn2 = /([0-9]+(?:\.[0-9]+)?)/;
var ptrn3 = /[\s,]+/;
var combo = [];
var res = data.Data.split(ptrn3);
var usage = 0;
if (res != null) {
//L1
usage = res[0];
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed1 = {"id": data.idx+ "_L1", "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed1 = {"id": data.idx+ "_L1", "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params1 = [];
params1.push({"key": "Watts", "value": usage.toString(), "unit": "W","graphable": "true"});
myfeed1.params = params1;
combo.push(myfeed1);
//L2
usage = res[2];
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed2 = {"id": data.idx+ "_L2", "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed2 = {"id": data.idx+ "_L2", "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params2 = [];
params2.push({"key": "Watts", "value": usage.toString(),"unit": "W","graphable": "true"});
myfeed2.params = params2;
combo.push(myfeed2);
//L3
usage = res[4];
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed3 = {"id": data.idx+ "_L3", "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed3 = {"id": data.idx+ "_L3", "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params3 = [];
params3.push({"key": "Watts", "value": usage.toString(),"unit": "W", "graphable": "true"});
myfeed3.params = params3;
combo.push(myfeed3);
}
return (combo);
}
function DevCounterIncremental(data) {
var ptrn1 = /(\d+) Watt/;
var ptrn2 = /([0-9]+(?:\.[0-9]+)?) /;
var ptrn3 = /[\s,]+/;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params = [];
var unit;
switch (data.SwitchTypeVal) {
case '0':
//energy
unit = 'kWh';
break;
case '1':
//gas
unit = 'm3';
break;
case '2':
//water
unit = 'm3';
break;
case '3':
//counter free
unit = data.ValueUnits.toString();
break;
case '4':
//energy generated
unit = 'kWh';
break;
default:
break;
}
if (data.Counter) {
var res = ptrn2.exec(data.CounterToday);
var usage = 0;
if (res != null) {
usage = Math.ceil(Number(res[1]));
}
if (!usage) {
usage = 0;
}
res = Math.ceil(usage);
//console.log("T1 "+data.CounterToday);
params.push({"key": "Watts", "value": usage, "unit": unit});
if (data.Counter) {
var res = ptrn2.exec(data.Counter);
//console.log(res[1]);
var total = 0;
if (res != null) {
total = Math.ceil(Number(res[1]));
}
//console.log("T2"+total);
params.push({"key": "ConsoTotal", "value": total.toString(), "unit": unit, "graphable": "true"});
}
} else {
var res = ptrn2.exec(data.Data);
var total = 0;
if (res != null) {
total = Math.ceil(Number(res[1]));
}
//console.log(total);
params.push({"key": "Watts", "value": total.toString(), "unit": unit, "graphable": "true"});
}
myfeed.params = params;
return (myfeed);
}
function DevGas(data) {
var ptrn1 = /([0-9]+(?:\.[0-9]+)?) m3/;
var ptrn2 = /([0-9]+(?:\.[0-9]+)?)/;
var ptrn3 = /[\s,]+/;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params = [];
if (data.CounterToday) {
var res = ptrn1.exec(data.CounterToday);
var usage = 0;
if (res != null) {
usage = res[1]
}
if (!usage) {
usage = 0;
}
params.push({"key": "Watts", "value": usage.toString(), "unit": "m3"});
}
if (data.Data) {
var res = ptrn2.exec(data.Counter);
var total = 0;
if (res != null) {
total = Math.ceil(res[1]);
}
params.push({"key": "ConsoTotal", "value": total.toString(), "unit": "m3"});
}
myfeed.params = params;
return (myfeed);
}
function DevWater(data) {
var ptrn1 = /(\d+) Liter/;
var ptrn2 = /([0-9]+(?:\.[0-9]+)?) Liter/;
var ptrn2b = /([0-9]+(?:\.[0-9]+)?) m3/;
var ptrn3 = /[\s,]+/;
var combo = [];
var usage_l = 0;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevElectricity", "room": "Utility"};
room_tab.Utility=1;
}
var params = [];
if (data.CounterToday) {
var res = ptrn2.exec(data.CounterToday);
var usage = 0;
if (res != null) {
usage = Number(res[1]);
usage_l = Number(res[1]);
}
if (!usage) {
usage = 0;
}
params.push({"key": "Watts", "value": usage.toString(), "unit": "l", "graphable": "false"});
}
if (data.Counter) {
var res = ptrn2b.exec(data.Counter);
var total = 0;
if (res != null) {
total = Number(res[1]);
}
params.push({"key": "ConsoTotal", "value": total.toString(), "unit": "m3", "graphable": "true"});
}
//console.log(myfeed);
myfeed.params = params;
//combo.push(myfeed);
/*var myfeed = {"id": data.idx+"_1", "name": data.Name, "type": "DevGenericSensor", "room": "Utility"};
params=[];
params.push({"key": "Value", "value": usage_l, "unit": "L", "graphable": "true"});
myfeed.params=params;
combo.push(myfeed);*/
return (myfeed);
}
function DevFlow(data) {
var ptrn1 = /(\d+) Liter/;
var ptrn2 = /([0-9]+(?:\.[0-9]+)?) Liter/;
var ptrn2b = /([0-9]+(?:\.[0-9]+)?) m3/;
var ptrn3 = /[\s,]+/;
var ptrn4 = /([0-9]+(?:\.[0-9]+)?) l\/min/;
var combo = [];
var usage_l = 0;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevGenericSensor", "room": "Utility"};
room_tab.Utility=1;
}
var params = [];
var res = ptrn4.exec(data.Data);
//console.log(res[1]);
var total = 0;
if (res != null) {
total = Number(res[1]);
}
params.push({"key": "Value", "value": total.toString(), "unit": "l/s", "graphable": true});
myfeed.params = params;
return (myfeed);
}
function DevTH(data) {
var status = 0;
switch (data.Type) {
case 'Temp':
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevTemperature", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevTemperature", "room": "Temp"};
room_tab.Temp=1;
}
params = [];
params.push({"key": "Value", "value": data.Temp, "unit": "°C","graphable": "true"});
myfeed.params = params;
return (myfeed);
case 'Humidity':
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevHygrometry", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevHygrometry", "room": "Temp"};
room_tab.Temp=1;
}
params = [];
params.push({"key": "Value", "value": data.Humidity, "unit": "%", "graphable": "true"});
myfeed.params = params;
return (myfeed);
case 'Temp + Humidity':
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevTempHygro", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevTempHygro", "room": "Temp"};
room_tab.Temp=1;
}
var params = [];
params.push({"key": "Hygro", "value": data.Humidity, "unit": "%", "graphable": "true"});
params.push({"key": "Temp", "value": data.Temp, "unit": "°C", "graphable": "true"});
myfeed.params = params;
return (myfeed);
case 'Temp + Humidity + Baro':
var combo = [];
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevTempHygro", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevTempHygro", "room": "Temp"};
room_tab.Temp=1;
}
var params = [];
params.push({"key": "Hygro", "value": data.Humidity, "unit": "%", "graphable": "true"});
params.push({"key": "Temp", "value": data.Temp, "unit": "°C", "graphable": "true"});
myfeed.params = params;
combo.push(myfeed);
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx+ "_1", "name": data.Name, "type": "DevPressure", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx+ "_1", "name": data.Name, "type": "DevPressure", "room": "Weather"};
room_tab.Weather=1;
}
params = [];
params.push({"key": "Value", "value": data.Barometer, "unit": "mbar", "graphable": "true"});
myfeed.params = params;
combo.push(myfeed);
return (combo);
return (combo);
default:
logger.info("General: should not happen");
break;
}
}
function DevPressure(data) {
room_tab.Weather = 1;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevPressure", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevPressure", "room": "Weather"};
room_tab.Weather=1;
}
params = [];
if (data.SubType === "Pressure") {
if (data.Pressure < 800) {
var mb = data.Pressure * 1000;
params.push({"key": "Value", "value": mb, "unit": "mbar", "graphable": "true"});
} else {
params.push({"key": "Value", "value": data.Pressure, "unit": "bar", "graphable": "true"});
}
} else {
if (data.Barometer < 800) {
var mb = data.Barometer * 1000;
params.push({"key": "Value", "value": mb, "unit": "mbar", "graphable": "true"});
} else {
params.push({"key": "Value", "value": data.Barometer, "unit": "bar", "graphable": "true"});
}
}
myfeed.params = params;
return (myfeed);
}
function DevRain(data) {
var status = 0;
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevRain", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevRain", "room": "Weather"};
room_tab.Weather=1;
}
var params = [];
params.push({"key": "Accumulation", "value": data.Rain.toString(), "unit": "mm", "graphable": "true"});
params.push({"key": "Value", "value": data.RainRate.toString(), "unit": "mm/h", "graphable": "true"});
myfeed.params = params;
return (myfeed);
}
function DevUV(data) {
var status = 0;
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevUV", "room": "Weather"};
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevUV", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevUV", "room": "Weather"};
room_tab.Weather=1;
}
params = [];
params.push({"key": "Value", "value": data.UVI, "unit": "", "graphable": "true"});
myfeed.params = params;
return (myfeed);
}
function DevNoise(data) {
var ptrn = /([0-9]+(?:\.[0-9]+)?) ?(.+)/;
var res = data.Data.match(ptrn).slice(1);
var value = res[0];
var suffix = res[1];
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevNoise", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevNoise", "room": "Utility"};
room_tab.Utility=1;
}
params = [];
params.push({"key": "Value", "value": value, "unit": suffix.toString(), "graphable": "true"});
myfeed.params = params;
return (myfeed);
}
function DevLux(data) {
var ptrn1 = /(\d+) Lux/;
var res = ptrn1.exec(data.Data);
var usage = 0;
if (res != null) {
usage = res[1]
}
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevLuminosity", "room": domo_room_tab[data.PlanIDs[0]], params: []};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevLuminosity", "room": "Weather", params: []};
room_tab.Weather=1;
}
params = [];
params.push({"key": "Value", "value": usage, "unit": "lux", "graphable": "true"});
myfeed.params = params;
return (myfeed);
}
function DevGases(data) {
var ptrn1 = /(\d+) ppm/;
var res = ptrn1.exec(data.Data);
var usage = 0;
if (res != null) {
usage = Number(res[1]);
}
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2", "room": domo_room_tab[data.PlanIDs[0]], params: []};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevCO2", "room": "Temp", params: []};
room_tab.Temp=1;
}
params = [];
params.push({"key": "Value", value: usage.toString(), "unit": "ppm", "graphable": "true"});
myfeed.params = params;
return (myfeed);
}
function DevWind(data) {
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevWind", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevWind", "room": "Weather"};
room_tab.Weather=1;
}
var params = [];
params.push({"key": "Speed", "value": data.Speed, "unit": "km/h", "graphable": "true"});
if (typeof data.Direction !== 'undefined' && data.Direction !== null) {
params.push({"key": "Direction", "value": data.Direction.toString(), "unit": "°", "graphable": "true"});
}
myfeed.params = params;
return (myfeed);
}
function DevThermostat(data) {
if (typeof data.PlanIDs !== 'undefined' && data.PlanIDs[0] !== null && data.PlanIDs[0] > 0) {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevThermostat", "room": domo_room_tab[data.PlanIDs[0]]};
} else {
var myfeed = {"id": data.idx, "name": data.Name, "type": "DevThermostat", "room": "Switches"};
room_tab.Utility=1;
}
var params = [];
params.push({"key": "cursetpoint", "value": data.SetPoint.toString()});
params.push({"key": "curtemp", "value": data.SetPoint.toString()});
params.push({"key": "step", "value": "0.5"});
params.push({"key": "curmode", "value": "default"});
params.push({"key": "availablemodes", "value": "default"});
myfeed.params = params;
return (myfeed);
}
function DevScene(data) {
var dt = moment(data.Las