From 988899df41c986b756a0b3c73b3fe121ad854b20 Mon Sep 17 00:00:00 2001
From: herrmannj <>
Date: Mon, 10 Feb 2020 23:32:50 +0000
Subject: [PATCH] 59_GSI.pm: initial check-in
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@21172 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
FHEM/59_GSI.pm | 725 +++++++++++++++++++++++++++++++++++++++++++++++++
fhem.cfg | 36 ++-
2 files changed, 759 insertions(+), 2 deletions(-)
create mode 100644 FHEM/59_GSI.pm
diff --git a/FHEM/59_GSI.pm b/FHEM/59_GSI.pm
new file mode 100644
index 000000000..cf60fec3b
--- /dev/null
+++ b/FHEM/59_GSI.pm
@@ -0,0 +1,725 @@
+# $Id$
+###############################################################################
+#
+# This file is part of fhem.
+#
+# Fhem is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Fhem is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with fhem. If not, see .
+#
+#
+###############################################################################
+
+package main;
+
+use strict;
+use warnings;
+use utf8;
+use Time::HiRes qw( gettimeofday tv_interval );
+use HttpUtils;
+
+sub GSI_Initialize {
+ my ($hash) = @_;
+
+ $hash->{'DefFn'} = 'GSI_Define';
+ $hash->{'UndefFn'} = 'GSI_Undef';
+ $hash->{'NotifyFn'} = 'GSI_Notify';
+ $hash->{'FW_detailFn'} = 'GSI_FW_detailFn';
+ $hash->{'AttrList'} = "$readingFnAttributes ";
+ $hash->{'NOTIFYDEV'} = 'TYPE=Global';
+ return undef;
+};
+
+sub GSI_Define {
+ my ($hash, $def) = @_;
+ my ($name, $type, $plz) = split /\s/, $def;
+
+ my $cvsid = '$Id$';
+
+ return "German ZIP code required" unless ($plz =~ m/\d{5}/);
+ $hash->{'ZIP'} = $plz;
+ $hash->{'SVN'} = $cvsid;
+
+ $attr{$name}{'devStateIcon'} = '{GSI::devStateIcon($name)}';
+ GSI_Run($hash) if ($init_done);
+ return undef;
+};
+
+sub GSI_Undef {
+ my ($hash) = @_;
+
+ RemoveInternalTimer($hash, \&GSI_ApiRequest);
+ RemoveInternalTimer($hash, \&GSI_doReadings);
+ return undef;
+};
+
+sub GSI_Notify {
+ my ($hash, $dev) = @_;
+ my $name = $hash->{'NAME'};
+ return undef if(IsDisabled($name));
+
+ my $events = deviceEvents($dev, 1);
+ return if(!$events);
+
+ foreach my $event (@{$events}) {
+ my @e = split /\s/, $event;
+ Log3 ($name, 5, sprintf('[%s] event:[%s], device:[%s]', $name, $event, $dev->{'NAME'}));
+ if ($dev->{'TYPE'} eq 'Global') {
+ if ($e[0] and $e[0] eq 'INITIALIZED') {
+ GSI_Run($hash);
+ };
+ };
+ };
+};
+
+sub GSI_FW_detailFn {
+ my ($FW_wname, $name, $FW_room) = @_;
+ my $hash = $defs{$name};
+
+ my $ret;
+
+ if (exists($hash->{'forecast'}) and scalar @{$hash->{'forecast'}}) {
+ my $fc = $hash->{'forecast'};
+
+ $ret = '
';
+ $ret .= sprintf(<<'HTML', 'Zeit', 'Index (EE)', 'Co2 (EE)', 'Co2 (Std.Mix)');
+
+ |
+ |
+ |
+
+ |
+HTML
+ $ret .= '';
+ my $i = 0;
+ foreach my $e (@{$fc}) {
+ last if ($i++ == 24);
+ my $p0 = ($i % 2 == 1)?'odd':'even';
+ my $p1 = POSIX::strftime('%a %R (%D)', localtime($e->{'epochtime'}));
+ my $p2 = $e->{'eevalue'};
+ my $p3 = $e->{'co2_g_oekostrom'};
+ my $p4 = $e->{'co2_g_standard'};
+ $ret .= sprintf(<<'HTML', $p0, $p1, $i, $p2, $i, $p3, $i, $p4);
+
+ %s |
+ %i |
+ %s g/kWh |
+ %s g/kWh |
+
+HTML
+ };
+ return "$ret