Hauptmenü

Node-Red als Frontend

Begonnen von Master_Nick, 26 Oktober 2017, 13:07:28

Vorheriges Thema - Nächstes Thema

SamNitro

Freut mich wenn ich helfen konnte :)

LG Patrick
(Intel-Nuc Proxmox) (Homematic) (EnOcean) (CUL868) (CUL433) (Zigbee2MQTT) (ESP8266) (Echo) (DUOFERN)

pattex

Ich bin bei der Suche nach einer Anbindung von node-red an fhem über diesen alten Thread gestolpert. Ich möchte auch grundsätzlich bei FHEM bleiben vermisse aber eine "schöne" Oberfläche für Logik in meinem Smart Home.
Ich fand die hier im Thread erwähnten Möglichkeiten die Beiden zu verbinden zwar machbar aber nicht einfach genug für den nicht versierten Anwender.

Ich habe nun ein npm Paket (node-red-contrib-fhem) für node-red erstellt, welches die rudimentäre Funktionalität bereitstellt. Hier werde ich in nächster Zeit weiter dran arbeiten. Sollte jemand Interesse haben und Input geben wollen, nur her damit.

Master_Nick

#122
Das klingt interessant - frühstückt das dann MQTT mit ab? @pattex

Hast du nen Link zum Github?
Rancher K8s Cluster mit nanoCUL (a-culfw) | IObroker | IT(V1&V3), IT-PIR, THGR122NX |Co² | alexa-fhem | WOL | NFC | Harmony UltimateHub | Anwesenheitserkennnung | Roomba | 10" Touch mit Node-Red | SonOff S20 | SonOff Touch | SonOff Dual | Rolladen | Und ganz viel anderes tolles Gerödel.... ;-)

mwuerr

#123
Ich nutze Node Red in Verbindung mit FHEM. Angebunden über MQTT (MQTT2Client).
Passend zu dem Thema FHEM zu Node-red über MQTT habe ich etwas geschrieben zum parsen von readings die Wertlisten beinhalten.

Beispiel: 00_THZ.pm device THZ (THZ gerät) erzeugt Readings im Format:
Reading: "sDHW"
Wert : "dhwTemp: 43.8 outsideTemp: 0.8 dhwSetTemp: 45 compBlockTime: 0 out: 0008 heatBlockTime: 0 dhwBoosterStage: 0 pasteurisationMode: 0 dhwOpMode: normal x36: FAA7"

Das ist schon fast JSON. Leider nicht ganz.

Lösung in Node Red:

Du darfst diesen Dateianhang nicht ansehen.

export des flows:
[{"id":"a8f61be078978f20","type":"mqtt in","z":"292283190412ad7e","name":"","topic":"/FhemAtRaspiHeizung2/GGTechnik/Mythz/sDHW","qos":"2","datatype":"utf8","broker":"7aa8da9.1a0f224","nl":false,"rap":false,"inputs":0,"x":210,"y":280,"wires":[["917d50f30d06acab"]]},{"id":"14f0cff4d9ef2f81","type":"json","z":"292283190412ad7e","name":"","property":"payload","action":"obj","pretty":false,"x":790,"y":280,"wires":[["9130f38cb4da1220","874f2f4551a4b413","32d30c519ced2b17","be6d1921b5ac47ed"]]},{"id":"9130f38cb4da1220","type":"debug","z":"292283190412ad7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":970,"y":420,"wires":[]},{"id":"874f2f4551a4b413","type":"debug","z":"292283190412ad7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.dhwTemp","targetType":"msg","statusVal":"payload.dhwTemp","statusType":"auto","x":1020,"y":220,"wires":[]},{"id":"32d30c519ced2b17","type":"debug","z":"292283190412ad7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.dhwSetTemp","targetType":"msg","statusVal":"payload.dhwTemp","statusType":"auto","x":1040,"y":360,"wires":[]},{"id":"917d50f30d06acab","type":"function","z":"292283190412ad7e","name":"convert key values to json","func":"//Takes data in the format\n//key: value key: value key: value \n//and converts it to json\n//{ \"key\": \"value\", \"key\": \"value\", \"key\": \"value\" }\nvar isKey = true;\nvar keys = 0;\nvar values = 0;\n\nvar resultJson = \"\\{\";\nfor (var element of msg.payload.split(\" \")) \n{\n    if(isKey) {\n        if(values > 0) {\n            //for seccond pair and any further\n            resultJson = resultJson.concat(\",\");\n        }\n        \n        //remove : from end of key\n        //add newline, \" and : to key\n        resultJson = resultJson.concat(\n            \"\\n\\\"\",\n            element.substring(0,element.length-1),\n            \"\\\"\",\n            \": \");\n        keys++;\n    }else{\n        //value, add value, in \"\n        resultJson = resultJson.concat(\n            \"\\\"\", element, \"\\\"\\n\");\n        values++;\n    }\n    \n    isKey = !isKey;\n}\n//close json\nresultJson = resultJson.concat(\"\\n\\}\");\n\nmsg.payload = resultJson;\n\nnode.status(keys + \" keys \" + values + \" values\");\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":280,"wires":[["14f0cff4d9ef2f81","e4176194255a01e5"]]},{"id":"e4176194255a01e5","type":"debug","z":"292283190412ad7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":500,"wires":[]},{"id":"bf84a0bca868b781","type":"inject","z":"292283190412ad7e","name":"testen mit sDHW","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"dhwTemp: 44.1 outsideTemp: 0.7 dhwSetTemp: 45 compBlockTime: 0 out: 6008 heatBlockTime: 0 dhwBoosterStage: 0 pasteurisationMode: 0 dhwOpMode: normal x36: FA8E","payloadType":"str","x":360,"y":360,"wires":[["917d50f30d06acab"]]},{"id":"7aa8da9.1a0f224","type":"mqtt-broker","name":"raspberrypi-HeizungMqttBroker","broker":"192.168.188.106","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
vielleicht hilft es ja jemandem. Oder jemand sieht das hier und sagt "so ein quatsch, das geht einfacher".
FHEM auf Raspi 3B, FHEM THZ module, THZ 504, sFirmware: version: 07.59, sFirmware-Id: HW: 239 SW: 4.16 Date: NOV  7 2022