# # # 93_PWMR.pm # written by Andreas Goebel 2012-07-25 # e-mail: ag at goebel-it dot de # ############################################## # $Id$ # 29.07.15 GA change set manualTempDuration # 21.09.15 GA update, use Log3 and readingsSingleUpdate # 07.10.15 GA initial version published # 07.10.15 GA fix calculation of PWMPulse, default for c_autoCalcTemp # 13.10.15 GA add event-on-change-reading # 14.10.15 GA fix round energyusedp # 15.10.15 GA add a_regexp_on, a regular expression for the on state of the actor # 05.11.15 GA fix new reading desired-temp-until which substitutes modification date of desired-temp in the future # events for desired-temp adjusted (no update of timestamp if temperature stays the same) # 10.11.15 GA fix event for actor change added again, desired-temp notifications adjusted for midnight change # 17.11.15 GA add ReadRoom will now set a reading named temperature containing the last temperature used for calculation # 18.11.15 GA add adjusted energyusedp to be in percent. Now it can be used in Tablet-UI as valve-position # 19.11.15 GA fix move actorState to readings # 22.11.15 GA fix rules on wednesday are now possible (thanks to Skusi) # 22.11.15 GA fix error handling in SetRoom (thanks to cobra112) # 30.11.15 GA fix set reading of desired-temp-used to frost_protect if window is opened # 30.11.15 GA add call PWMR_Attr in PWMR_Define if already some attributes are defined # 26.01.16 GA fix don't call AssignIoPort # 26.01.16 GA fix assign IODev as reference to that hash (otherwise xmllist will crash fhem) # 26.01.16 GA add implementation of PID regulation # 27.01.16 GA add attribute desiredTempFrom to take desiredTemp from another object # 04.02.16 GA add DLookBackCnt, buffer holding previouse temperatures used for PID D-Part calculation # 08.02.16 GA add ILookBackCnt, buffer holding previouse temperatures used for PID I-Part calculation # 08.02.16 GA add valueFormat attribute # 29.06.16 GA add "set frostProtect on|off" # 16.08.16 GA add event-min-interval # 23.09.16 GA fix changes on commandref based on suggestions from user "sledge" # 28.09.16 GA add readings for tempRules (single reading for Mo to So) # 04.10.16 GA fix adjust readings for tempRules if temperature changes # 11.10.16 GA fix delete log entries for PWMR_NormalizeRules # 17.10.16 GA fix attribute tempFrostProtect is now evaluated # 16.11.16 GA add display time until in state if "ManualSetUntil" # 16.11.16 GA fix format desired-temp with one digit after the decimal point # 17.11.16 GA add internals for configuration parameters: p_factor, p_tsensor, p_actor, p_window, p_pid # 11.12.16 GA add alternative PID calculation, selectable by usePID=2, implementation from user Albatros_ # 14.12.16 GA fix adjust rounding of PVal and newpulsePID # 14.12.16 GA fix supply DBuffer with delta temps for usePID=2 calculation # 14.12.16 GA add implement get previousTemps # 01.08.17 GA add documentation for attribute disable # 27.12.17 GA add handle "off" as c_tempFrostProtect and "on" as c_tempC in getDesiredTempFrom (valid form Homematic) # 31.01.18 GA add support for stateFormat # 08.02.18 GA fix PID_I_previousTemps was shortened to c_PID_DLookBackCnt instead of c_PID_ILookBackCnt in define # 19.11.18 GA add support for attribute maxOffTime # 19.11.18 GA add support hh:mm in set desired-temp # 20.11.18 GA add integrate $init_done into PWMR_Define to supress error messages during startup # 20.11.18 GA add change default for w_regexp from ".*Open.*" to ".*[Oo]pen.*" to fit for MAX window contacts # 11.02.19 GA add redesign of maxOffTime # 21.01.20 GA fix remove default tempRule if only tempRule1 or tempRule2 is defined # 28.12.20 GA fix reset maxOffTimeApply to 0 if heating is needed (decision depends on calculation model) # 20.01.21 GA fix remove DoTrigger; # the below due to hints from phys1 # fix prevent parallel InternalTimer calls # fix remove attribute loglevel # fix reading actorState to correct when non default regex is used # add clear PID helper structure when PWM or PWMR object gets disabled # 31.01.21 GA fix wrong time logged for "desired-temp was manualy set until" # 02.02.21 GA fix handle access to not yet defined iodev on startup # 13.03.22 GA fix handle error in attr desiredTempFrom when device is not yet defined during startup # module for PWM (Pulse Width Modulation) calculation # this module defines a room for calculation # it is used by a PWM object # reference to the PWM object is via IODev # PWMR object defines: # IODev: reference to PWM # factor (also used in Pulse calculation): # temperatur difference * factor * cycletime (from PWM) defines on/off periods (pulse) # sensor delivering the temperature (temperature is read from reading using a regexp) # actor to switch on/off the heating devices (may be a structure if more than on actor..) # comma separated list of window contacts followd by ":" and a regular expression # default for the regular expression is "Open" # if the regular expression matches on of the contacts # then readRoom will return c_tempFrostProtect as desired-temp # instead of the current calculated desired-temp # this should cause the calculation routine for the room to switch off heating # # calculation of "desired-temp" is done in a loop (5-minutes default) # - if c_frostProtect is "1" -> set to c_tempFrostProtect # - if c_autoCalcTemp is "1" -> use c_tempN, c_tempD, c_tempC, c_tempE and c_tempRule[1-5] # - c_* variables are syntax checked and derived from attr which have a readable syntax # # - c_tempRule[1-5] are processed in order 5..1 (5 is highes priority) # rules define: # ,[N|D|C] [