mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
60_Watches: contrib 0.21.0
git-svn-id: https://svn.fhem.de/fhem/trunk@21897 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2e74c55f32
commit
17a910edae
@ -71,7 +71,8 @@ BEGIN {
|
||||
|
||||
# Versions History intern
|
||||
my %vNotesIntern = (
|
||||
"0.20.1" => "08.05.2020 asynchron read digital text and much more fixes ",
|
||||
"0.21.0" => "08.05.2020 support of alarm time of model digital 'watch' ",
|
||||
"0.20.1" => "08.05.2020 asynchron read digital text and much more fixes, set client as default timeSource ",
|
||||
"0.20.0" => "07.05.2020 asynchron read alarmTime reading, some fixes ",
|
||||
"0.19.0" => "06.05.2020 alarm event creation for watch models 'Station' and 'Station' ",
|
||||
"0.18.0" => "06.05.2020 attr 'digitalTextTicker' deleted and switched to setter 'textTicker', default text switched to blank ",
|
||||
@ -136,7 +137,7 @@ sub Initialize {
|
||||
"stationHourHand:Bar,Pointed,Swiss,Vienna ".
|
||||
"stationStrokeDial:GermanHour,German,Austria,Swiss,Vienna,No ".
|
||||
"stationBody:Round,SmallWhite,RoundGreen,Square,Vienna,No ".
|
||||
"timeSource:client,server ".
|
||||
"timeSource:server,client ".
|
||||
"";
|
||||
|
||||
$hash->{FW_hideDisplayName} = 1; # Forum 88667
|
||||
@ -424,7 +425,7 @@ sub digitalWatch {
|
||||
my $adsd = AttrVal($d, "digitalSegmentDistance", 0.5);
|
||||
my $adda = AttrVal($d, "digitalDigitAngle", 9);
|
||||
my $adtdn = AttrVal($d, "digitalTextDigitNumber", 0);
|
||||
my $tsou = AttrVal($d, "timeSource", "server");
|
||||
my $tsou = AttrVal($d, "timeSource", "client");
|
||||
|
||||
my $deftxt = " ";
|
||||
my $rdtt = ReadingsVal ($d, "displayTextTicker", "off");
|
||||
@ -1086,18 +1087,18 @@ sub digitalWatch {
|
||||
}
|
||||
|
||||
// localStorage speichern letzte Alarmzeit
|
||||
function localStoreSetLastalm_$d (lastalmtime) {
|
||||
localStorage.setItem('lastalmtime_$d', lastalmtime);
|
||||
function localStoreSetLastalm_$d (dev, lastalmtime) {
|
||||
localStorage.setItem('lastalmtime_'+dev, lastalmtime);
|
||||
}
|
||||
|
||||
// Check ob Alarm ausgelöst werden soll und ggf. Alarmevent triggern
|
||||
function checkAndDoAlm_$d (acttime, almtime) {
|
||||
lastalmtime = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
|
||||
if ( (acttime == almtime || acttime == '$alarmdef') && acttime != lastalmtime ) {
|
||||
function checkAndDoAlm_$d (dev, acttime, almtime) {
|
||||
lastalmtime_$d = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
|
||||
if ( (acttime == almtime || acttime == '$alarmdef') && acttime != lastalmtime_$d ) {
|
||||
command = '{ CommandSetReading(undef, \"$d alarmed '+acttime+'\") }';
|
||||
url_$d = makeCommand(command);
|
||||
|
||||
localStoreSetLastalm_$d (acttime); // aktuelle Alarmzeit sichern
|
||||
localStoreSetLastalm_$d (dev, acttime); // aktuelle Alarmzeit sichern
|
||||
|
||||
if(acttime == almtime) {
|
||||
\$.get(url_$d);
|
||||
@ -1122,6 +1123,17 @@ sub digitalWatch {
|
||||
modulo_$d = cycleseconds % 2; // Taktung für Readingabruf (Serverauslastung reduzieren)
|
||||
|
||||
if (watchkind_$d == 'watch') {
|
||||
if (modulo_$d != zmodulo_$d) {
|
||||
command = '{ReadingsVal(\"$d\",\"alarmTime\",\"+almtime0_$d+\")}'; // alarmTime Reading lesen
|
||||
url_$d = makeCommand(command);
|
||||
\$.get( url_$d, function (data) {
|
||||
almtime0_$d = data.replace(/\\n/g, '');
|
||||
zmodulo_$d = modulo_$d;
|
||||
return (almtime0_$d, zmodulo_$d);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Zeitsteuerung - aktueller Timestamp in Millisekunden
|
||||
if ('$tsou' == 'server') { // Serverzeit
|
||||
command = '{ int(time*1000) }';
|
||||
@ -1148,6 +1160,16 @@ sub digitalWatch {
|
||||
var hours_$d = time_$d.getHours();
|
||||
var minutes_$d = time_$d.getMinutes();
|
||||
var seconds_$d = time_$d.getSeconds();
|
||||
|
||||
acttime_$d = ((hours_$d < 10) ? '0' : '') + hours_$d + ':' +
|
||||
((minutes_$d < 10) ? '0' : '') + minutes_$d + ':' +
|
||||
((seconds_$d < 10) ? '0' : '') + seconds_$d;
|
||||
|
||||
if (acttime_$d == '00:00:00') {
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen zum Tageswechsel
|
||||
}
|
||||
|
||||
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
|
||||
}
|
||||
|
||||
if (watchkind_$d == 'staticwatch') {
|
||||
@ -1166,19 +1188,18 @@ sub digitalWatch {
|
||||
);
|
||||
|
||||
if (state_$d == 'started' || state_$d == 'resumed') {
|
||||
if (state_$d == 'started') {
|
||||
localStoreSetLastalm_$d ('NaN'); // letzte Alarmzeit zurücksetzen
|
||||
}
|
||||
|
||||
if (modulo_$d != zmodulo_$d) {
|
||||
command = '{ReadingsVal(\"$d\",\"alarmTime\",\"+almtime0_$d+\")}'; // alarmTime Reading lesen
|
||||
url_$d = makeCommand(command);
|
||||
\$.get( url_$d, function (data) {
|
||||
almtime0_$d = data.replace(/\\n/g, '');
|
||||
return almtime0_$d;
|
||||
zmodulo_$d = modulo_$d;
|
||||
return (almtime0_$d, zmodulo_$d);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// == Startzeit ==
|
||||
// == Startzeit für CountDown ==
|
||||
command = '{ReadingsNum(\"$d\",\"starttime\", 0)}';
|
||||
url_$d = makeCommand(command);
|
||||
\$.get( url_$d, function (data) {
|
||||
@ -1201,12 +1222,16 @@ sub digitalWatch {
|
||||
elapsesec_$d = parseInt(elapsesec_$d);
|
||||
}
|
||||
|
||||
if (state_$d == 'started' && elapsesec_$d <= 5) {
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen bis 2 s nach Start
|
||||
}
|
||||
|
||||
hours_$d = parseInt(elapsesec_$d / 3600);
|
||||
elapsesec_$d -= hours_$d * 3600;
|
||||
minutes_$d = parseInt(elapsesec_$d / 60);
|
||||
seconds_$d = parseInt(elapsesec_$d - minutes_$d * 60);
|
||||
|
||||
checkAndDoAlm_$d ($ddt, almtime0_$d); // Alarm auslösen wenn zutreffend
|
||||
checkAndDoAlm_$d ('$d', $ddt, almtime0_$d); // Alarm auslösen wenn zutreffend
|
||||
|
||||
localStoreSet_$d (hours_$d, minutes_$d, seconds_$d, NaN);
|
||||
}
|
||||
@ -1226,7 +1251,7 @@ sub digitalWatch {
|
||||
seconds_$d = 0;
|
||||
|
||||
localStoreSet_$d (hours_$d, minutes_$d, seconds_$d);
|
||||
localStoreSetLastalm_$d ('NaN'); // letzte Alarmzeit zurücksetzen
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen
|
||||
}
|
||||
}
|
||||
|
||||
@ -1240,10 +1265,6 @@ sub digitalWatch {
|
||||
);
|
||||
|
||||
if (state_$d == 'started' || state_$d == 'resumed') {
|
||||
if (state_$d == 'started') {
|
||||
localStoreSetLastalm_$d ('NaN'); // letzte Alarmzeit zurücksetzen
|
||||
}
|
||||
|
||||
if (modulo_$d != zmodulo_$d) {
|
||||
command = '{ReadingsVal(\"$d\",\"alarmTime\",\"+almtime0_$d+\")}'; // alarmTime Reading lesen
|
||||
url_$d = makeCommand(command);
|
||||
@ -1298,11 +1319,12 @@ sub digitalWatch {
|
||||
currDate_$d = new Date(ct_$d);
|
||||
elapsesec_$d = (currDate_$d.getTime() - startDate_$d.getTime())/1000; // vergangene Millisekunden in Sekunden umrechnen
|
||||
|
||||
if (state_$d == 'started' && elapsesec_$d <= 5) {
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen bis 2 s nach Start
|
||||
}
|
||||
|
||||
// == Countdown errechnen ==
|
||||
countcurr_$d = parseInt(countInitVal_$d) - parseInt(elapsesec_$d);
|
||||
//if (countcurr_$d < 0) { // Fehlerkorrektur bei resumed
|
||||
// countcurr_$d = 1;
|
||||
//}
|
||||
//log(\"countcurr_$d: \"+countcurr_$d);
|
||||
|
||||
hours_$d = parseInt(countcurr_$d / 3600);
|
||||
@ -1311,7 +1333,7 @@ sub digitalWatch {
|
||||
seconds_$d = parseInt(countcurr_$d - minutes_$d * 60);
|
||||
|
||||
if (countcurr_$d >= 0) {
|
||||
checkAndDoAlm_$d ($ddt, almtime0_$d); // Alarm auslösen wenn zutreffend
|
||||
checkAndDoAlm_$d ('$d', $ddt, almtime0_$d); // Alarm auslösen wenn zutreffend
|
||||
localStoreSet_$d (hours_$d, minutes_$d, seconds_$d, NaN);
|
||||
}
|
||||
}
|
||||
@ -1331,17 +1353,12 @@ sub digitalWatch {
|
||||
seconds_$d = 0;
|
||||
|
||||
localStoreSet_$d (hours_$d, minutes_$d, seconds_$d);
|
||||
localStoreSetLastalm_$d ('NaN'); // letzte Alarmzeit zurücksetzen
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen
|
||||
}
|
||||
}
|
||||
|
||||
if (watchkind_$d == 'text') {
|
||||
tlength_$d = digitxt_$d.length-1; // Länge des Textes abzgl. 1 für ' '
|
||||
if($adtdn) {
|
||||
tlength_$d = $adtdn;
|
||||
}
|
||||
|
||||
display_$d.pattern = ''; // Textschablone erstellen
|
||||
display_$d.pattern = ''; // Template erstellen
|
||||
for (var i = 0; i <= tlength_$d; i++) {
|
||||
display_$d.pattern += '#';
|
||||
}
|
||||
@ -1354,9 +1371,9 @@ sub digitalWatch {
|
||||
var rtmillis = rttime.getMilliseconds();
|
||||
|
||||
if (tticker_$d == 'on') { // Text als Laufband ?
|
||||
var text = '$forerun'+digitxt_$d+' ';
|
||||
var index = ( 2 * (rtseconds + 60*rtminutes + 24*60*rthours) + Math.floor(rtmillis / 500) ) % (text.length - 6);
|
||||
value_$d = text.substr(index, tlength_$d+parseInt(1));
|
||||
var text_$d = '$forerun'+digitxt_$d+' ';
|
||||
var index_$d = ( 2 * (rtseconds + 60*rtminutes + 24*60*rthours) + Math.floor(rtmillis / 500) ) % (text_$d.length - 6);
|
||||
value_$d = text_$d.substr(index_$d, tlength_$d+parseInt(1));
|
||||
|
||||
} else {
|
||||
value_$d = digitxt_$d;
|
||||
@ -1368,7 +1385,11 @@ sub digitalWatch {
|
||||
\$.get( url_$d, function (data) {
|
||||
digitxt_$d = data.replace(/\\n/g, '');
|
||||
digitxt_$d = ' '+digitxt_$d;
|
||||
return digitxt_$d;
|
||||
tlength_$d = digitxt_$d.length-1; // Länge des Textes abzgl. 1 für ' '
|
||||
if($adtdn > 0) {
|
||||
tlength_$d = $adtdn;
|
||||
}
|
||||
return (digitxt_$d, tlength_$d);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -1419,7 +1440,7 @@ sub stationWatch {
|
||||
my $ssd = AttrVal ($d, "stationStrokeDial", "Swiss"). "StrokeDial";
|
||||
my $sbody = AttrVal ($d, "stationBody", "Round"). "Body";
|
||||
my $hattr = AttrVal ($d, "htmlattr", "width='150' height='150'");
|
||||
my $tsou = AttrVal($d,"timeSource","server");
|
||||
my $tsou = AttrVal ($d, "timeSource", "client");
|
||||
|
||||
my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc");
|
||||
|
||||
@ -1509,20 +1530,30 @@ sub stationWatch {
|
||||
}
|
||||
|
||||
// localStorage speichern letzte Alarmzeit
|
||||
function localStoreSetLastalm_$d (lastalmtime) {
|
||||
localStorage.setItem('lastalmtime_$d', lastalmtime);
|
||||
function localStoreSetLastalm_$d (dev, lastalmtime) {
|
||||
localStorage.setItem('lastalmtime_'+dev, lastalmtime);
|
||||
}
|
||||
|
||||
// Check ob Alarm ausgelöst werden soll und ggf. Alarmevent triggern
|
||||
function checkAndDoAlm_$d (acttime, almtime) {
|
||||
lastalmtime = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
|
||||
if ( (acttime == almtime) && acttime != lastalmtime ) {
|
||||
function checkAndDoAlm_$d (dev, acttime, almtime) {
|
||||
lastalmtime_$d = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
|
||||
if ( acttime == almtime && acttime != lastalmtime_$d ) {
|
||||
command = '{ CommandSetReading(undef, \"$d alarmed '+acttime+'\") }';
|
||||
url_$d = makeCommand(command);
|
||||
|
||||
localStoreSetLastalm_$d (acttime); // aktuelle Alarmzeit sichern
|
||||
localStoreSetLastalm_$d (dev, acttime); // aktuelle Alarmzeit sichern
|
||||
|
||||
if(acttime == almtime) {
|
||||
\$.get(url_$d);
|
||||
|
||||
} else {
|
||||
\$.get(url_$d, function (data) {
|
||||
command = '{ CommandSetReading(undef, \"$d state stopped\") }';
|
||||
url_$d = makeCommand(command);
|
||||
\$.get(url_$d);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1743,7 +1774,11 @@ sub stationWatch {
|
||||
((minutes_$d < 10) ? '0' : '') + minutes_$d + ':' +
|
||||
((seconds_$d < 10) ? '0' : '') + seconds_$d;
|
||||
|
||||
checkAndDoAlm_$d (acttime_$d, almtime0_$d);
|
||||
if (acttime_$d == '00:00:00') {
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen zum Tageswechsel
|
||||
}
|
||||
|
||||
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
|
||||
|
||||
// draw hour hand
|
||||
context.save();
|
||||
@ -2014,7 +2049,7 @@ sub modernWatch {
|
||||
my $fr = AttrVal($d, "modernColorRing", "FFFFFF");
|
||||
my $fre = AttrVal($d, "modernColorRingEdge", "333");
|
||||
my $hattr = AttrVal($d, "htmlattr", "width='150' height='150'");
|
||||
my $tsou = AttrVal($d, "timeSource", "server");
|
||||
my $tsou = AttrVal($d, "timeSource", "client");
|
||||
|
||||
my $alarm = ReadingsVal($d, "alarmTime", "aa:bb:cc");
|
||||
|
||||
@ -2052,20 +2087,30 @@ sub modernWatch {
|
||||
}
|
||||
|
||||
// localStorage speichern letzte Alarmzeit
|
||||
function localStoreSetLastalm_$d (lastalmtime) {
|
||||
localStorage.setItem('lastalmtime_$d', lastalmtime);
|
||||
function localStoreSetLastalm_$d (dev, lastalmtime) {
|
||||
localStorage.setItem('lastalmtime_'+dev, lastalmtime);
|
||||
}
|
||||
|
||||
// Check ob Alarm ausgelöst werden soll und ggf. Alarmevent triggern
|
||||
function checkAndDoAlm_$d (acttime, almtime) {
|
||||
lastalmtime = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
|
||||
if ( (acttime == almtime) && acttime != lastalmtime ) {
|
||||
function checkAndDoAlm_$d (dev, acttime, almtime) {
|
||||
lastalmtime_$d = localStorage.getItem('lastalmtime_$d'); // letzte Alarmzeit laden
|
||||
if ( acttime == almtime && acttime != lastalmtime_$d ) {
|
||||
command = '{ CommandSetReading(undef, \"$d alarmed '+acttime+'\") }';
|
||||
url_$d = makeCommand(command);
|
||||
|
||||
localStoreSetLastalm_$d (acttime); // aktuelle Alarmzeit sichern
|
||||
localStoreSetLastalm_$d (dev, acttime); // aktuelle Alarmzeit sichern
|
||||
|
||||
if(acttime == almtime) {
|
||||
\$.get(url_$d);
|
||||
|
||||
} else {
|
||||
\$.get(url_$d, function (data) {
|
||||
command = '{ CommandSetReading(undef, \"$d state stopped\") }';
|
||||
url_$d = makeCommand(command);
|
||||
\$.get(url_$d);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2169,7 +2214,11 @@ sub modernWatch {
|
||||
((minute_$d < 10) ? '0' : '') + minute_$d + ':' +
|
||||
((second_$d < 10) ? '0' : '') + second_$d;
|
||||
|
||||
checkAndDoAlm_$d (acttime_$d, almtime0_$d);
|
||||
if (acttime_$d == '00:00:00') {
|
||||
localStoreSetLastalm_$d ('$d', 'NaN'); // letzte Alarmzeit zurücksetzen zum Tageswechsel
|
||||
}
|
||||
|
||||
checkAndDoAlm_$d ('$d', acttime_$d, almtime0_$d);
|
||||
|
||||
//hour_$d
|
||||
hour_$d = hour_$d%12;
|
||||
@ -2452,7 +2501,7 @@ Als Zeitquelle können sowohl der Client (Browserzeit) als auch der FHEM-Server
|
||||
<li><b>timeSource</b><br>
|
||||
Wählt die Zeitquelle aus. Es kann die lokale Clientzeit (Browser) oder die Zeit des FHEM-Servers angezeigt werden. <br>
|
||||
Diese Einstellung ist bei (CountDown-)Stoppuhren nicht relevant. <br>
|
||||
(default: server)
|
||||
(default: client)
|
||||
</li>
|
||||
<br>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user