# $Id$ ############################################################################## # # 98_RandomTimer_Initialize.pm # written by Dietmar Ortmann # # 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 . # ############################################################################## # 10.09.2013 Svenson : disable direct if attribute changed, add state disabled; # randomtimer run every day if attribut runonce 0 (default is 1) # ############################################################################## package main; use strict; use warnings; use IO::Socket; use Time::HiRes qw(gettimeofday); use Time::Local 'timelocal_nocheck'; sub RandomTimer_stopTimeReached($); sub schaltZeitenErmitteln ($$); sub RandomTimer_setState($); sub RandomTimer_Initialize($) { my ($hash) = @_; if(!$modules{Twilight}{LOADED} && -f "$attr{global}{modpath}/FHEM/59_Twilight.pm") { my $ret = CommandReload(undef, "59_Twilight"); Log3 undef, 1, $ret if($ret); } $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 ". $readingFnAttributes; } ######################################################################## sub RandomTimer_Undef($$) { my ($hash, $arg) = @_; myRemoveInternalTimer("SetTimer", $hash); myRemoveInternalTimer("Exec", $hash); delete $modules{RandomTimer}{defptr}{$hash->{NAME}}; return undef; } ######################################################################## 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 \"[+][*]