Smart Meter P1 port support in fhem

Begonnen von kroonen, 04 Januar 2014, 21:34:38

Vorheriges Thema - Nächstes Thema

kroonen

Hi,

In the netherlands the meters for gas and electricity will be replaced the next years everywhere door smart meters. The energy companies can read your meter and they give you the usage on the fly on there website.

But on those meters are also an rj11 jack where you also can read the data from. Every 10 seconds the values will show.

Now I want also this will be integrated into them, but I have no program experience but I already found some perl program that read the data and put it into a database. Can somebody help me to get this into a module for them.

This is the code I found to read the smart meter (ISKRA ME382)

#!/usr/bin/perl

use strict;
use Data::Dumper;
use Device::SerialPort;
use DBI;

my $dbh = DBI->connect('DBI:mysql:power_usage:192.168.1.2', 'xxxxxxx', 'xxxxxx'
               ) || die "Could not connect to database: $DBI::errstr";


my $debug = 0;

my $PortObj = Device::SerialPort->new("/dev/ttyUSB0");
$PortObj->databits(7);
$PortObj->baudrate(9600);
$PortObj->parity('even');
$PortObj->stopbits(1);

$PortObj->are_match("/ISk5\2MT382-1003", "!");    # possible end strings
$PortObj->lookclear;                  # empty buffers
$PortObj->write("Feed Me:");          # initial prompt
#$PortObj->is_prompt("More Food:");    # not implemented

my $gotit = "";
until ("" ne $gotit) {
    $gotit = $PortObj->lookfor;       # poll until data ready
    die "Aborted without match\n" unless (defined $gotit);
    sleep 1;                          # polling sample time
}

printf "gotit = %s\n", $gotit if ($debug == 1); # input BEFORE the match
my ($match, $after, $pattern, $instead) = $PortObj->lastlook;
      # input that MATCHED, input AFTER the match, PATTERN that matched
      # input received INSTEAD when timeout without match
printf "lastlook-match = %s  -after = %s  -pattern = %s\n", $match, $after, $pat                                                      tern if ($debug == 2);

# Example
#Line 0:
#Line 1: /ISk5\2MT382-1003
#Line 2:
#Line 3: 0-0:96.1.1(5A424556303035303830383938343132)
#Line 4: 1-0:1.8.1(00817.914*kWh)
#Line 5: 1-0:1.8.2(00401.037*kWh)
#Line 6: 1-0:2.8.1(00210.914*kWh)
#Line 7: 1-0:2.8.2(00443.454*kWh)
#Line 8: 0-0:96.14.0(0002)
#Line 9: 1-0:1.7.0(0000.10*kW)
#Line 10: 1-0:2.7.0(0000.00*kW)
#Line 11: 0-0:17.0.0(0999.00*kW)
#Line 12: 0-0:96.3.10(1)
#Line 13: 0-0:96.13.1()
#Line 14: 0-0:96.13.0()
#Line 15: 0-1:24.1.0(3)
#Line 16: 0-1:96.1.0(3338303034303031313338333032373131)
#Line 17: 0-1:24.3.0(120822100000)(00)(60)(1)(0-1:24.2.1)(m3)
#Line 18: (00283.940)
#Line 19: 0-1:24.4.0(1)

my($ltu,$htu,$ltp,$htp,$actual,$gas);
my @lines = split("\n", $gotit);
print Dumper @lines if ($debug == 1);
foreach my $line (@lines) {
    if($line =~ /1-0:1.8.1/) {
        # Set High tarrif
        $line =~ s/1-0:1.8.1\(//;
        $line =~ s/\*kWh\)//;
        $ltu = $line;
        print "low tarrif used: " . $line . "\n" if ($debug == 1);
    } elsif ($line =~ /1-0:1.8.2/) {
        # Set Low tarrif
        $line =~ s/1-0:1.8.2\(//;
        $line =~ s/\*kWh\)//;
        $htu = $line;
        print "high tarrif used: " . $line . "\n" if ($debug == 1);
    } elsif ($line =~ /1-0:2.8.1/) {
        # Set high tarrif produced
        $line =~ s/1-0:2.8.1\(//;
        $line =~ s/\*kWh\)//;
        $ltp = $line;
        print "low tarrif produced: " . $line . "\n" if ($debug == 1);
    } elsif ($line =~ /1-0:2.8.2/) {
        # Set Low tarrif produced
        $line =~ s/1-0:2.8.2\(//;
        $line =~ s/\*kWh\)//;
        $htp = $line;
        print "high tarrif produced: " . $line . "\n" if ($debug == 1);
    } elsif ($line =~ /1-0:1.7.0/) {
        # Set actual usage
        $line =~ s/1-0:1.7.0\(//;
        $line =~ s/\*kW\)//;
        $actual = $line;
        my $actualUsage = $line * 1000.0;
        print "Current usage: " . $actualUsage . "\n" if ($debug == 1);
    } elsif ($line =~ /0-1:24.3.0/) {
        # Set gas usage
        $lines[17] =~ s/\(//;
        $lines[17] =~ s/\)//;
        $gas = $lines[17];
        print "Gas usage: " . $gas . "\n" if ($debug == 1);
    } else {
        next;
    }
}

my $sql = "insert into iskra_meter (low_tarrif_used, normal_tarrif_used, low_tar                                                      rif_produced, normal_tarrif_produced, actual_usage, gas_usage) values (?,?,?,?,?                                                      ,?)";
my $sth = $dbh->prepare($sql);
$sth->execute($ltu,$htu,$ltp,$htp,$actual,$gas);
$dbh->disconnect();

HarryT

Hi

Is this already implemented?

Thanks
FHEM 6.3 auf Raspberry Pi3  (1,2 Ghz)
RFXTRX433XL, ZWave, KFL200 and ConBeeIII
Raspberry Pi1 (0,7 Ghz) and Raspberry Pi4 for testing
German reading skills are good.