added influxdb export and temperature extraction
[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                 );
30                 if ( $influx ) {
31                         open($curl, '|-', qq( tee /dev/shm/parse.curl | curl -XPOST $influx --data-binary \@- )) unless $curl;
32                         print $curl "thermostat ",join(',', map { chr( ord('a') + $_ ) . '=' . $d[$_] . 'i' } 1 .. $#d ), ($temp ? ",temp=$temp" : ""), " ", int($t * 1_000_000_000), "\n";
33                 } else {
34                         print join(',', @d,$temp),$/;
35                 }
36         } else {
37                 warn "# $_\n";
38         }
39 }