Werte via Perl abfragen und anzeigen

Begonnen von olgo59, 01 November 2015, 14:15:38

Vorheriges Thema - Nächstes Thema

olgo59

Hallo Gemeinde,
ich versuche mein Raumthermostat "Heatmiser Wifi" mit FHEM ab zu fragen, einzustellen und die Werte anzeigen zu lassen.
Ich habe ein Heatmiser Logging via Perl und mysql Datenbank bereits am laufen.

Jetzt würde ich gerne das Perl-Script nutzen um die Werte in FHEM angezeigt zu bekommen, leider fehlt mir das KnowHow dafür und daher hoffe ich auf Eure Unterstützung.

Das Perl Script:
#!/usr/bin/perl

# This is a simple script to illustrate use of the Heatmiser Wi-Fi Perl
# library for accessing the iPhone interface of Heatmiser's range of Wi-Fi
# enabled thermostats.

# Copyright © 2011, 2012 Alexander Thoukydides
#
# This file is part of the Heatmiser Wi-Fi project.
# <http://code.google.com/p/heatmiser-wifi/>
#
# Heatmiser Wi-Fi 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 3 of the License, or (at your option)
# any later version.
#
# Heatmiser Wi-Fi 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 Heatmiser Wi-Fi. If not, see <http://www.gnu.org/licenses/>.


# Catch errors quickly
use strict;
use warnings;

# Allow use of modules in the same directory
use Cwd 'abs_path';
use File::Basename;
use lib dirname(abs_path $0);

# Useful libraries
use Getopt::Std;
use heatmiser_config;
use heatmiser_wifi;

# Command line options
my ($prog) = $0 =~ /([^\\\/]+$)/;
sub VERSION_MESSAGE { print "Heatmiser Wi-Fi Thermostat CLI v1\n"; }
sub HELP_MESSAGE { print "Usage: $prog [-h <host>] [-p <pin>] [-d]\n"; }
$Getopt::Std::STANDARD_HELP_VERSION = 1;
our ($opt_h, $opt_p, $opt_d);
getopts('h:p:d');
heatmiser_config::set(host => [h => $opt_h], pin => [p => $opt_p],
                      debug => $opt_d);

# Loop through all configured hosts
foreach my $host (@{heatmiser_config::get_item('host')})
{
    # Read the current status of the thermostat
    print "### $host ###\n";
    my $heatmiser = new heatmiser_wifi(host => $host,
                                       heatmiser_config::get(qw(pin)));
    my @dcb = $heatmiser->read_dcb();
# Display the thermostat's status
    if (heatmiser_config::get_item('debug'))
    {
        # Dump the raw DCB data for debugging purposes
        for (my $index = 0; $index < @dcb; $index += 8)
        {
            my $values = scalar @dcb - $index < 8 ? scalar @dcb - $index : 8;
            printf "%11s%-48s # (index %3i - %3i)\n",
                   $index ? '' : 'my @dcb = (',
                   join(', ', map { sprintf '0x%02x', $_ }
                                  @dcb[$index .. $index + $values - 1])
                   . ($index + $values < @dcb ? ',' : ');'),
                   $index, $index + $values - 1;
        }
    }
    else
    {
        # Convert the DCB to readable text
        my $status = $heatmiser->dcb_to_status(@dcb);
        print $heatmiser->status_to_text($status);
    }
}

# That's all folks
exit;


und hier der Output von perl heatmiser.pl :

### heatmiser ###
Heatmiser PRT version 1.7
Thermostat is ON
Time 2015-11-01 14:11:33
Temperature 20.4 deg C (internal)
Calibration offset 65523
Target 20 deg C
Heating is OFF (heating mode)
Feature 01 (01): Temperature format        C
Feature 02 (02): Switching differential  0.5 deg C
Feature 03 (03): Frost protect             1
Feature 04 (04): Frost temperature        16 deg C
Feature 05 (05): Output delay              5 minutes
Feature 06 (10): Comms #                 n/a
Feature 07 (11): Temperature limit         0 deg C
Feature 08 (12): Sensor selection        internal
Feature 09 (13): Floor limit             n/a
Feature 10 (14): Optimum start           disabled hours
Feature 11 (15): Rate of change           20 minutes / deg C
Feature 12 (16): Program mode            5/2 day
Weekday   1: 04:30 20 deg C
          2: 09:00 20 deg C
          3: 17:00 20 deg C
          4: 22:00 19 deg C
