From b265838f49d2722c10cd98e7b214674fb5a1fe09 Mon Sep 17 00:00:00 2001 From: jamesgo Date: Thu, 19 Nov 2015 09:47:05 +0000 Subject: [PATCH] 94_PWM.pm : add additional parameter in definition. OverallHeatingSwitch can be used to control pumps or heating systems if all rooms are switched off git-svn-id: https://svn.fhem.de/fhem/trunk@9933 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/94_PWM.pm | 72 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/fhem/contrib/94_PWM.pm b/fhem/contrib/94_PWM.pm index 4e7939bdc..cea5d1ea4 100644 --- a/fhem/contrib/94_PWM.pm +++ b/fhem/contrib/94_PWM.pm @@ -9,6 +9,7 @@ # 13.10.15 GA add event-on-change-reading # 13.10.15 GA add several readings # 15.10.15 GA add reading for avg pulses +# 19.10.15 GA add overall heating switch ############################################## # $Id: @@ -333,7 +334,8 @@ PWM_Calculate($) } $minRoomsOnList =~ s/,$//; - #if ($roomsActive == 0 or $hash->{NoRoomsToStayOnThreshold} == 0 or $newpulseSum/$roomsActive < $hash->{NoRoomsToStayOnThreshold}) { + #if ($roomsActive == 0 or $hash->{NoRoomsToStayOnThreshold} == 0 or $newpulseSum/$roomsActive < $hash->{NoRoomsToStayOnThreshold}) + if ($roomsActive == 0 or $hash->{NoRoomsToStayOnThreshold} == 0 or $pulseSum/$roomsCounted < $hash->{NoRoomsToStayOnThreshold}) { $minRoomsOn = 0; @@ -432,6 +434,32 @@ PWM_Calculate($) readingsBulkUpdate ($hash, "roomsToStayOn", $minRoomsOn); readingsBulkUpdate ($hash, "roomsToStayOnList", $minRoomsOnList); } + + if ( defined ($hash->{OverallHeatingSwitch}) ) { + if ( $hash->{OverallHeatingSwitch} ne "") { + + my $newstate = ($cntRoomsOn > 0) ? "on" : "off"; + my $actor = $hash->{OverallHeatingSwitch}; + my $actstate = ($defs{$actor}{STATE} =~ $hash->{OverallHeatingSwitch_regexp_on}) ? "on" : "off"; + + if ($newstate ne $actstate) { + + my $ret = fhem sprintf ("set %s %s", $hash->{OverallHeatingSwitch}, $newstate); + if (!defined($ret)) { # sucessfull + Log3 ($name, 4, "PWMR_SetRoom: $name: set $actor $newstate"); + + readingsBulkUpdate ($hash, "OverallHeatingSwitch", $newstate, 1); + +# push @{$room->{CHANGED}}, "actor $newstate"; +# DoTrigger($name, undef); + + } else { + Log3 ($name, 4, "PWMR_SetRoom $name: set $actor $newstate failed ($ret)"); + } + } + } + } + readingsEndUpdate($hash, 1); @@ -617,8 +645,9 @@ PWM_Define($$) my $name = $hash->{NAME}; - return "syntax: define PWM [] [] [] [] [,] [,,]" - if(int(@a) < 2 || int(@a) > 8); + return "syntax: define PWM [] [] [] [] [,] [,,]". + " [[;]]" + if(int(@a) < 2 || int(@a) > 9); my $interval = ((int(@a) > 2) ? $a[2] : 60); my $cycletime = ((int(@a) > 3) ? $a[3] : 900); @@ -676,6 +705,30 @@ PWM_Define($$) } + ########## + # [] + + + + if (int(@a) > 8) { + my ($hactor, $h_regexp_on) = split (":", $a[8], 2); + $h_regexp_on = "on" unless defined ($h_regexp_on); + + if (!$defs{$hactor} && $hactor ne "dummy") + { + my $msg = "$name: Unknown actor device $hactor specified"; + Log3 ($hash, 3, "PWM_Define $msg"); + return $msg; + } + + + $hash->{OverallHeatingSwitch} = $hactor; + $hash->{OverallHeatingSwitch_regexp_on} = $h_regexp_on; + } else { + $hash->{OverallHeatingSwitch} = ""; + $hash->{OverallHeatingSwitch_regexp_on} = ""; + } + AssignIoPort($hash); if($hash->{INTERVAL} > 0) { @@ -724,7 +777,9 @@ sub PWM_Undef($$) Define
    - define <name> PWM [<interval>] [<cycletime>] [<minonofftime>] [<maxPulse>] [<maxSwitchOnPerCycle>,<maxSwitchOffPerCycle>] [<roomStayOn>,<roomStayOff>,<stayOnThreshold>]
    + define <name> PWM [<interval>] [<cycletime>] [<minonofftime>] [<maxPulse>] [<maxSwitchOnPerCycle>,<maxSwitchOffPerCycle>] [<roomStayOn>,<roomStayOff>,<stayOnThreshold>] [<overallHeatingSwitch>]
    +
    + eg. define fb PWM 60 900 120 1 99,99 0,0,0 pumpactor

    Define a calculation object with the following parameters:
      @@ -765,10 +820,17 @@ sub PWM_Undef($$) stayOnThreshold = 0 ... no impact.
      For energy saving reasons the following may be set: "4,1,0.25". This means:
      The room with the least pulse will be kept off (roomsStayOff=1)
      - If the average pulse for the (roomsStayOn=4) rooms with the most heating required is greater than (stayOnThreshold=0.25) then maxRoomStayOn will be kept in state "on", even it the time for the current pulse is reached. + If the average pulse for the (roomsStayOn=4) rooms with the most heating required is greater than (stayOnThreshold=0.25) then maxRoomStayOn will be kept in state "on", even if the time for the current pulse is reached. If the threshold is not reached (not so much heating required) then all rooms can be switched off at the same time.

      + +
    • overallHeatingSwitch[:<overallHeatingSwitch_regexp_on>]
      + Universal switch to controll eg. pumps or the heater itself. It will be set to "off" if no heating is required (all rooms off) and otherwise "on".
      + overallHeatingSwitch_regexp_on defines a regular expression to be applied to the state of the actor. Default is 'on". If state matches the regular expression it is handled as "on", otherwise "off"
      +
      +
    • +