########################################################################## # $Id$ # # copyright ################################################################### # # 98_RandomTimer.pm # # written by Dietmar Ortmann # Maintained by igami since 02-2018 # # This file is part of FHEM. # # FHEM is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # FHEM is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with FHEM. If not, see . # packages #################################################################### package main; use strict; use warnings; no if $] >= 5.017011, warnings => 'experimental::smartmatch'; use Time::HiRes qw(gettimeofday); use Time::Local 'timelocal_nocheck'; # forward declarations ######################################################## sub RandomTimer_Initialize($); sub RandomTimer_Define($$); sub RandomTimer_Undef($$); sub RandomTimer_Attr($$$); sub RandomTimer_addDays ($$); sub RandomTimer_device_switch ($); sub RandomTimer_device_toggle ($); sub RandomTimer_down($); sub RandomTimer_Exec($); sub RandomTimer_getSecsToNextAbschaltTest($); sub RandomTimer_isAktive ($); sub RandomTimer_isDisabled($); sub RandomTimer_schaltZeitenErmitteln ($$); sub RandomTimer_setActive($$); sub RandomTimer_setState($); sub RandomTimer_setSwitchmode ($$); sub RandomTimer_SetTimer($); sub RandomTimer_startZeitErmitteln ($$); sub RandomTimer_stopTimeReached($); sub RandomTimer_stopZeitErmitteln ($$); sub RandomTimer_Wakeup(); sub RandomTimer_zeitBerechnen ($$$$); # initialize ################################################################## sub RandomTimer_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "RandomTimer_Define"; $hash->{UndefFn} = "RandomTimer_Undef"; $hash->{AttrFn} = "RandomTimer_Attr"; $hash->{AttrList} = "onCmd offCmd switchmode disable:0,1 disableCond ". "runonce:0,1 keepDeviceAlive:0,1 forceStoptimeSameDay:0,1 ". $readingFnAttributes; } # regular Fn ################################################################## sub RandomTimer_Define($$) { my ($hash, $def) = @_; RemoveInternalTimer($hash); my ($name, $type, $timespec_start, $device, $timespec_stop, $timeToSwitch) = split("[ \t][ \t]*", $def); return "wrong syntax: define RandomTimer " if(!defined $timeToSwitch); return "Wrong timespec_start <$timespec_start>, use \"[+][*]