Anfängerfrage Gaszähler mit HttpMod oder JsonMod abfragen

Begonnen von marboj, 27 November 2023, 08:20:50

Vorheriges Thema - Nächstes Thema

marboj

Hallo zusammen,

habe nun endlich eine Möglichkeit gefunden, meinen Gaszähler smart zu machen: https://footprintzero.de/

Habe das Modul am Samstag bekommen und am Gaszähler angeschlossen. In meinem Netz ist es aufrufbar.

Du darfst diesen Dateianhang nicht ansehen.

Du darfst diesen Dateianhang nicht ansehen. 

Versuche nun seit Samstag, dass Ding im Fhem anzulegen, sowohl mit HttpMod als auch mit JsonMod bekomme ich keine Readings angelegt.

Hier die angelegten Geräte:
defmod Gaszaehler HTTPMOD http://192.168.0.124 300
attr Gaszaehler reading01Name Zaehlerstand
attr Gaszaehler reading01Regex Z&auml;;hlerstand</div><br /><br/>([0-9]+) m<sup>3</sup></td></tr></table>
attr Gaszaehler reading02Name VerbrauchHeute
attr Gaszaehler reading02Regex heute.[0-9]+,[0-9]+ kWh.>([0-9]+,[0-9]+).gestern

defmod GaszaehlerJson JsonMod http://192.168.0.124/json
attr GaszaehlerJson interval */15 * * * *
attr GaszaehlerJson readingList complete()



Hier der Logeintrag zu JsonMod:
2023.11.27 08:08:35 4: WEB_192.168.0.20_53824 GET /fhem?cmd=%7BReadingsVal(%22GaszaehlerJson%22%2C%22reread%22%2C%22%22)%7D&XHR=1&fwcsrf=csrf_28971078847475; BUFLEN:0
2023.11.27 08:08:35 5: Cmd: >{ReadingsVal("GaszaehlerJson","reread","")}<
2023.11.27 08:08:35 4: WEB: /fhem?cmd=%7BReadingsVal(%22GaszaehlerJson%22%2C%22reread%22%2C%22%22)%7D&XHR=1&fwcsrf=csrf_28971078847475 / RL:21 / text/plain; charset=UTF-8 / Content-Encoding: gzip

Hier der Logeintrag zu HttpMod:
2023.11.27 08:01:59 5: Cmd: >set Gaszaehler reread<
2023.11.27 08:01:59 5: Gaszaehler: set called with reread
2023.11.27 08:01:59 4: Gaszaehler: GetUpdate called (reread)
2023.11.27 08:01:59 5: Gaszaehler: AddToQueue adds type update to URL http://192.168.0.124, no data, no headers, retry 0, initial queue len: 0
2023.11.27 08:01:59 5: Gaszaehler: HandleSendQueue called from AddToSendQueue, qlen = 1
2023.11.27 08:01:59 4: Gaszaehler: HandleSendQueue sends update with timeout 2 to http://192.168.0.124, No Data, No Header
2023.11.27 08:01:59 5: Gaszaehler: ReadCallback called from HttpUtils_NonblockingGet
2023.11.27 08:01:59 5: Gaszaehler: Read callback Error LogLvl set to 3, regex
2023.11.27 08:01:59 3: Gaszaehler: Read callback: Error: http://192.168.0.124: malformed or unsupported URL
2023.11.27 08:01:59 4: Gaszaehler: Read callback: request type was update retry 0, no headers, no body
2023.11.27 08:01:59 5: Gaszaehler: Read callback: body empty
2023.11.27 08:01:59 4: Gaszaehler: BodyDecode is not decoding the response body (charset not found, bodyDecode defaults to none)
2023.11.27 08:01:59 5: Gaszaehler: GetCookies is looking for Cookies
2023.11.27 08:01:59 5: Gaszaehler: ExtractSid called, context reading, num unknown
2023.11.27 08:01:59 4: Gaszaehler: no header to look for redirects
2023.11.27 08:01:59 5: Gaszaehler: Read callback sets LAST_REQUEST to update
2023.11.27 08:01:59 5: Gaszaehler: CheckAuth decided no authentication required
2023.11.27 08:01:59 5: GET /fhem?detail=Gaszaehler&fw_id= HTTP/1.1
Host: 192.168.0.110:8083

