Homematic Wetterstation mit NodeRed und MongoDB

In einem kleinen Bastelprojekt habe ich mich mit der Anbindung der Homematic Wetterstation an NodeRed beschäftigt um ein Dashboard zu bauen, das alle signifikanten Werte anzeigt. Am Ende habe ich noch eine Schippe draufgelegt und speichere alle Werte einmal pro Minute in einer MongoDB als json-File. Der Plan für das nächste Projekt steht schon. Die Visualisierung der Daten. Aber das kommt dann im nächsten Schritt. Hier könnt Ihr lesen was bisher geschah:

Die Hardware

Um es einfach zu halten war die Überlegung eine vorhandene Hardware zu nehmen. Die erste Überlegung war ein Raspberry Pi. Nachdem dann aber mit NodeRed und MongoDB schon zwei Anwendungen auf dem Plan standen und klar war, daß es wahrscheinlich mehr wird fiel meine Wahl auf die vorhandene QNAP mit der App ContainerStation. Die ist schnell installiert und stellt eine komplette Docker-Umgebung zur Verfügung und ist einfach zu verwalten. Außerdem ist der zusätzliche Stromverbrauch nicht relevant. So habe ich erstmal zwei Container erstellt:

Damit war der erste Schritt gemacht. In ein paar langen Abenden mit viel Testen, so manchen Fehlversuch entstand dann der NodeRed-Flow. An dieser Stelle erkläre ich den einen oder anderen Abschnitt. Wer mehr wissen will darf mich gerne kontaktieren. Den kompletten Quellcode findet Ihr am Ende des Artikels.

 

Zum grundsätzlichen Design

Anhand des oben gezeigten Ausschnitts eine kurze Erklärung was passiert. Der Injektor triggert einmal pro Minute das Auslesen der Daten von der Station. Ganz oben ist noch eine Anzeige von Datum und Zeit mit der Info, daß gerade eine Aktualisierung stattgefunden hat. Darunter seht Ihr ein paar Beispiele. Der Rest der Werte funktioniert sinngemäß genau so.

Temperatur Nordseite ist mein Carport (ein separater Sensor), Temperatur Wetterstation der Sensor in der Wetterstation und Luftfeuchtigkeit kommt ebenfalls aus der Wetterstation. Alle werden vom Injektor minütlich getriggert und geben ihre Werte direkt an das Dashboard aus.

Dazu werden diverse Werte in globalen Variablen gespeichert. Die werden dann später zusammen ausgelesen und an MongoDB gesandt. Die Erklärung wie das funktioniert findet Ihr dann unten.

Noch ein Hinweis: die Darstellung der Windrichtung habe ich hier gefunden.

Die Übergabe an MongoDB

Der Screenshot oben zeigt nun die Übergabe an MongoDB. Getriggert wird der Prozess vom gleichen Injektor, nur mit einer Sekunde Verzögerung weil ich festgestellt habe, daß die Laufzeit der einzelnen Teilprozesse nicht unendlich schnell ist, sondern eben eine Weile braucht. Mit der Sekunde Verzögerung läuft es stabil. Dieser Schritt liest nun alle vorher gespeicherten Werte aus und schiebt sie in den MongoDB-Connector. Den Inhalt von Read global all sieht so aus.

msg.payload= {
    "dataset":      "weather@home",
    "datetime":     new Date().toISOString().replace("Z", ""),
    "speed":        global.get("wind_speed"),
    "degrees":      global.get("wind_degrees"),
    "temperature":  global.get("temperature"),
    "humidity":     global.get("humidity"),
    "rain":         global.get("rain"),
    "sunshine":     global.get("sunshine")
}
return msg;

Zur Erklärung:

  • dataset dient dazu den Datensatz-Typ zu indentifizieren, falls man mal auf die Idee kommt noch weitere Daten in die gleiche MongoDB-Datenbank zu kippen.
  • datetime baut einfach einen lesbaren Timestamp um das aktuelle Datum und die Uhrzeit in den Datensatz zu schreiben. Erbsenzähler werden bemerken, daß es eine Sekunde zu spät ist.
  • Die weiteren Elemente erklären sich selbst.

Die MongoDB-Daten

Schaut man mit MongoDB-Compass nun in die Daten findet man folgendes:

{"_id":{"$oid":"5f26f5c16b2b680018b5737f"},"dataset":"weather@home","datetime":"2020-08-02T17:20:01.981","speed":5.2,"degrees":115,"temperature":25.7,"humidity":53,"rain":21.8}

