########################################################################## # $Id: 98_RandomTimer.pm 21449 2020-03-19 11:07:03Z Beta-User $ # # copyright ################################################################### # # 98_RandomTimer.pm # # written by Dietmar Ortmann # Maintained by Beta-User since 11-2019 # # 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 #################################################################### ## unserer packagename package FHEM::RandomTimer; use strict; use warnings; no if $] >= 5.017011, warnings => 'experimental::smartmatch'; use Time::HiRes qw(gettimeofday); use Time::Local 'timelocal_nocheck'; use GPUtils qw(GP_Import GP_Export); ## Import der FHEM Funktionen #-- Run before package compilation BEGIN { # Import from main context GP_Import( qw( readingsSingleUpdate readingsBulkUpdate readingsBeginUpdate readingsEndUpdate defs modules Log Log3 attr readingFnAttributes AttrVal ReadingsVal featurelevel Value FmtDateTime strftime max stacktrace GetTimeSpec ) ); } #-- Export to main context with different name GP_Export( qw( Initialize Exec ) ); # initialize ################################################################## sub Initialize { my ($hash) = @_; $hash->{DefFn} = 'FHEM::RandomTimer::Define'; $hash->{UndefFn} = 'FHEM::RandomTimer::Undef'; $hash->{SetFn} = 'FHEM::RandomTimer::Set'; $hash->{AttrFn} = 'FHEM::RandomTimer::Attr'; $hash->{AttrList} = 'onCmd offCmd switchmode disable:0,1 disableCond disableCondCmd:none,offCmd,onCmd offState ' . 'runonce:0,1 keepDeviceAlive:0,1 forceStoptimeSameDay:0,1 ' . $readingFnAttributes; } # regular Fn ################################################################## sub Define { my ( $hash, $def ) = @_; main::RemoveInternalTimer($hash); my ( $name, $type, $timespec_start, $device, $timespec_stop, $timeToSwitch, $variation ) = split( "[ \t][ \t]*", $def ); return "wrong syntax: define RandomTimer []" if ( !defined $timeToSwitch ); return "Wrong timespec_start <$timespec_start>, use \"[+][*]