Nach meiner Recherche im Forum oder auch im Wiki müsste da doch was geliefert werden, oder?

Wo ist mein Denkfehler?

Gruß
Marco
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

yersinia

Die Screenshots kann ich nicht öffnen, aber eher geht es um grundsätzliche Fragen:
1. welche API liefert der server? Irgendwie finde ich nichts auf footprintzero, es soll csv Dateien geben, aber die API auch auf MQTT erweitert werden?
2. was ist denn die Ausgabe von
http://192.168.0.124/json?
3. Diesen Blogpost hast du gelesen?
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

marboj

Hallo,

zu 1: folgendes habe ich gefunden: https://footprintzero.de/quickstart/#json


zu 2: die Ausgabe von http://192.168.0.124/json ist:

Content-Type: application/json
{"gesamt": 868370, "aktuell": 0, "heute": 0, "since_last_call": 51, "gestern": 51, "glmw": 0}

zu 3: Danach habe ich es ja angelegt. Nachdem das keine Ergebnisse lieferte, habe ich JsonMod probiert.

Gruß
Marco

meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

betateilchen

2023.11.27 08:01:59 3: Gaszaehler: Read callback: Error: http://192.168.0.124: malformed or unsupported URL
2023.11.27 08:01:59 4: Gaszaehler: Read callback: request type was update retry 0, no headers, no body
2023.11.27 08:01:59 5: Gaszaehler: Read callback: body empty

Da stimmt was mit der URL nicht, die Du aufrufst.

Probier doch mal als einfachsten Ansatz folgendes:

define gas JsonMod http://192.168.0.124/json
attr gas readingList complete()

und danach ein "set gas reread".
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

marboj

Hallo betateilchen,

es werden auch damit keine Readings erstellt.

API_LAST_MSG
http://192.168.0.124/json: empty answer received

Gruß
Marco
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

yersinia

Wenn dies die Rückmeldung ist...
Content-Type: application/json
{"gesamt": 868370, "aktuell": 0, "heute": 0, "since_last_call": 51, "gestern": 51, "glmw": 0}
...dann verschluckt sich JsonMod am
Content-Type: application/json
Ohne die erste Zeile liefert JsonMod ein sauberes Ergebnis mit complete(); zurück:
   READINGS:
     2023-11-27 08:47:21   .computedReadings gestern,gesamt,heute,since_last_call,aktuell,glmw
     2023-11-27 08:47:21   aktuell         0
     2023-11-27 08:47:21   gesamt          868370
     2023-11-27 08:47:21   gestern         51
     2023-11-27 08:47:21   glmw            0
     2023-11-27 08:47:21   heute           0
     2023-11-27 08:47:21   since_last_call 51

Entweder mit HTTPMOD auf das json zugreifen oder schauen, was der Webserver an HTML Code liefert.
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

marboj

Müsste ich dann nicht aber hiermit einen Wert bekommen:

defmod Gaszaehler2 HTTPMOD http://192.168.0.124/json 300
attr Gaszaehler2 get01JSON gesamt
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

yersinia

Bevor du und andere im Dunkeln stochern, schau doch erstmal was HTTPMOD empfängt und setze showBody auf 1. Darüberhinaus musst du wesentlich mehr Infos liefern -  verbose des Deivce auf 5 und Auszug aus dem log.

Eventuell kannst du es aber auch einfacher haben wenn du schon MQTT in FHEM nutzt => https://footprintzero.de/quickstart/#mqtt
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

marboj

MQTT habe ich leider nicht...

