kuhinja battery change
[vaillant-thermostat] / parse.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 my $curl;
6 my $influx = $ENV{INFLUX}; # || 'http://127.0.0.1:8086/write?db=boiler';
7
8 my $temp = '';
9
10 while(<>) {
11         chomp;
12         if ( s/\s+\|\s+(\d+\.\d\d).+$// ) {
13                 $temp = $1;
14         }
15 #$temp = ( $temp - 20 ) * 500 + 500;
16         if ( m/^([0-9\.]+) .+aa fc 39 aa (.+)/ ) {
17                 my $t = $1;
18                 #warn "# $1 $2\n";
19                 my @l = split(/\s+/,$2);
20                 my @d = (
21                         $t,
22                         hex( $l[0] . $l[1] ),
23                         hex( $l[3] . $l[4] ),
24                         hex( $l[6] ),
25                         hex( $l[12] ),
26                         hex( $l[14] ), # * 300,
27                         hex( $l[15] ), # * 400,
28                         hex( $l[18] ),
29                         $temp
30                 );
31                 if ( $influx ) {
32                         open($curl, '|-', qq( tee /dev/shm/parse.curl | curl -XPOST $influx --data-binary \@- )) unless $curl;
33                         print $curl "thermostat ",join(',', map { chr( ord('a') + $_ ) . '=' . $d[$_] . 'i' } 1 .. $#d ), ($temp ? ",temp=$temp" : ""), " ", int($t * 1_000_000_000), "\n";
34                 } else {
35                         print join(',', @d,$temp),$/;
36                 }
37         } else {
38                 warn "# $_\n";
39         }
40 }