Skip to content

Instantly share code, notes, and snippets.

@qsolutionsde
Created March 2, 2018 22:18
Show Gist options
  • Save qsolutionsde/22a99002b04c29e97bb2ad09764d2dce to your computer and use it in GitHub Desktop.
Save qsolutionsde/22a99002b04c29e97bb2ad09764d2dce to your computer and use it in GitHub Desktop.
FHEM event processing via Telnet (inform)

The flow connects to an FHEM instance via Telnet (change the IP address in the incoming TCP node) and listens to all events. It parses events into device, reading and value.

[
{
"id": "dca33d8.38ff4c",
"type": "tcp out",
"z": "379029c6.41a1f6",
"host": "",
"port": "",
"beserver": "reply",
"base64": false,
"end": false,
"name": "reply",
"x": 830,
"y": 200,
"wires": []
},
{
"id": "756957c2.573038",
"type": "tcp in",
"z": "379029c6.41a1f6",
"name": "FHEM",
"server": "client",
"host": "192.168.1.1",
"port": "7072",
"datamode": "stream",
"datatype": "utf8",
"newline": "\\n",
"topic": "fhem",
"base64": false,
"x": 190,
"y": 200,
"wires": [
[
"27c79c99.9276b4",
"aa51ec2a.5d5cd"
]
]
},
{
"id": "f3779ae5.6a2498",
"type": "template",
"z": "379029c6.41a1f6",
"name": "+ newline",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "inform on\n",
"x": 662,
"y": 82,
"wires": [
[
"dca33d8.38ff4c"
]
]
},
{
"id": "27c79c99.9276b4",
"type": "template",
"z": "379029c6.41a1f6",
"name": "no msg back",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "",
"x": 510,
"y": 200,
"wires": [
[
"dca33d8.38ff4c"
]
]
},
{
"id": "b34730fc.7a247",
"type": "status",
"z": "379029c6.41a1f6",
"name": "on status",
"scope": [
"756957c2.573038"
],
"x": 160,
"y": 90,
"wires": [
[
"92b575a3.467ae8"
]
]
},
{
"id": "92b575a3.467ae8",
"type": "switch",
"z": "379029c6.41a1f6",
"name": "",
"property": "status.text",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "common.status.connected",
"vt": "str"
},
{
"t": "eq",
"v": "common.status.disconnected",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 304,
"y": 90,
"wires": [
[
"f3779ae5.6a2498"
],
[
"1d7a0b18.82c475"
]
]
},
{
"id": "aa51ec2a.5d5cd",
"type": "function",
"z": "379029c6.41a1f6",
"name": "parseFHEMInform",
"func": "var i1 = msg.payload.indexOf(' ');\nvar i2 = msg.payload.indexOf(' ', i1+1);\n\nmsg.deviceType = msg.payload.substring(0,i1);\nmsg.device = msg.payload.substring(i1+1,i2);\nmsg.event = msg.payload.substring(i2+1);\n\nvar i3 = msg.event.indexOf(': ');\n\nif (i3 > 0)\n{\n msg.reading = msg.event.substring(0,i3);\n msg.value = msg.event.substring(i3+2);\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 280,
"wires": [
[
"65727cc.f4e8584",
"52c1a183.ce97f"
]
]
},
{
"id": "52c1a183.ce97f",
"type": "debug",
"z": "379029c6.41a1f6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 510,
"y": 320,
"wires": []
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment