Node-RED Tutorial-Reihe - Part 9: Daten von FHEM per JsonList holen
In einem früheren Video habe ich ja bereits gezeigt, wie man über einen generischen Weg per MQTT die Daten in Node-RED aktualisieren kann. Was wäre aber, wenn man kein MQTT hat oder extra nutzen möchte, und trotzdem Informationen aus FHEM holen will? Dann bietet sich der Weg über ein FHEM-Modul namens JsonList2 an. Dieses liefert die aktuellen Readings und deren Wert im Json-Format aus. In NdeRed lieben wir JSON, da man damit extrem einfach weiter arbeiten kann. Wie genau das geht, zeige ich DIr in diesem Video.
Was wird benötigt?
- Eine Node-RED-Installation
- Eine FHEM-Installation
Video
Beispiel-Flow zum importieren
[
{
"id": "fb6b67f4.d7aee8",
"type": "subflow",
"name": "Von FHEM",
"info": "",
"in": [
{
"x": 60,
"y": 60,
"wires": [
{
"id": "3f754c77.b2f4d4"
}
]
}
],
"out": [
{
"x": 1160,
"y": 40,
"wires": [
{
"id": "a4b7a456.c9ab38",
"port": 0
}
]
},
{
"x": 920,
"y": 140,
"wires": [
{
"id": "1e2f55f6.75270a",
"port": 0
}
]
}
]
},
{
"id": "12b059a2.82d646",
"type": "http request",
"z": "fb6b67f4.d7aee8",
"name": "",
"method": "GET",
"ret": "txt",
"url": "",
"tls": "",
"x": 470,
"y": 60,
"wires": [
[
"925db50c.7dc158"
]
]
},
{
"id": "3f754c77.b2f4d4",
"type": "function",
"z": "fb6b67f4.d7aee8",
"name": "Jsonlist",
"func": "msg.url = 'http://fhem:8083/fhem?cmd=jsonlist2%20' + msg.payload + '&XHR=1';\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 300,
"y": 60,
"wires": [
[
"12b059a2.82d646"
]
]
},
{
"id": "925db50c.7dc158",
"type": "json",
"z": "fb6b67f4.d7aee8",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 610,
"y": 60,
"wires": [
[
"d8ccb083.5b964",
"1e2f55f6.75270a"
]
]
},
{
"id": "d8ccb083.5b964",
"type": "switch",
"z": "fb6b67f4.d7aee8",
"name": "Ergebnisse",
"property": "payload.totalResultsReturned",
"propertyType": "msg",
"rules": [
{
"t": "gte",
"v": "1",
"vt": "num"
},
{
"t": "else"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 770,
"y": 60,
"wires": [
[
"a4b7a456.c9ab38"
],
[
"34783fbd.68f6a"
]
]
},
{
"id": "a4b7a456.c9ab38",
"type": "function",
"z": "fb6b67f4.d7aee8",
"name": "Erstes Element holen",
"func": "msg.payload = msg.payload.Results[0];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1020,
"y": 40,
"wires": [
[]
]
},
{
"id": "1e2f55f6.75270a",
"type": "function",
"z": "fb6b67f4.d7aee8",
"name": "Anzahl Ergebnisse",
"func": "msg.payload = msg.payload.totalResultsReturned;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 790,
"y": 140,
"wires": [
[]
]
},
{
"id": "34783fbd.68f6a",
"type": "function",
"z": "fb6b67f4.d7aee8",
"name": "Fehler, keine Geräte",
"func": "msg.payload = 'Keine Geräte gefunden';\nnode.error(\"Keine Geräte gefunden\", msg);",
"outputs": 1,
"noerr": 0,
"x": 1020,
"y": 80,
"wires": [
[]
]
},
{
"id": "9023e543.753388",
"type": "subflow:fb6b67f4.d7aee8",
"z": "bf5eeb85.d24f28",
"name": "",
"x": 310,
"y": 1500,
"wires": [
[
"dd5a729a.e965"
],
[]
]
}
]