Weekend   1: 04:30 20 deg C
          2: 07:30 20 deg C
          3: 22:30 19 deg C


Habt Ihr eine Idee und Vorschlag wie ich dieser Script einfach in FHEM einbinde und mir einige der Outputs in ein Log schreiben lasse um dann eine
Grafische Darstellung zu generieren?

Besten Dank für Eure Hilfe.

Gruß
Olaf

Prof. Dr. Peter Henning

Ja.

1. Perl lernen https://wiki.selfhtml.org/wiki/Perl
2. Quick and Dirty: Den o.a. Code in 99_myUtils.pm übernehmen und in irgendein Device als readings hineinschreiben.
3. Sauber: Eigenes Modul schreiben.

LG

pah

olgo59

Hi,

besten Dank für die Antwort werde ich mal versuchen.
Ein eigenes Modul wäre natürlich am besten, aber ich glaube das bekomme ich so ohne weiteres nicht hin;-(

Aber wenn Du hier auch einen Hinweis für mich hättest ....???

Gruß
Olaf

pejonp

Zitat von: olgo59 am 01 November 2015, 14:15:38
...
ich versuche mein Raumthermostat "Heatmiser Wifi" mit FHEM ab zu fragen, einzustellen und die Werte anzeigen zu lassen.

Hallo Olaf,

kannst du deinen Raumthermostat "Heatmiser Wifi" mit http://ip:port/irgendwas abfragen ? Wenn ja kannst du es mit HTTPMOD versuchen. Ich habe mir gerade die Seite https://github.com/thoukydides/heatmiser-wifi angesehen, dort ist ja einiges beschrieben.
Du könntest auch Versuchen auf die SQL-DB zugreifen und dort die Daten auslesen. Modul ?

Jörg
LaCrossGW 868MHz:WT470+TFA+TX37-IT+EMT7110+W136+WH25A HP1003+WH2621
SignalD(CC1101):Bresser+WS-0101(868MHz WH1080)+Velux KLF200+MAX!+HM-MOD-UART:Smoke HM-SEC-SD+VITOSOLIC 200 RESOL VBUS-LAN+SolarEdge SE5K(Modbus)+Sonnen!eco8(10kWh)+TD3511+DRT710M(Modbus)+ZigBee+Z-Wave+MQTT+vitoconnect

olgo59

Hallo Jörg,

nein über HTTP kann ich zwar konfigurieren und ansehen, aber die Werte bekomme ich nicht gesondert raus ;-(

Das Modul wäre das beste, aber das bekomme ich nicht hin, habe gestern noch versucht über myUtils das ganz zu realisieren, aber da fehlt mir einfach das KnowHow.

Die Datenbankabfrage habe ich auch schon ins Auge gefasst, aber auch das ist mir nicht gelungen ....

Daher baue ich einwenig auf Hilfe ;-)

Danke & Gruß
olaf

Prof. Dr. Peter Henning

Selbstverständlich kann man mit httpmod alle Werte einzeln herausholen - bitte Commandref lesen !

LG

pah

franky08

Warum nimmst du nicht die Quick and Dirty Methode, wie pah geschrieben hat? Den Code hast du ja schon, weise den ausgelesenen Readings skalare Variablen zu (z.B. my $read1 = da kommt das Reading hin, my $read2 = das nächste, usw)
Dann schreibst du mit
fhem "set <device> $read1";
oder als neues Reading mit
fhem "setreading <device> <reading> $read1"; usw.
die ausgelesenen Werte in ein neues fhem device (z.B. ein dummy).
Vorher natürlich das dummy in fhem anlegen! Mit der setreading Version kannst du alle Readings in ein dummy schreiben. Dort hast du dann alle Werte aus deinem ausgelesenen Gerät.

VG
Frank

VG
Frank
Debian Bookworm auf HUNSN / Debian Bullseye auf 2.ter HUNSN F2F an 2x RaspiB
mit FHEM aktuell
22Zoll ViewSonic als Infodislay (WVC)
3xHMLAN mit vccu, raspmatic_rpi3, HMIP-HCU1

pejonp

#7
Zitat von: olgo59 am 02 November 2015, 10:32:14
...
nein über HTTP kann ich zwar konfigurieren und ansehen, aber die Werte bekomme ich nicht gesondert raus ;-(
Hallo Olaf,

was liefert den der http://ip:port/irgendwas Aufruf. Schreib es mal in eine Datei und häng es an.
Hier sind mal ein paar Beispiele wie man etwas selektieren kann:
http://forum.fhem.de/index.php/topic,34404.msg352743.html#msg352743,
http://forum.fhem.de/index.php/topic,10303.msg346301.html#msg346301 (Dateianlage)


pejonp

LaCrossGW 868MHz:WT470+TFA+TX37-IT+EMT7110+W136+WH25A HP1003+WH2621
SignalD(CC1101):Bresser+WS-0101(868MHz WH1080)+Velux KLF200+MAX!+HM-MOD-UART:Smoke HM-SEC-SD+VITOSOLIC 200 RESOL VBUS-LAN+SolarEdge SE5K(Modbus)+Sonnen!eco8(10kWh)+TD3511+DRT710M(Modbus)+ZigBee+Z-Wave+MQTT+vitoconnect

olgo59

Hallo
besten Dank für den Hinweis, ich habe nun mal die Commandref angesehen und einwenig ausprobiert.

Im buf sehe ich:

HTTP/1.1 200 OK Connection: close Content-Type: text/html Cache-Control: no-cache <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Heatmiser Wifi Thermostat</title> <link href="/mywifi.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <meta http-equiv="Content-Language" content="en-gb"> <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"> </head> <script language="javascript"> function awayClick() {   aw = document.FrmChg4; if(aw.actH.value=='1') { aw.actH.value=2; } else { aw.actH.value=1; } aw.submit(); } function summerClick() {   sm = document.fostfm; if(sm.fost.value=='1') { sm.fost.value=2; } else { sm.fost.value=1; } sm.submit(); } function myrefsh() { location.assign(location);   } function myonload() {} </script> <body bgcolor="#B3120C" onload="myonload()" topmargin=0 leftmargin=0 rightmargin=0 style="overflow-x:hidden;overflow-y:auto"> <form name="logfm"> <input type=hidden name="lgst" value="1"> <input type=hidden name="disw" value="none"> <input type=hidden name="modl" value="2"> <input type=hidden name="senor" value="0"> <input type="hidden" name="hldy" value="2"> </form> <script language="javascript"> if(document.logfm.lgst.value != "1") top.location.href="index.htm"; </script> </script> <form name="FrmChg4" method="post"> <input type="hidden" name="actH" value="2"> </form> <form name="fostfm" method="post"> <input type="hidden" name="fost" value="2"> <form> <div id="lb7" ><> <form name='dispFrm'> <table bgcolor="#B3120C" style='text-align:center;' border="0" width=100% height=100% cellspacing=0 cellpadding=0 > <script language="javascript"> var tmp, sntm, hltm; tmp = Number(document.logfm.modl.value); sntm = Number(document.logfm.senor.value); hltm = Number(document.logfm.hldy.value); if(tmp > 1) document.write("<tr><td align=center height=30 colspan=4 ><a href='/statSetup.htm' target='midfm' onfocus='this.blur()' ><b><font color='white' face='arial'>12:10&nbsp;&nbsp;05/11/2015</font></b></a></td></tr>"); else document.write("<tr><td align=center height=30 colspan=4 ><br></td></tr>"); document.write("<tr><td height=30 bgcolor='black' colspan=4></td></tr><td class='p5' colspan=4 ><b>Live View&nbsp;</b><input type='button' value='Refresh' onclick='myrefsh()'></td></tr><tr><td colspan=4 ><br></td></tr>"); if(tmp < 5) {   if(sntm > 1) document.write("<tr><td class='p5'colspan=4><b>Floor&nbsp;:&nbsp;</b><font size='5'>&nbsp;<font face='Arial'>&deg;</font>C</font></td></tr>"); if(sntm!=2) document.write("<tr><td class='p5'colspan=4><b>Actual&nbsp;:&nbsp;</b><font size='5'>20.4&nbsp;<font face='Arial'>&deg;</font>C</font></td></tr>"); document.write("<tr><td class='p5'colspan=4><b>Set&nbsp;:&nbsp;</b><font size='4'>20&nbsp;<font face='Arial'>&deg;</font>C</font></td></tr><tr><td colspan=4 ><br></td></tr><tr><td class='p5'colspan=4><b>Heat Status:</b><font size='4'>OFF&nbsp;<font face='Arial'></td></tr>"); } if(tmp > 3) { if(tmp < 5 ) document.write("<tr><td class='p5'colspan=4><b>Hot Water:</b><font size='4'>&nbsp;<font face='Arial'></td></tr>"); else document.write("<tr><td class='p5'colspan=4><b>Timer :</b><font size='4'>&nbsp;<font face='Arial'></td></tr>"); if(tmp == 6) document.write("<tr><td colspan=4 ><br></td></tr><tr><td class='p5'colspan=4><b>Timer left&nbsp;: 68 &nbsp;h:&nbsp;16&nbsp;min</b></td></tr>"); } if((tmp > 1)&&(tmp < 5)) document.write("<tr><td colspan=4 ><br></td></tr><tr><td class='p5'colspan=4><b>Hold&nbsp;for:&nbsp;0&nbsp;h:&nbsp;00&nbsp;min</b></td></tr>");   document.write("<tr><td colspan=4 ><br></td></tr><tr><td class='p5' colspan=4><b>Occupancy</b></td></tr>"); document.write("<tr><td class='p5'colspan=1 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td class='p5' style='text-decoration:underline;'colspan=1><b>Home</b></td><td class='p5' colspan=1><a onclick=awayClick() style='color:white;' href='#'><b>Away</b></a></td><td class='p5'colspan=1 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"); if(tmp == 4) { if(hltm!=1) { document.write("<tr><tr><td colspan=4 ><br></td></tr><tr><td class='p5' colspan=4><b>Summer</b></td></tr>"); document.write("<tr><td class='p5'colspan=1 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td class='p5' </td><td class='p5' </td><td class='p5'colspan=1 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"); } } </script> </table> </form> </body> </html>


Um hier ersteinmal etwas zu schaffen habe ich mich auf den Actuellen Temp Wert konzentriert, den ich hier:

document.write("<tr><td class='p5'colspan=4><b>Actual&nbsp;:&nbsp;</b><font size='5'>20.4&nbsp;<font face='Arial'>&deg;</font>C</font></td></tr>");

finde.
Leider bin ich mit den Regex nicht wirklich weit gekommen.
Könntest Du mir hier erneut eine Hilfe zukommen lassen?

Danke

Gruß
Olaf

Prof. Dr. Peter Henning

Vielleicht besser erst die Commandref lesen und dann Andere fragen.
Auch das mit den regulären Ausdrücken kann man systematisch lernen und muss nicht schon beim ersten Komma aufgeben.

LG

pah

olgo59

Hallo pah,

na dann besten Dank. Genau diese Information hat mir gefehlt um das Problem zu lösen.

@pejonp: Besten Dank für die Unterstützung, mit Deiner Hilfe habe ich es geschafft und bekomme die Werte auch ausgelesen. !!!DANKE

Gruß
Olaf

Prof. Dr. Peter Henning

Wenn jemand  in seinem vierten Post schreibt, dass er "jetzt mal die Commandref gelesen" habe, ist der Hinweis sicher nicht sinnlos gewesen.

Und zum Thema reguläre Ausdrücke: https://wiki.selfhtml.org/wiki/Perl/Regul%C3%A4re_Ausdr%C3%BCcke

LG

pah