hier der Logauszug:

2023.11.27 09:17:45 4: Gaszaehler2: GetUpdate called (update)
2023.11.27 09:17:45 4: Gaszaehler2: UpdateTimer called from GetUpdate with cmd next sets timer to call update function in 300.0 sec at 09:22:45.248, interval 300
2023.11.27 09:17:45 4: Gaszaehler2: HandleSendQueue sends update with timeout 2 to http://192.168.0.124/json, No Data, No Header
2023.11.27 09:17:45 4: Gaszaehler2: Read callback: request type was update retry 0,
header: HTTP/1.0 200 OK, body length 127
2023.11.27 09:17:45 4: Gaszaehler2: BodyDecode is not decoding the response body (charset not found, bodyDecode defaults to none)
2023.11.27 09:17:45 4: Gaszaehler2: error while parsing JSON data: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "Content-Type: applic...") at lib/FHEM/HTTPMOD/Utils.pm line 694.

2023.11.27 09:17:45 3: Gaszaehler2: Content-Type was
2023.11.27 09:17:45 4: Gaszaehler2: checking for redirects, code=200, ignore=0
2023.11.27 09:17:45 4: Gaszaehler2: no redirects to handle
2023.11.27 09:17:45 4: Gaszaehler2: Read response to update didn't match any Reading

Leider sagt mir das nichts.
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

yersinia

Hast du das Attribut showBody auf 1 gesetzt?
Was zeigt das Reading body?
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

marboj

#10
ja, habe ich.

Zeigt den Inhalt der Seite 192.168.0.124/json

Content-Type: application/json
{"gesamt": 868392, "aktuell": 7, "heute": 22, "since_last_call": 1, "gestern": 51, "glmw": 0}
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

betateilchen

Bitte verwende code-Tags für die Formatierung von Daten. Danke.


Da behaupte ich mal, dass da einfach eine inhaltlich falsche Antwort kommt.
Der Content-Type gehört in den Header der response, nicht in den Body.

Deshalb funktionieren sowohl HTTPMOD als auch JsonMod nicht.
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

marboj

Also muss ich den Hersteller informieren, dass die json-Seite nicht korrekt ist?
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II

yersinia

Ich ging davon aus, dass du mit HTTPMOD nach dem Blogpost direkt auf den Webserver gehst:
defmod Gaszaehler HTTPMOD http://192.168.0.124 300
attr Gaszaehler reading01Name Zaehlerstand
attr Gaszaehler reading01Regex Z&auml;;hlerstand</div><br /><br/>([0-9]+) m<sup>3</sup></td></tr></table>
attr Gaszaehler reading02Name VerbrauchHeute
attr Gaszaehler reading02Regex heute.[0-9]+,[0-9]+ kWh.>([0-9]+,[0-9]+).gestern
Nutze erstmal diesen Vorschlag mit showBody.

Darüberhinaus würde ich MQTT versuchen, wenn es der Sensor anbietet.
viele Grüße, yersinia
----
FHEM 6.4 (SVN) on RPi 4B with RasPi OS Bookworm (perl 5.36.0) | FTUI
nanoCUL->2x868(1x ser2net)@tsculfw, 1x433@Sduino | MQTT2 | Tasmota | ESPEasy
VCCU->14xSEC-SCo, 7xCC-RT-DN, 5xLC-Bl1PBU-FM, 3xTC-IT-WM-W-EU, 1xPB-2-WM55, 1xLC-Sw1PBU-FM, 1xES-PMSw1-Pl

marboj

#14
da bleibt das Feld httpbody leer...


Was ist denn für MQTT zu tun? Ich dachte, dass die httpmod-Abfrage für mich als Laien einfacher ist. Verstehe halt nicht, warum es nicht, wie im Blog beschrieben, funktioniert?
meine FHEM-Konfiguration: Raspberry Pi4, BT-Dongle, CUL868, CeeBee II