rain today from log

Begonnen von Guest, 08 September 2011, 22:29:46

Vorheriges Thema - Nächstes Thema

Guest

Originally posted by: <email address deleted>

Hi,

I'm using the oregon rain sensor with fhem.

Now I want to get the daily rain as a value.

So i want the 1st measure of the day, and the last

the format looks like this. So today I have 1771.0912 - 1762.6838=
8.4mm rain

Anyone knows how to grab it with date,tail, awk grep or else to get
the 8.4?


2011-09-08_00:00:28 Regenmeter rain_rate: 0
2011-09-08_00:00:28 Regenmeter rain_total: 1762.6838
2011-09-08_00:00:28 Regenmeter battery: 90
2011-09-08_00:00:28 Regenmeter RR: 0 TR: 1762.6838


2011-09-08_22:23:53 Regenmeter rain_rate: 0
2011-09-08_22:23:53 Regenmeter rain_total: 1771.0912
2011-09-08_22:23:53 Regenmeter battery: 90
2011-09-08_22:23:53 Regenmeter RR: 0 TR: 1771.0912

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Dr. Boris Neubert

                                             

Hi,

Am 08.09.2011 22:29, schrieb kroonen:
> I'm using the oregon rain sensor with fhem.
>
> Now I want to get the daily rain as a value.
>
> So i want the 1st measure of the day, and the last
>
This is possible, in principle, with a shell script, but quite a
cumbersome task. I suggest that you rather amend the respective Oregon
FHEM module. Please have a look at the code 13_KS300.pm. It keeps track
of the first value received for the day and exposes a reading cum_day.

Kind regards
Boris

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

rudolfkoenig

                                                   

> Anyone knows how to grab it with date,tail, awk grep or else to get
> the 8.4?

I'd recommend collecting the value from the first occurance of the last day
till the first occurence of the current day, so there are no holes.  This is
also how the avarage computation in the KS300 module is working.  For this
purpose you could use:

  perl -ane '{
    next if($F[2] ne "rain_total:");

    @d=split('_',$F[0]);

    if(!$lastV) {
      $lastV=$F[3];
      $lastD=$d[0];
    }
    if($lastD ne $d[0]) {
      printf "$d[0] %f\n", ($F[3]-$lastV);
      $lastV=$F[3];
      $lastD=$d[0];
    }
  }' file

Adding the avarage_day/avarage_month semantic to the module is of course
better, as it would make life easier for others too.

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Guest

Originally posted by: <email address deleted>

Rudolf it works but gets all the days. I only want today is this
simple to adjust?


2011-09-06 1.117600
2011-09-07 10.490200
2011-09-08 3.200400
2011-09-09 8.407400
2011-09-10 0.000000

I tried tail -n1, this works but he grabbing the whole log, so takes 2
minutes or so.

regads Richard

On Sep 9, 10:06 am, Rudolf Koenig wrote:
> > Anyone knows how to grab it with date,tail, awk grep or else to get
> > the 8.4?
>
> I'd recommend collecting the value from the first occurance of the last day
> till the first occurence of the current day, so there are no holes.  This is
> also how the avarage computation in the KS300 module is working.  For this
> purpose you could use:
>
>   perl -ane '{
>     next if($F[2] ne "rain_total:");
>
>     @d=split('_',$F[0]);
>
>     if(!$lastV) {
>       $lastV=$F[3];
>       $lastD=$d[0];
>     }
>     if($lastD ne $d[0]) {
>       printf "$d[0] %f\n", ($F[3]-$lastV);
>       $lastV=$F[3];
>       $lastD=$d[0];
>     }
>   }' file
>
> Adding the avarage_day/avarage_month semantic to the module is of course
> better, as it would make life easier for others too.

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Guest

Originally posted by: <email address deleted>

It also rained last hour, but it doesn't say yet ow much, while fhem
pgm2 already reports around 22mm in the graph

regards Richard


On Sep 10, 8:35 pm, kroonen wrote:
> Rudolf it works but gets all the days. I only want today is this
> simple to adjust?
>
> 2011-09-06 1.117600
> 2011-09-07 10.490200
> 2011-09-08 3.200400
> 2011-09-09 8.407400
> 2011-09-10 0.000000
>
> I tried tail -n1, this works but he grabbing the whole log, so takes 2
> minutes or so.
>
> regads Richard
>
> On Sep 9, 10:06 am, Rudolf Koenig wrote:
>
>
>
>
>
>
>
> > > Anyone knows how to grab it with date,tail, awk grep or else to get
> > > the 8.4?
>
> > I'd recommend collecting the value from the first occurance of the last day
> > till the first occurence of the current day, so there are no holes.  This is
> > also how the avarage computation in the KS300 module is working.  For this
> > purpose you could use:
>
> >   perl -ane '{
> >     next if($F[2] ne "rain_total:");
>
> >     @d=split('_',$F[0]);
>
> >     if(!$lastV) {
> >       $lastV=$F[3];
> >       $lastD=$d[0];
> >     }
> >     if($lastD ne $d[0]) {
> >       printf "$d[0] %f\n", ($F[3]-$lastV);
> >       $lastV=$F[3];
> >       $lastD=$d[0];
> >     }
> >   }' file
>
> > Adding the avarage_day/avarage_month semantic to the module is of course
> > better, as it would make life easier for others too.

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Guest

