diff --git a/fhem/CHANGED b/fhem/CHANGED index 7d8960e0e..22f1865b6 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - added: 98_CustomReadings.pm (maintainer: HCS) - change: 98_Text2Speech.pm: fix a problem with microseconds in time() by using mp3-templates or playing mp3 directly - feature: state definition and split attribute added to 66_ECMD, diff --git a/fhem/FHEM/98_CustomReadings.pm b/fhem/FHEM/98_CustomReadings.pm new file mode 100644 index 000000000..e66593a29 --- /dev/null +++ b/fhem/FHEM/98_CustomReadings.pm @@ -0,0 +1,201 @@ + +# $Id$ +# +# TODO: + +package main; + +use strict; +use warnings; +use SetExtensions; + +sub +CustomReadings_Initialize($) +{ + my ($hash) = @_; + + $hash->{DefFn} = "CustomReadings_Define"; + $hash->{UndefFn} = "CustomReadings_Undef"; + $hash->{AttrList} = "readingDefinitions " + . "interval " + . "$readingFnAttributes"; +} + +sub +CustomReadings_Define($$) +{ + my ($hash, $def) = @_; + my $name = $hash->{NAME}; + + CustomReadings_read($hash); + + return undef; +} + +sub CustomReadings_read($) +{ + my ($hash) = @_; + my $name = $hash->{NAME}; + + RemoveInternalTimer($hash); + InternalTimer(gettimeofday()+ AttrVal( $name, "interval", 5), "CustomReadings_read", $hash, 0); + + # Get the readingDefinitions and remove all newlines from the attribute + my $readingDefinitions = AttrVal( $name, "readingDefinitions", ""); + $readingDefinitions =~ s/\n//g; + + my @definitionList = split(',', $readingDefinitions); + my @used = ("state"); + + readingsBeginUpdate($hash); + foreach (@definitionList) { + my @definition = split(':', $_, 2); + push(@used, $definition[0]); + + my $value = eval($definition[1]); + if($value) { + $value =~ s/^\s+|\s+$//g; + } + else { + $value = "ERROR"; + } + + readingsBulkUpdate($hash, $definition[0], $value); + } + + readingsEndUpdate($hash, 1); + + foreach my $r (keys %{$hash->{READINGS}}) { + if (not $r ~~ @used ) { + delete $hash->{READINGS}{$r}; + } + } + +} + + +sub +CustomReadings_Undef($$) +{ + my ($hash, $arg) = @_; + my $name = $hash->{NAME}; + + RemoveInternalTimer($hash); + + return undef; +} + + +1; + +=pod +=begin html + + +

CustomReadings

+ + + + +=end html +=cut diff --git a/fhem/MAINTAINER.txt b/fhem/MAINTAINER.txt index d62768ec5..fc849d443 100644 --- a/fhem/MAINTAINER.txt +++ b/fhem/MAINTAINER.txt @@ -236,6 +236,7 @@ FHEM/98_cloneDummy.pm Joachim http://forum.fhem.de Automatis FHEM/98_cmdalias.pm rudolfkoenig http://forum.fhem.de Automatisierung FHEM/98_configdb.pm betateilchen http://forum.fhem.de Sonstiges FHEM/98_copy.pm justme1968 http://forum.fhem.de Sonstiges +FHEM/98_CustomReadings.pm HCS http://forum.fhem.de Unterstuetzende Dienste FHEM/98_dewpoint.pm wherzig http://forum.fhem.de Automatisierung FHEM/98_dummy.pm rudolfkoenig http://forum.fhem.de Automatisierung FHEM/98_fheminfo.pm mfr69bs http://forum.fhem.de Sonstiges diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index b8a083ed9..dd47a37d8 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -93,6 +93,7 @@ average   Calendar   configDB   + CustomReadings   DOIF   Dashboard   DbLog   diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index 9c8157465..c097bda16 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -40,6 +40,7 @@ configdb   copy   createlog   + CustomReadings   define   delete   deleteattr