This commit is contained in:
Marc Hoppe
2016-03-27 17:24:12 +02:00
parent e88e701a59
commit 8a8a64cd91

View File

@@ -10,13 +10,12 @@ sub MyUtils_Initialize($$)
} }
use constant { use constant {
STATE_IDLE => 0, STATE_IDLE => 0,
STATE_HOCH => 1, STATE_HOCH => 1,
STATE_RUNTER => 2, STATE_RUNTER => 2,
STATE_SCHLITZ => 3, STATE_SCHLITZ => 3,
}; };
my @rolls = ( my @rolls = (
{ roll => "wohn.rollTerrR", dir=>"W", typ=>"n", temp=>"tempWohn", tempS=>21, win=>"wohn.fenTerr", state=>STATE_IDLE, }, { roll => "wohn.rollTerrR", dir=>"W", typ=>"n", temp=>"tempWohn", tempS=>21, win=>"wohn.fenTerr", state=>STATE_IDLE, },
{ roll => "wohn.rollTerrL", dir=>"W", typ=>"n", temp=>"tempWohn", tempS=>21, win=>"", state=>STATE_IDLE, }, { roll => "wohn.rollTerrL", dir=>"W", typ=>"n", temp=>"tempWohn", tempS=>21, win=>"", state=>STATE_IDLE, },
@@ -29,155 +28,163 @@ my @rolls = (
{ roll => "bad.roll", dir=>"S", typ=>"n", temp=>"tempBad", tempS=>23, win=>"", state=>STATE_IDLE, }, { roll => "bad.roll", dir=>"S", typ=>"n", temp=>"tempBad", tempS=>23, win=>"", state=>STATE_IDLE, },
{ roll => "schlaf.rollWeg", dir=>"S", typ=>"s", temp=>"tempSchlaf", tempS=>18, win=>"", state=>STATE_IDLE, }, { roll => "schlaf.rollWeg", dir=>"S", typ=>"s", temp=>"tempSchlaf", tempS=>18, win=>"", state=>STATE_IDLE, },
{ roll => "schlaf.rollStr", dir=>"O", typ=>"s", temp=>"tempSchlaf", tempS=>18, win=>"wohn.fenTerr", state=>STATE_IDLE, }, { roll => "schlaf.rollStr", dir=>"O", typ=>"s", temp=>"tempSchlaf", tempS=>18, win=>"wohn.fenTerr", state=>STATE_IDLE, },
); );
#my %rollStates = (
# lastWeatherCode => 0,
# lastWaetherCodeTime => 0,
# timerNum => 0,
# );
# in dieser Reihenfolge fahren
my @rollHoch = ( my @rollHoch = (
"bad.roll", "bad.roll",
"arb.rollWeg", "arb.rollWeg",
"arb.rollTerr", "arb.rollTerr",
"kuch.rollStr", "kuch.rollStr",
"kuch.rollBar", "kuch.rollBar",
"ess.roll", "ess.roll",
"wohn.rollSofa", "wohn.rollSofa",
"wohn.rollTerrL", "wohn.rollTerrL",
"wohn.rollTerrR" "wohn.rollTerrR"
); );
my @rollRunter = ( my @rollRunter = (
"wohn.rollTerrR", "wohn.rollTerrR",
"wohn.rollTerrL", "wohn.rollTerrL",
"wohn.rollSofa", "wohn.rollSofa",
"ess.roll", "ess.roll",
"kuch.rollBar", "kuch.rollBar",
"kuch.rollStr", "kuch.rollStr",
"arb.rollTerr", "arb.rollTerr",
"arb.rollWeg", "arb.rollWeg",
"bad.roll", "bad.roll",
"schlaf.rollWeg", "schlaf.rollWeg",
"schlaf.rollStr" "schlaf.rollStr"
); );
# Bei Weckzeit auf Schlitz
my @rollWeck = ( my @rollWeck = (
"schlaf.rollWeg", "schlaf.rollWeg",
"schlaf.rollStr" "schlaf.rollStr"
); );
my @rollTest = ( my @rollTest = (
"wohn.rollTerrR" "wohn.rollTerrR"
); );
my @rollSchlaf = ( my @rollSchlaf = (
"schlaf.rollWeg", "schlaf.rollWeg",
"schlaf.rollStr" "schlaf.rollStr"
); );
my @rollArb = ( my @rollArb = (
"arb.rollTerr", "arb.rollTerr",
"arb.rollWeg", "arb.rollWeg",
); );
#------------------------------------------
my $tc=0; my $tc=0;
my @blocktime=localtime; my @blocktime=localtime;
my $blocktimerRunning=0; my $blocktimerRunning=0;
sub myfhem($) { #------------------------------------------
sub myfhemcmd($) {
#Log 1, "@_"; #Log 1, "@_";
fhem("@_"); fhem("@_");
} }
#------------------------------------------
sub RollCheckSkip($$) sub RollCheckSkip($$)
{ {
my($cmd, $roll) = @_; my($cmd, $roll) = @_;
my $skip=0; my $skip=0;
if ($cmd eq "closes") { if ($cmd eq "closes") {
if ($roll eq "wohn.rollTerrR") { if ($roll eq "wohn.rollTerrR") {
if (Value("wohn.fenTerr") eq "Open") { if (Value("wohn.fenTerr") eq "Open") {
$skip=1; $skip=1;
} }
} }
} }
return $skip return $skip
} }
#------------------------------------------
sub RollCmd($$$) sub RollCmd($$$)
{ {
my ($cmd, $roll, $delay) = @_; my ($cmd, $roll, $delay) = @_;
if(RollCheckSkip($cmd, $roll)==0) { if(RollCheckSkip($cmd, $roll)==0) {
myfhem ("define r".int(rand(10000))." at +".$delay." set ".$roll." ".$cmd); myfhemcmd ("define r".int(rand(10000))." at +".$delay." set ".$roll." ".$cmd);
} }
} }
#------------------------------------------
sub RollGroup(\@$$) sub RollGroup(\@$$)
{ {
my ($rolls, $cmd, $delay) = @_; my ($rolls, $cmd, $delay) = @_;
#Log 1, "RollGroup ## cmd:$cmd del:$delay"; #Log 1, "RollGroup ## cmd:$cmd del:$delay";
my $i; my $i;
my @myrolls; my @myrolls;
@myrolls=@$rolls; @myrolls=@$rolls;
#local $" = ', '; #local $" = ', ';
#print "@myrolls $cmd\n"; #print "@myrolls $cmd\n";
$i=0; $i=0;
for my $r (@myrolls) { for my $r (@myrolls) {
my @tparts = gmtime($i*$delay+1); my @tparts = gmtime($i*$delay+1);
my $t=sprintf ("%02d:%02d:%02d",@tparts[2,1,0]); my $t=sprintf ("%02d:%02d:%02d",@tparts[2,1,0]);
my $skip=0; my $skip=0;
#$t="00:00:".sprintf("%02d", $i*5); #$t="00:00:".sprintf("%02d", $i*5);
#Log 1, "time $t"; #Log 1, "time $t";
if ($cmd eq "closes") { if ($cmd eq "closes") {
if ($r eq "wohn.rollTerrR") { if ($r eq "wohn.rollTerrR") {
if (Value("wohn.fenTerr") eq "Open") { if (Value("wohn.fenTerr") eq "Open") {
$skip=1; $skip=1;
} }
} }
} }
if($skip==0) { if($skip==0) {
myfhem ("define r".$i." at +".$t." set ".$r." ".$cmd); myfhemcmd ("define r".$i." at +".$t." set ".$r." ".$cmd);
} }
$i=$i+1; $i=$i+1;
} }
} }
#------------------------------------------
sub RollTest() { sub RollTest() {
&RollGroup(\@rollTest, "closes", 1); &RollGroup(\@rollTest, "closes", 1);
} }
#------------------------------------------
sub RollAll($$) { sub RollAll($$) {
# Log 1, "################"; my ($cmd, $delay) = @_;
my ($cmd, $delay) = @_; if($cmd eq "closes") {
# Log 1, "c:$cmd d:$delay"; &RollGroup(\@rollRunter, $cmd,$delay);
# &RollGroup(\@rollAlle, $cmd, $delay); }
if($cmd eq "closes") { else {
&RollGroup(\@rollRunter, $cmd,$delay); &RollGroup(\@rollHoch, $cmd,$delay);
} }
else {
&RollGroup(\@rollHoch, $cmd,$delay);
}
} }
#------------------------------------------
sub RollWeck($) { sub RollWeck($) {
my ($delay) = @_; my ($delay) = @_;
&RollGroup(\@rollWeck, "up 5", $delay); &RollGroup(\@rollWeck, "up 5", $delay);
myfhem("define weckwachat at +03:00:00 set wach 1"); myfhemcmd ("define weckwachat at +03:00:00 set wach 1");
# myfhem("set wach 1"); # myfhem("set wach 1");
} }
#------------------------------------------ #------------------------------------------
sub Dbg($) { sub Dbg($) {
Log 1,$_[0]; Log3 "Roll", 1, $_[0];
} }
#------------------------------------------
sub RollRunterSchlitz($;$) { sub RollRunterSchlitz($;$) {
my ($roll, $delay) = @_; my ($roll, $delay) = @_;
$delay ||= 0; $delay ||= 0;
@@ -189,10 +196,12 @@ sub RollRunterSchlitz($;$) {
my $i=$tc++; my $i=$tc++;
Dbg("RollChg: $roll - runter schlitz($delay)\n"); Dbg("RollChg: $roll - runter schlitz($delay)\n");
myfhem("define r".$i." at +".$t." set ".$roll." closes"); myfhemcmd("define r".$i." at +".$t." set ".$roll." closes");
myfhem("define ru".$i." at +".$t2." set ".$roll." up 6"); myfhemcmd("define ru".$i." at +".$t2." set ".$roll." up 6");
} }
#------------------------------------------
sub RollHoch($;$) { sub RollHoch($;$) {
my ($roll, $delay) = @_; my ($roll, $delay) = @_;
$delay ||= 0; $delay ||= 0;
@@ -202,9 +211,11 @@ sub RollHoch($;$) {
my $i=$tc++; my $i=$tc++;
Dbg("RollChg: $roll - hoch($delay)\n"); Dbg("RollChg: $roll - hoch($delay)\n");
myfhem("define r".$i." at +".$t." set ".$roll." opens"); myfhemcmd("define r".$i." at +".$t." set ".$roll." opens");
} }
#------------------------------------------
sub RollRunter($;$) { sub RollRunter($;$) {
my ($roll, $delay) = @_; my ($roll, $delay) = @_;
$delay ||= 0; $delay ||= 0;
@@ -214,29 +225,33 @@ sub RollRunter($;$) {
my $i=$tc++; my $i=$tc++;
Dbg("RollChg: $roll - runter($delay)\n"); Dbg("RollChg: $roll - runter($delay)\n");
myfhem("define r".$i." at +".$t." set ".$roll." closes"); myfhemcmd("define r".$i." at +".$t." set ".$roll." closes");
} }
#------------------------------------------
sub IsSunny($) { sub IsSunny($) {
my ($wett)=@_; my ($wett)=@_;
if($wett==30 || $wett==31 || $wett==32 || $wett==33 || $wett==34 || $wett==35 || $wett==36) { # sonnig, heiter, heiss if($wett==30 || $wett==31 || $wett==32 || $wett==33 || $wett==34 || $wett==35 || $wett==36) { # sonnig, heiter, heiss
return(1); return(1);
} }
return(0); return(0);
} }
#------------------------------------------
sub IsLater($) { sub IsLater($) {
my($t)=@_; my($t)=@_;
#Dbg("Islater:$t"); #Dbg("Islater:$t");
my @time = localtime(time); my @time = localtime(time);
if ($t =~ /(\d+):(\d+)/ and ($time[2]>=$1) and ($time[1]>=$2) ) { if ($t =~ /(\d+):(\d+)/ and ($time[2]>=$1) and ($time[1]>=$2) ) {
Dbg("later:$t"); Dbg("later:$t");
return(1); return(1);
} }
return(0); return(0);
} }
#------------------------------------------
# Nach dem Wechsel auf !sonne noch 2Std warten # Nach dem Wechsel auf !sonne noch 2Std warten
sub IsWetterSonneWait($) { sub IsWetterSonneWait($) {
@@ -244,32 +259,34 @@ sub IsWetterSonneWait($) {
state $wettalt=0; state $wettalt=0;
if($wett != $wettalt) { if($wett != $wettalt) {
if(!IsSunny($wett)) { if(!IsSunny($wett)) {
if(IsSunny($wettalt)) { if(IsSunny($wettalt)) {
@blocktime=localtime; @blocktime=localtime;
$blocktime[2]+=2; # +2Std $blocktime[2]+=2; # +2Std
if($blocktime[2]>23) { $blocktime[2]=23; } # da nachts keine sonne scheint egal if($blocktime[2]>23) { $blocktime[2]=23; } # da nachts keine sonne scheint egal
$blocktimerRunning=1; $blocktimerRunning=1;
Dbg("son1"); Dbg("son1");
} }
} }
else { else {
} }
$wettalt=$wett; $wettalt=$wett;
} }
if($blocktimerRunning) { if($blocktimerRunning) {
if(!IsLater("$blocktime[2]:$blocktime[1]")) { if(!IsLater("$blocktime[2]:$blocktime[1]")) {
return(1); return(1);
} }
else { else {
$blocktimerRunning=0; $blocktimerRunning=0;
} }
} }
return(0); return(0);
} }
#------------------------------------------
sub RollCheck() { sub RollCheck() {
# Dbg("RollCheck\n"); #Dbg("RollCheck\n");
my $temp=20; my $temp=20;
my $r; my $r;
my $i=0; my $i=0;
@@ -280,16 +297,16 @@ sub RollCheck() {
my $twil=Value("twil"); my $twil=Value("twil");
if ($twil>=3 && $twil<10) { # civil if ($twil>=3 && $twil<10) { # civil
$tag=1; $tag=1;
myfhem("set tag 1"); myfhem("set tag 1");
} else { } else {
myfhem("set tag 0"); myfhem("set tag 0");
} }
my $light=ReadingsVal("twil", "light", 0); my $light=ReadingsVal("twil", "light", 0);
if ($light>=5) { # weather if ($light>=5) { # weather
myfhem("set hell 1"); myfhem("set hell 1");
} else { } else {
myfhem("set hell 0"); myfhem("set hell 0");
} }
my $wett=ReadingsVal("wetter", "code", 99); my $wett=ReadingsVal("wetter", "code", 99);
@@ -300,103 +317,104 @@ sub RollCheck() {
for $r ( @rolls ) { for $r ( @rolls ) {
my $fen="Closed"; my $fen="Closed";
my $tempH=0; my $tempH=0;
my $tempL=0; my $tempL=0;
my $sonne=0; my $sonne=0;
my $skipRunter=0; my $skipRunter=0;
my $skipHoch=0; my $skipHoch=0;
my $ndelay=$i*$delay+1; my $ndelay=$i*$delay+1;
#Dbg("--------r:g ".$r->{roll}." / ".$r->{temp}); #Dbg("--------r:g ".$r->{roll}." / ".$r->{temp});
# Raum zu warm und aussentemp hoch ? # Raum zu warm und aussentemp hoch ?
#$temp=ReadingsVal($r->{temp},"measured-temp", 99); #$temp=ReadingsVal($r->{temp},"measured-temp", 99);
$temp=ReadingsVal($r->{temp},"temperature", 99); $temp=ReadingsVal($r->{temp},"temperature", 99);
if( ($temp>$r->{tempS} && $tempOut>($r->{tempS}-3)) || $temp>($r->{tempS}+2) ) { if( ($temp>$r->{tempS} && $tempOut>($r->{tempS}-3)) || $temp>($r->{tempS}+2) ) {
$tempH=1; $tempH=1;
} }
if( $temp<$r->{tempS}-1 ) { if( $temp<$r->{tempS}-1 ) {
$tempL=1; $tempL=1;
} }
# Sonne scheint ins Fenster ? # Sonne scheint ins Fenster ?
if($twil>=5 && $twil<7) { # nur, wenn der Sonnenstand ueber 'weather' liegt if($twil>=5 && $twil<7) { # nur, wenn der Sonnenstand ueber 'weather' liegt
# bei hoher Raum- und Aussentemperatur immer unten lassen # bei hoher Raum- und Aussentemperatur immer unten lassen
if($temp > ($r->{tempS}+2) && $tempOut > $r->{tempS}) { if($temp > ($r->{tempS}+2) && $tempOut > $r->{tempS}) {
$sonne=1; $sonne=1;
} }
elsif (index($sr, $r->{dir}) != -1) { # Sonnenrichtung ins Fenster elsif (index($sr, $r->{dir}) != -1) { # Sonnenrichtung ins Fenster
if($sonneblock) { if($sonneblock) {
$sonne=1; $sonne=1;
} }
elsif(IsSunny($wett)) { elsif(IsSunny($wett)) {
$sonne=1; $sonne=1;
} }
#Dbg("son3, $sonne"); #Dbg("son3, $sonne");
} }
} }
# Offene Fenster nicht mit Rollaeden verschliessen # Offene Fenster nicht mit Rollaeden verschliessen
if($r->{win} ne "") { if($r->{win} ne "") {
$fen=Value($r->{win}); $fen=Value($r->{win});
#Dbg("test win:$r->{roll}-$fen"); #Dbg("test win:$r->{roll}-$fen");
if ($fen eq "Open") { if ($fen eq "Open") {
#Dbg("$r->{roll}:skipR"); #Dbg("$r->{roll}:skipR");
$skipRunter=1; $skipRunter=1;
} }
} }
# Zur Schlafzeit nicht oeffnen # Zur Schlafzeit nicht oeffnen
if($r->{typ} eq "s") { if($r->{typ} eq "s") {
if(Value("wach") eq "0") { if(Value("wach") eq "0") {
$skipHoch=1; $skipHoch=1;
} }
} }
Dbg("RollCheck:$r->{roll}-tempH:$tempH temp:$temp tempO:$tempOut so:$sonne wett:$wett sr:$sr twil:$twil tag:$tag fen:$fen skipR:$skipRunter skipH:$skipHoch st:$r->{state}"); Dbg("RollCheck:$r->{roll}-tempH:$tempH temp:$temp tempO:$tempOut so:$sonne wett:$wett sr:$sr twil:$twil tag:$tag fen:$fen skipR:$skipRunter skipH:$skipHoch st:$r->{state}");
if( $tag and $sonne and $tempH) { if( $tag and $sonne and $tempH) {
if($r->{state}!=STATE_SCHLITZ) { if($r->{state}!=STATE_SCHLITZ) {
if(!$skipHoch && !$skipRunter) { if(!$skipHoch && !$skipRunter) {
RollRunterSchlitz($r->{roll}, $ndelay); RollRunterSchlitz($r->{roll}, $ndelay);
} }
$r->{state}=STATE_SCHLITZ; $r->{state}=STATE_SCHLITZ;
} }
} }
if(($tag && !$sonne)||($tag && $tempL)) { if(($tag && !$sonne)||($tag && $tempL)) {
if($r->{state}!=STATE_HOCH) { if($r->{state}!=STATE_HOCH) {
if(!$skipHoch) { if(!$skipHoch) {
RollHoch($r->{roll}, $ndelay); RollHoch($r->{roll}, $ndelay);
$r->{state}=STATE_HOCH; $r->{state}=STATE_HOCH;
} }
} }
} }
if(!$tag) { if(!$tag) {
if($r->{state}!=STATE_RUNTER) { if($r->{state}!=STATE_RUNTER) {
if(!$skipRunter) { if(!$skipRunter) {
RollRunter($r->{roll}, $ndelay); RollRunter($r->{roll}, $ndelay);
} }
$r->{state}=STATE_RUNTER; $r->{state}=STATE_RUNTER;
} }
} }
$i=$i+1; $i=$i+1;
} # for } # for
} }
#------------------------------------------
sub Untoggle($) { sub Untoggle($) {
my ($obj) = @_; my ($obj) = @_;
if (Value($obj) eq "toggle"){ if (Value($obj) eq "toggle"){
if (OldValue($obj) eq "off") { if (OldValue($obj) eq "off") {
{fhem ("setstate ".$obj." on")} {fhem ("setstate ".$obj." on")}
} }
else { else {
{fhem ("setstate ".$obj." off")} {fhem ("setstate ".$obj." off")}
} }
} }
else { else {
{fhem "setstate ".$obj." ".Value($obj)} {fhem "setstate ".$obj." ".Value($obj)}
} }
} }