Originally posted by: <email address deleted>

On 10 Sep., 21:20, kroonen wrote:
> It also rained last hour, but it doesn't say yet ow much, while fhem
> pgm2 already reports around 22mm in the graph
>
> regards Richard
>
> On Sep 10, 8:35 pm, kroonen wrote:

What is about the following script?

#!/bin/sh
FILE=$1
LINES=9000
tail -${LINES} ${FILE}|perl -e '{
    while (<>) {
      @F = split(/ /);
      next if($F[2] ne "rain_total:");
      @d=split('_',$F[0]);
      $rain_total_last_today = $F[3];
      if(!$rain_total_first_today) {
        $rain_total_first_today = $rain_total_last_today;
        $lastD=$d[0];
      }
      if($lastD ne $d[0]) {
        $rain_total_first_today = $F[3];
        $lastD=$d[0];
      }
    }
    # print rain total of today
    printf "%f\n", ($rain_total_last_today-$rain_total_first_today);
  }'

Today I get the following

./do_rain.sh /var/log/fhem/PCR800_5d-2011.log
12.598400

The number of lines ($LINES) for tail should be so that at least the
lines of the whole day will be returned.
On your log there are 4 lines about x seconds. My PCR800 sends status
every 40 seconds. This would be 4*24*60*60/40 = 8640 lines.

Hope this helps.

Regards

Willi

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Guest

Originally posted by: <email address deleted>

On 9 Sep., 10:06, Rudolf Koenig wrote:
> Adding the avarage_day/avarage_month semantic to the module is of course
> better, as it would make life easier for others too.

Your are right.

On the other hand it works with an external script. For me the effort
to implement and test this in the module is higher that the gain. It
seems that there are only few FHEM users that both have an RFXCOM
receiver and Oregon rain gauge.

Of course I would be very happy if somebody else wants to implement it
in the OREGON module.

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Guest

Originally posted by: <email address deleted>

Willi,

I think the script works, Today no rain yet;-)

Have you got also an idea howto run the script from rudolf for only
last 7 days?

So I get these results, The I can simply add graphs with gnuplot with
it

2011-09-04 0.000000
2011-09-05 13.690600
2011-09-06 1.117600
2011-09-07 10.490200
2011-09-08 3.200400
2011-09-09 8.407400
2011-09-10 0.000000
2011-09-11 27.406600

regards Richard


On Sep 11, 4:06 pm, Willi wrote:
> On 10 Sep., 21:20, kroonen wrote:
>
> > It also rained last hour, but it doesn't say yet ow much, while fhem
> > pgm2 already reports around 22mm in the graph
>
> > regards Richard
>
> > On Sep 10, 8:35 pm, kroonen wrote:
>
> What is about the following script?
>
> #!/bin/sh
> FILE=$1
> LINES=9000
> tail -${LINES} ${FILE}|perl -e '{
>     while (<>) {
>       @F = split(/ /);
>       next if($F[2] ne "rain_total:");
>       @d=split('_',$F[0]);
>       $rain_total_last_today = $F[3];
>       if(!$rain_total_first_today) {
>         $rain_total_first_today = $rain_total_last_today;
>         $lastD=$d[0];
>       }
>       if($lastD ne $d[0]) {
>         $rain_total_first_today = $F[3];
>         $lastD=$d[0];
>       }
>     }
>     # print rain total of today
>     printf "%f\n", ($rain_total_last_today-$rain_total_first_today);
>   }'
>
> Today I get the following
>
> ./do_rain.sh /var/log/fhem/PCR800_5d-2011.log
> 12.598400
>
> The number of lines ($LINES) for tail should be so that at least the
> lines of the whole day will be returned.
> On your log there are 4 lines about x seconds. My PCR800 sends status
> every 40 seconds. This would be 4*24*60*60/40 = 8640 lines.
>
> Hope this helps.
>
> Regards
>
> Willi

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com

Guest

Originally posted by: <email address deleted>

On 11 Sep., 20:34, kroonen wrote:
> Have you got also an idea howto run the script from rudolf for only
> last 7 days?

No. Guess you have to modify it.............

But this is my modified quick and dirty (not beautifully) version.
Adjust $LINES to your needs (number of lines so that there are at
least 7 days).


#!/bin/sh
FILE=$1
LINES=61000
tail -${LINES} ${FILE}|perl -e '{
    while (<>) {
      @F = split(/ /);
      next if($F[2] ne "rain_total:");

      @d=split('_',$F[0]);
      $rain_total_last_today = $F[3];
      if(!$rain_total_first_today) {
        $rain_total_first_today = $rain_total_last_today;
        $lastD=$d[0];
      }
      if($lastD ne $d[0]) {
        printf "$lastD %f\n", ($F[3]-$rain_total_first_today);
        $rain_total_first_today=$F[3];
        $lastD=$d[0];
      }
    }
    # print rain total of today
    printf "$d[0] %f\n", ($rain_total_last_today-
$rain_total_first_today);

  }'

--
To unsubscribe from this group, send email to
fhem-users+unsubscribe@googlegroups.com