FHEM Forum

FHEM => English Corner => Thema gestartet von: id001 am 23 März 2021, 16:54:19

Titel: How to ignore specific readings?
Beitrag von: id001 am 23 März 2021, 16:54:19
Hello all! I have a problem and need some help.

I have a modbus to mqtt gateway which sometimes cant read the values correctly from my energy meters and returns "bad" instead of the values. See the attached picture.
The problem is with the statistics module. If at the end of the hour when the statistics are calculated for the last hour the "bad" reading messes up the values and the graphs, too.
How can I ignore this reading?

Thank you.
Titel: Antw:How to ignore specific readings?
Beitrag von: Beta-User am 23 März 2021, 17:40:00
You're a little spars wrt. to details how readings are generated (no list or RAW definition provided).

If it's always the word "bad", you could try to filter these words out by using some Perl in your readingList attribute.
Based on this from the 6channel_ethernet_board_6input_split attrTemplate:
attr DEVICE readingList Advantech/DEVNAME/data:.* { $EVENT =~ s/true/"on"/g;; $EVENT =~ s/false/"off"/g;; my $rets = json2nameValue($EVENT,'',$JSONMAP);; my %cleaned = map { $_,$rets->{$_} } grep { ReadingsVal($NAME,$_,"unknown") ne $rets->{$_} } keys %{$rets};; return \%cleaned }\
I'd suggest sth. like
attr DEVICE readingList <your topic>:.* { my $rets = json2nameValue($EVENT,'',$JSONMAP);; my %cleaned = map { $_,$rets->{$_} } grep { 'bad' ne $rets->{$_} } keys %{$rets};; return \%cleaned }
Titel: Antw:How to ignore specific readings?
Beitrag von: id001 am 23 März 2021, 19:27:42
Thank you, this is what I wanted.