NEWS
Определяем местонахождение хозяев
-
Как вариант накидал скриптик, пишет в переменную два последних посещенных помещения квартиры.
Первая версия
! ````
createState('Location', '');
var listStateMotion = $('mqtt.0.myhome..Motion');
var arrlocation = [];
listStateMotion.on(function(obj) {
if(obj.oldState.val === '1' || obj.oldState.val == 1){
if (obj.name == 'myhome/Bedroom/Motion'){Location('bedroom');}
if (obj.name == 'myhome/Kitchen/Motion'){Location('kitchen');}
if (obj.name == 'myhome/Guestroom/Motion'){Location('guestroom');}
}
});
! on('mqtt.0.myhome.Lighting.BathRoom_Main', function (obj) {
if (obj.newState.val == '1' || obj.newState.val == 1){Location('bathroom');}
});
! function Location(onelocation){
log(onelocation);
arrlocation = (getState('javascript.0.Location').val).split(/\s,\s*/);
if (onelocation != arrlocation[1]/** && onelocation != arrlocation[1]*/){
arrlocation[0] = arrlocation[1];
arrlocation[1] = onelocation;
}
setState ('javascript.0.Location', arrlocation[0]+','+arrlocation[1]);
}Переписал скрипт. Вторая версия скрипта: >! ```` createState('Location', ''); var listStateMotion = $('mqtt.0.myhome.*.Motion'); var flag = 0; >! var arrlocation = { "bedroom": 0, "kitchen": 0, "guestroom": 0, "hall": 0, "bathroom": 0 }; >! listStateMotion.on(function(obj) { if(obj.newState.val === '1' || obj.newState.val === 1){ if (obj.name === 'myhome/Bedroom/Motion'){ arrlocation.bedroom = obj.newState.ts; } else if (obj.name === 'myhome/Kitchen/Motion'){ arrlocation.kitchen = obj.newState.ts; } else if (obj.name === 'myhome/Guestroom/Motion'){ arrlocation.guestroom = obj.newState.ts; } else if (obj.name === 'myhome/Hall/Motion'){ arrlocation.hall = obj.newState.ts; } Location(arrlocation); } }); >! on('mqtt.0.myhome.Lighting.BathRoom_Main', function (obj) { if (obj.newState.val === '1' || obj.newState.val === 1){ arrlocation.bathroom = obj.newState.ts; } Location(arrlocation); }); >! var OldName; function Location(arrlocation){ //log(onelocation); var BathRoomLight = getState('mqtt.0.myhome.Lighting.BathRoom_Main').val; var Sleep = getState('javascript.0.Scenes.Sleep').val; var date = new Date(); var day = date.getDay(); // 0-воскр. 6-суббота var hour = date.getHours(); var min = (date.getMinutes()<10?'0':'') + date.getMinutes(); >! var max = 0; var maxName = ""; for (var name in arrlocation) { if (max < arrlocation[name]) { max = arrlocation[name]; maxName = name; } } log(maxName); var location = (getState('javascript.0.Location').val).split(/\s*,\s*/); if (maxName !== location[1]){ location[0] = location[1]; location[1] = maxName; flag++; setTimeout(function() {flag = 0;}, 3600000); if ((Sleep === true || Sleep === 'true') && hour > 6 && hour < 21 && flag > 8){ flag = 0; setState('javascript.0.Scenes.Sleep', 'false'); setState ('sayit.0.tts.text', 'Доброе утро!'); setTimeout(function() { setState ('sayit.0.tts.text', 'Прогноз погоды на сегодня: ' + getState("javascript.0.forecast.today").val); }, 7000); setTimeout(function() { setState ('sayit.0.tts.text', 'Сейчас за окном ' + parseFloat(getState("mqtt.0.myhome.Bedroom.Temp_in").val).toFixed(0)+'°'); }, 25000); setTimeout(function() { setState ('sayit.0.tts.text', 'Курс доллара ' + (getState("javascript.0.Valuta.USD").val.toFixed(2)).toString().replace(/[.]+/g, ',')+' руб. , '+'курс евро '+ (getState("javascript.0.Valuta.EUR").val.toFixed(2)).toString().replace(/[.]+/g, ',')+ ' руб.'); }, 35000); setTimeout(function() {setState ('javascript.0.Read_iCal', 'true');}, 120000); } } setState ('javascript.0.Location', location[0]+','+location[1]); }
-
Обновил скриптик.