Die ID wird automatisch generiert. Der Rest erklärt sich wohl selbst. Am 2.8.2020 um 17:20 kam der Wind aus Südost (115°) mit 5,2 km/h. Die Temperatur betrug 25,7°C und die relative Luftfeuchtigkeit 53%. Das mit dem Regen ist so eine Sache. Die Wetterstation kumuliert nur, so daß man am Ende immer im Diagramm nachsehen muss was sich verändert hat. So sieht das am Ende dann aus. Bei Regen sieht man den leichten Knick, da hab ich noch keine Zeit gefunden es schöner darzustellen.

Der MongoDB-Connector

Weil ich eine Weile daran rumgefummelt habe, hier auch noch die Konfiguration des MongoDB-Connectors:

Der Quellcode

Ihr könnt den Quellcode einfach mit Copy-Paste in NodeRed übernehmen. Es wird erst einmal Fehlermeldungen hageln, weil Libraries fehlen. Ihr braucht folgende Nodes:

  • node-red-contrib-ccu : ccu-get-value
  • node-red-contrib-calc : calculator
  • node-red-dashboard
  • node-red-contrib-mongodb2 : mongodb2 in
  • und was ich noch vergessen habe… 
[{"id":"94def7bc.2e58a8","type":"ui_chart","z":"7b4de25e.70997c","name":"Carport","group":"9776c587.104478","order":4,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1240,"y":100,"wires":[[]]},{"id":"b0eb282d.1b4da8","type":"ui_gauge","z":"7b4de25e.70997c","name":"","group":"9776c587.104478","order":3,"width":0,"height":0,"gtype":"gage","title":"Carport","label":"°C","format":"{{value}}","min":"-20","max":"40","colors":["#b3b3b3","#b3b3b3","#b3b3b3"],"seg1":"","seg2":"","x":1240,"y":140,"wires":[]},{"id":"908d8769.e00808","type":"inject","z":"7b4de25e.70997c","name":"","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":100,"wires":[["c28f71ad.942d6","b0e748f0.b98f08","a31a6bb4.0edd28","e5033442.7bfc18","59dd648a.e6c23c","efb9937b.c0717","e471621b.992d5","541cb8b1.914eb8","2b870f94.b5ed5","efab3e71.1ba38","dad422e8.df014","7445881c.7de198"]]},{"id":"fdf93300.3555b","type":"ui_chart","z":"7b4de25e.70997c","name":"Wetterstation","group":"9776c587.104478","order":2,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1250,"y":180,"wires":[[]]},{"id":"f65ad2f8.f2366","type":"ui_gauge","z":"7b4de25e.70997c","name":"","group":"9776c587.104478","order":1,"width":0,"height":0,"gtype":"gage","title":"Wetterstation","label":"°C","format":"{{value}}","min":"-20","max":"40","colors":["#b3b3b3","#b3b3b3","#b3b3b3"],"seg1":"","seg2":"","x":1250,"y":220,"wires":[]},{"id":"ee11ed8d.3f254","type":"ui_chart","z":"7b4de25e.70997c","name":"Luftfeuchtigkeit","group":"b9dd5626.717fb8","order":2,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1260,"y":260,"wires":[[]]},{"id":"44009e30.7acbb","type":"ui_gauge","z":"7b4de25e.70997c","name":"Luftfeuchtigkeit","group":"b9dd5626.717fb8","order":1,"width":0,"height":0,"gtype":"gage","title":"","label":"%rF","format":"{{value}}","min":"0","max":"100","colors":["#b3b3b3","#b3b3b3","#b3b3b3"],"seg1":"","seg2":"","x":1260,"y":300,"wires":[]},{"id":"271a38ba.406138","type":"ui_template","z":"7b4de25e.70997c","group":"17a5813f.47654f","name":"Wind","order":3,"width":4,"height":4,"format":"<!--\npass msg.payload.degrees, msg.payload.speed, msg.payload.speed_unit\n-->\n<script>\n    // Watch the incoming message and convert the degrees to a human readable compass direction\n    (function(scope){\n        scope.$watch('msg', function(msg) {\n            if(typeof(msg) === \"object\"){\n                // Convert the degrees to cardinal directions\n                var deg = msg.payload.degrees;\n                var dirs = [\"N\",\"NNE\",\"NE\",\"ENE\",\"E\",\"ESE\",\"SE\",\"SSE\",\"S\",\"SSW\",\"SW\",\"WSW\",\"W\",\"WNW\",\"NW\",\"NNW\",\"N\"];\n                var idx = Math.round(deg*(dirs.length-1)/360);\n                scope.direction = dirs[idx];\n                \n                \n                // Keep track of the highest speed value, giving it 40 as a rough starting point.\n                // Works okay for MPH and KTS, but KM/H will show purple at a lower speed than the rest\n                scope.max_val = (msg.payload.speed > scope.max_val ? msg.payload.speed : 40);\n                \n                scope.p_speed = msg.payload.speed;\n                scope.p_max_val = scope.max_val;\n                var low_colors = [\n                    '#FFFFFF', // white\n                    '#d6f7ff', // light blue\n                    '#85ffd2', // blue green\n                    '#61ff6e' // green 10mph\n                    ];\n                var high_colors = [\n                    '#61ff6e', // green 10mph\n                    '#d5ff61', // green yellow\n                    '#fffc61', // yellow\n                    '#ffe561', // yellow orange 20mph\n                    '#ffcd61', // orange\n                    '#ffad61', // orange red\n                    '#ff7661', // red\n                    '#ff61dd', // red purple\n                    '#e261ff' // purple\n                ];\n                \n                if(msg.payload.speed <= 10){\n                    scope.color = low_colors[Math.round(msg.payload.speed*(low_colors.length-1)/10)];\n                }else{\n                    scope.color = high_colors[Math.round(msg.payload.speed*(high_colors.length-1) / scope.max_val)];\n                }\n                \n                //$(\".compass_container\").css(\"background-color\",scope.color);\n            }\n    \t});\n    })(scope);\n    \n    // Hacks to improve the layout and make it scale\n    $(document).ready(function(){\n        setTimeout(function () {\n            // Remove the auto scrolling from the parent node\n            $(\".compass_container\").parent().css(\"overflow\",\"hidden\");\n        \n            // Adjust the color to match the theme base color by looking up the toolbar header background color;\n            $(\".compass_container .triangle\").css(\"border-bottom-color\",$(\"md-toolbar\").css(\"background-color\"));\n        \n            // Scale the compass into the box that it's being rendered in\n            // This CSS hack helps make sure the line & font size scales appropriately\n            // Based on the node's grid size\n            $(\".compass_container\").each(function(k,v){\n                var scaleWidth = $(v).parent().width() / $(v).width();\n                var scaleHeight = $(v).parent().height() / $(v).height();\n        \n                var translateX = ($(v).width() - $(v).parent().width()) / 2;\n                var translateY = ($(v).height() - $(v).parent().height()) / 2;\n        \n                $(v).css(\"transform\",\"translate(-\"+translateX+\"px,-\"+translateY+\"px) scale(\"+scaleWidth+\",\"+scaleHeight+\") \");\n            });\n            \n            $(\".compass_container\").css(\"display\",\"block\"); // Unhide it now that it's resized\n        }, 1000);\n    });\n</script>\n<style>\n     @import url(https://fonts.googleapis.com/css?family=Dosis:200,400,500,600);\n     \n     .compass_container{\n        transition: 1s ease-in-out;\n        position: relative;\n        display: none;\n        width: 500px;\n        height: 500px;\n        border-radius: 100%;\n        font-family: 'Dosis';\n        font-size: 80px;\n        box-shadow: inset 0px 0px 0px 30px #777; \n        background-color: {{color}};\n     }\n     \n     .compass_container .compass_header{\n        font-weight: bold;\n        position: absolute;\n        text-align: center;\n        width: 100%;\n        font-size: 75%;\n        top: -15px\n     }\n     .compass_container .text_container{\n        height: 100%;\n        width: 100%;\n        padding: 0px;\n        display: block;\n        border-radius: 100%;\n        display: flex;\n        flex-direction: column;\n        justify-content: center;\n        align-items: center;\n     }\n     \n     .compass_container .arrow{\n        transition: 1s ease-in-out;\n        width: 100%;\n        height: 100%;\n        display: block;\n        position: absolute;\n        top: 0;\n     }\n     \n     .compass_container .arrow .triangle{\n        width: 0;\n\t\theight: 0;\n\t\tborder-left: 45px solid transparent;\n\t\tborder-right: 45px solid transparent;\n\t\tborder-bottom: 90px solid black;\n\t\tposition: absolute;\n\t\ttop: -15px;\n\t\tleft: 50%;\n\t\tmargin-left: -45px;\n\t\tz-index: 99;\n     }\n</style>\n\n<div class=\"compass_container\" style=\"\">\n    <div class=\"compass_header\">N</div>\n  \n    <div class=\"nr-dashboard-text text_container\">\n    \n        <div class=\"direction\" style=\"font-size: 120%\">{{direction}}</div>\n        <div style=\"flex-direction: row; font-weight: bold;\">\n            <span style=\"font-size: 100%\">{{msg.payload.speed}}</span>\n            <span style=\"font-size: 75%\">{{msg.payload.speed_unit}}</span>\n        </div>\n    </div>\n    <div class=\"arrow\" style=\"transform: rotate({{msg.payload.degrees}}deg);\">\n      <div class=\"triangle\"></div>\n    </div>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":1230,"y":620,"wires":[[]]},{"id":"b37a73b4.30a2b","type":"ui_chart","z":"7b4de25e.70997c","name":"Regen","group":"31df2a88.c71916","order":2,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1230,"y":700,"wires":[[]]},{"id":"22c131f5.6262de","type":"ui_gauge","z":"7b4de25e.70997c","name":"Regen","group":"31df2a88.c71916","order":1,"width":0,"height":0,"gtype":"gage","title":"","label":"mm","format":"{{value}}","min":"0","max":"100","colors":["#b3b3b3","#b3b3b3","#b3b3b3"],"seg1":"","seg2":"","x":1230,"y":740,"wires":[]},{"id":"c28f71ad.942d6","type":"change","z":"7b4de25e.70997c","name":"Aktuelle Zeit","rules":[{"t":"set","p":"payload","pt":"msg","to":"$now()","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":40,"wires":[["3f7f7270.76744e"]]},{"id":"3f7f7270.76744e","type":"ui_toast","z":"7b4de25e.70997c","position":"top right","displayTime":"5","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"Daten Wetterstation werden aktualisiert","name":"Info Aktualisierung","x":1270,"y":40,"wires":[]},{"id":"7d1a9f89.e5aec","type":"ui_chart","z":"7b4de25e.70997c","name":"","group":"17a5813f.47654f","order":6,"width":0,"height":0,"label":"Geschwindigkeit","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1260,"y":520,"wires":[[]]},{"id":"9e76976c.0fb0a8","type":"ui_chart","z":"7b4de25e.70997c","name":"","group":"17a5813f.47654f","order":6,"width":0,"height":0,"label":"Richtung","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"360","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1240,"y":380,"wires":[[]]},{"id":"60804d97.4c2a34","type":"ui_chart","z":"7b4de25e.70997c","name":"","group":"17a5813f.47654f","order":6,"width":0,"height":0,"label":"Schwankungsbreite","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1270,"y":460,"wires":[[]]},{"id":"c5926040.007b","type":"calculator","z":"7b4de25e.70997c","name":"in Stunden","inputMsgField":"payload","outputMsgField":"payload","operation":"div","constant":"60","x":710,"y":900,"wires":[["c57f58eb.f3c358"]]},{"id":"cd474a9c.6d2728","type":"function","z":"7b4de25e.70997c","name":"Save global wind speed","func":"global.set(\"wind_speed\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":560,"wires":[[]]},{"id":"1288c4a5.c6470b","type":"function","z":"7b4de25e.70997c","name":"Save global wind degrees","func":"global.set(\"wind_degrees\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":420,"wires":[[]]},{"id":"8652e4db.3a1488","type":"function","z":"7b4de25e.70997c","name":"Read global","func":"msg.payload= {\n    \"speed\":  global.get(\"wind_speed\", msg.payload),\n    \"speed_unit\":  \"km/h\",\n    \"degrees\": global.get(\"wind_degrees\", msg.payload)\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":620,"wires":[["271a38ba.406138"]]},{"id":"b0e748f0.b98f08","type":"delay","z":"7b4de25e.70997c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":620,"wires":[["8652e4db.3a1488"]]},{"id":"ab919d.84691e6","type":"ui_text","z":"7b4de25e.70997c","group":"17a5813f.47654f","order":4,"width":0,"height":0,"name":"","label":"Richtung","format":"{{msg.payload}}°","layout":"row-center","x":1240,"y":420,"wires":[]},{"id":"d813c6d.3ec8738","type":"mongodb2 in","z":"7b4de25e.70997c","service":"_ext_","configNode":"ded7e336.d1b6a","name":"","collection":"weather","operation":"insert","x":1290,"y":980,"wires":[[]]},{"id":"a31a6bb4.0edd28","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Regen","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"RAINING","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":450,"y":820,"wires":[["48328040.21b36"]]},{"id":"48328040.21b36","type":"ui_led","z":"7b4de25e.70997c","group":"31df2a88.c71916","order":3,"width":"0","height":"0","label":"Aktuell Regen","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"name":"Regen ja/nein","x":1260,"y":820,"wires":[]},{"id":"e5033442.7bfc18","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Windgeschwindigkeit","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"WIND_SPEED","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":500,"y":520,"wires":[["cd474a9c.6d2728","7d1a9f89.e5aec"]]},{"id":"59dd648a.e6c23c","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Windrichtung","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"WIND_DIR","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":470,"y":380,"wires":[["1288c4a5.c6470b","9e76976c.0fb0a8","ab919d.84691e6"]]},{"id":"efb9937b.c0717","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Luftfeuchtigkeit","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"HUMIDITY","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":480,"y":240,"wires":[["ee11ed8d.3f254","44009e30.7acbb","103262c6.617a1d"]]},{"id":"e471621b.992d5","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Temperatur Nordseite","ccuConfig":"2a777c1f.56a194","iface":"BidCos-RF","channel":"MEQ0281105:1 HM-WDS30-T-O MEQ0281105:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"TEMPERATURE","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":500,"y":120,"wires":[["94def7bc.2e58a8","b0eb282d.1b4da8"]]},{"id":"541cb8b1.914eb8","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Temperatur Wetterstation","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"ACTUAL_TEMPERATURE","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":510,"y":180,"wires":[["fdf93300.3555b","f65ad2f8.f2366","43ea39b8.382548"]]},{"id":"2b870f94.b5ed5","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Regenzähler","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"RAIN_COUNTER","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":470,"y":680,"wires":[["b37a73b4.30a2b","22c131f5.6262de","cf243cac.b0688"]]},{"id":"efab3e71.1ba38","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Schwankungsbreite","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"WIND_DIR_RANGE","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":490,"y":460,"wires":[["60804d97.4c2a34"]]},{"id":"dad422e8.df014","type":"ccu-get-value","z":"7b4de25e.70997c","name":"Sonnenscheindauer","ccuConfig":"2a777c1f.56a194","iface":"HmIP-RF","channel":"00185BE98B4117:1 HmIP-SWO-PR 00185BE98B4117:1","sysvar":"Alarmmeldungen","sysvarProperty":"value","datapoint":"SUNSHINEDURATION","datapointProperty":"value","setProp":"payload","setPropType":"msg","x":500,"y":900,"wires":[["c5926040.007b"]]},{"id":"cf243cac.b0688","type":"function","z":"7b4de25e.70997c","name":"Save global rain","func":"global.set(\"rain\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":740,"wires":[[]]},{"id":"103262c6.617a1d","type":"function","z":"7b4de25e.70997c","name":"Save global humidity","func":"global.set(\"humidity\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":760,"y":300,"wires":[[]]},{"id":"43ea39b8.382548","type":"function","z":"7b4de25e.70997c","name":"Save global temperature","func":"global.set(\"temperature\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":220,"wires":[[]]},{"id":"b3049ac4.c1d6a8","type":"function","z":"7b4de25e.70997c","name":"Read global all","func":"msg.payload= {\n    \"dataset\":      \"weather@home\",\n    \"datetime\":     new Date().toISOString().replace(\"Z\", \"\"),\n    \"speed\":        global.get(\"wind_speed\"),\n    \"degrees\":      global.get(\"wind_degrees\"),\n    \"temperature\":  global.get(\"temperature\"),\n    \"humidity\":     global.get(\"humidity\"),\n    \"rain\":         global.get(\"rain\"),\n    \"sunshine\":     global.get(\"sunshine\")\n}\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":700,"y":980,"wires":[["d813c6d.3ec8738"]]},{"id":"7445881c.7de198","type":"delay","z":"7b4de25e.70997c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":980,"wires":[["b3049ac4.c1d6a8"]]},{"id":"f752ea37.3ace28","type":"ui_chart","z":"7b4de25e.70997c","name":"Sonnenschein","group":"a5a9324f.1293c","order":2,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1260,"y":880,"wires":[[]]},{"id":"95750765.2c75e8","type":"ui_gauge","z":"7b4de25e.70997c","name":"Sonnenschein","group":"a5a9324f.1293c","order":1,"width":0,"height":0,"gtype":"gage","title":"","label":"Stunden","format":"{{value}}","min":"0","max":"100","colors":["#b3b3b3","#b3b3b3","#b3b3b3"],"seg1":"","seg2":"","x":1260,"y":920,"wires":[]},{"id":"c57f58eb.f3c358","type":"function","z":"7b4de25e.70997c","name":"Save global sunshine","func":"global.set(\"sunshine\", msg.payload-global.get(\"sunshine_midnight\"))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":900,"wires":[["f752ea37.3ace28","95750765.2c75e8"]]},{"id":"9776c587.104478","type":"ui_group","z":"","name":"Temperatur","tab":"8f4b65b7.2c4c98","order":2,"disp":true,"width":"6","collapse":false},{"id":"b9dd5626.717fb8","type":"ui_group","z":"","name":"Luftfeuchtigkeit","tab":"8f4b65b7.2c4c98","order":2,"disp":true,"width":"6","collapse":false},{"id":"17a5813f.47654f","type":"ui_group","z":"","name":"Wind","tab":"8f4b65b7.2c4c98","order":4,"disp":true,"width":"6","collapse":false},{"id":"31df2a88.c71916","type":"ui_group","z":"","name":"Regen","tab":"8f4b65b7.2c4c98","order":5,"disp":true,"width":"6","collapse":false},{"id":"ded7e336.d1b6a","type":"mongodb2","z":"","uri":"mongodb://192.168.178.18:27017/mjr_demo","name":"MongoDB","options":"","parallelism":""},{"id":"2a777c1f.56a194","type":"ccu-connection","z":"","name":"192.168.178.11","host":"192.168.178.11","regaEnabled":true,"bcrfEnabled":true,"iprfEnabled":true,"virtEnabled":true,"bcwiEnabled":false,"cuxdEnabled":false,"regaPoll":true,"regaInterval":"30","rpcPingTimeout":"60","rpcInitAddress":"","rpcServerHost":"192.168.178.16","rpcBinPort":"2089","rpcXmlPort":"2090","queueTimeout":"5000","queuePause":"250","contextStore":"memory"},{"id":"a5a9324f.1293c","type":"ui_group","z":"","name":"Sonnenschein","tab":"8f4b65b7.2c4c98","order":5,"disp":true,"width":"6","collapse":false},{"id":"8f4b65b7.2c4c98","type":"ui_tab","z":"","name":"Wetter@home","icon":"wi-wu-mostlysunny","order":1,"disabled":false,"hidden":false}]

Dieser Artikel ist ohne jegliche Garantie. Professionelle IT-Unterstützung finden Sie bei der MJR GmbH.

MJR GmbH, Knittlingen
Für professionelle Unterstützung besuchen Sie bitte https://mjr.gmbh

2 Gedanken zu „Homematic Wetterstation mit NodeRed und MongoDB

  1. Malte Antworten

    Hallo Michael,

    super Projekt, ein ähnliches versuche ich auch gerade aufzusetzen. Ich möchte gerne über Node-RED auf die Regenmenge der Wetterstation Pro zugreifen und zeitlich speichern um auch einen Tages- / Wochen- / Monatsverlauf mir aufbauen zu können. Leider komme ich aber mit dem Zugriff auf die Regenmenge nicht weiter, da der Counter scheinbar nicht so funktioniert wie ich dachte. Hast du da eine Lösung für?

    Beste Grüße,

    Malte

  2. Michael Raber Autor des BeitragsAntworten

    Guten Morgen Malte,

    ich habe leider keinen Zugriff mehr auf die Wetterstation. Steht bei meiner Ex-Frau hinter meinem Ex-Haus. 😉 

    Aber soweit ich mich erinnern kann ist der Regenzähler einfach kumuliert. Das heißt er zeigt nicht den Regen pro Stunde oder Tag oder so an, sondern summier einfach. Jetzt mal aus dem Kopf und in der Theorie:

    Nimm einen Inject-Node, der z. B. einmal pro Stunde (oder wie Du es möchtest) den Wert ausliest und in eine Context-Variable (https://nodered.org/docs/user-guide/context) schreibt. 
    Der gleiche Inject kann auch das berechnen der Regenmenge im letzten Zeitintervall triggern, indem er den aktuellen Wert und den gespeicherten Wert subtrahiert.
    Irgendwann schlägt der Wert über, also quasi ein Überlauf. Da musst Du Dir eine passende Funktion schreiben, die dann noch korrekt rechnet, oder Du ignorierst den Fehler einfach. Passiert ja nicht so oft.

    Ich hoffe es hilft Dir weiter. Ansonsten einfach nochmal schreiben.

    Grüße
    Michael

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert