Control Tasmota devices via OXRS touch-panel

This is a sample flow to to control Tasmota devices via the OXRS touch-panel.

It works by mapping the OXRS screen and tile payloads to specific Tasmota device topics, and vice versa. This allows the touch screen to control the Tasmota device and the Tasmota device to update the tile to display ON/OFF state.

[
    {
        "id": "b023a7a132c29f23",
        "type": "function",
        "z": "cc6fe24bc46bf95c",
        "name": "From Tasmota",
        "func": "const mapping = global.get(\"mapping\")\nlet foundButton = null;\nlet screen = 0\nlet tile = 0\n\n// Modify incomming Tasmota topic to match outgoing topic,\n// so we can lookup the button that called it\nlet topic = msg.topic.split(\"/\")\nlet index = \"cmnd/\" + topic[1] + \"/\" + topic[2]\n\n// Reverse lookup oxrs \nfor (const button in mapping) {\n    if (mapping[button] === index) {\n        foundButton = button;\n        break;\n    }\n}\nif (foundButton === null) {\n    node.warn(\"no matching button \" + msg.topic);\n    return\n}\n\nnode.status({ text: foundButton + \" \" + msg.payload });\n\nconst match = foundButton.match(/s(\\d+)t(\\d+)/);\nif (match) {\n    screen = match[1]; // Digits after 's'\n    tile = match[2]; // Digits after 't'\n}\n\n// Build json to send to oxrs\n\nmsg.topic = \"oxrs/cmnd/oxrs1\"\n\nmsg.payload = {\n    \"tiles\": [\n        {\n            \"screen\": screen,\n            \"tile\": tile,\n            \"state\": msg.payload == \"ON\" ? \"on\" : \"off\",  // set tile to match relay state\n            \"subLabel\": \"\"\n        }\n    ]\n}\n\nreturn msg;\n\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 860,
        "y": 480,
        "wires": [
            [
                "3cf8da9c763b3a09"
            ]
        ]
    },
    {
        "id": "3b73da0d42e3d253",
        "type": "mqtt in",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "topic": "stat/+/POWER",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 580,
        "y": 340,
        "wires": [
            [
                "b023a7a132c29f23"
            ]
        ]
    },
    {
        "id": "35d5e4847ecdf1de",
        "type": "mqtt in",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "topic": "stat/+/POWER1",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 580,
        "y": 380,
        "wires": [
            [
                "b023a7a132c29f23"
            ]
        ]
    },
    {
        "id": "bcc95d53af371d2f",
        "type": "mqtt in",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "topic": "stat/+/POWER2",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 580,
        "y": 420,
        "wires": [
            [
                "b023a7a132c29f23"
            ]
        ]
    },
    {
        "id": "95f7aa59cf6910e5",
        "type": "mqtt in",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "topic": "stat/+/POWER3",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 580,
        "y": 460,
        "wires": [
            [
                "b023a7a132c29f23"
            ]
        ]
    },
    {
        "id": "ea28bd3766368e3c",
        "type": "mqtt in",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "topic": "stat/+/POWER4",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 580,
        "y": 500,
        "wires": [
            [
                "b023a7a132c29f23"
            ]
        ]
    },
    {
        "id": "3cf8da9c763b3a09",
        "type": "mqtt out",
        "z": "cc6fe24bc46bf95c",
        "name": "MQTT Out",
        "topic": "",
        "qos": "1",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "",
        "x": 1070,
        "y": 420,
        "wires": []
    },
    {
        "id": "0c36a0e46e91aee7",
        "type": "function",
        "z": "cc6fe24bc46bf95c",
        "name": "To Tasmota",
        "func": "const mapping = global.get(\"mapping\")\n\nlet sxtx = \"s\" + msg.payload.screen + \"t\" + msg.payload.tile\n\nif (mapping[sxtx] != null) {\n    msg.topic = mapping[sxtx]\n    msg.payload = \"toggle\"\n    node.status({text:msg.topic});\n    return msg;\n}\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 850,
        "y": 420,
        "wires": [
            [
                "3cf8da9c763b3a09"
            ]
        ]
    },
    {
        "id": "4ba09dcfb678f8e1",
        "type": "mqtt in",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "topic": "oxrs/stat/oxrs1",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 820,
        "y": 360,
        "wires": [
            [
                "0c36a0e46e91aee7"
            ]
        ]
    },
    {
        "id": "99f21333636e0231",
        "type": "change",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "mapping",
                "pt": "global",
                "to": "{\"s1t2\":\"cmnd/kitchenlights/POWER1\",\"s1t3\":\"cmnd/kitchenlights/POWER2\",\"s2t1\":\"cmnd/socket01/POWER1\",\"s2t2\":\"cmnd/socket01/POWER2\",\"s2t3\":\"cmnd/socket02/POWER1\",\"s2t4\":\"cmnd/socket02/POWER2\"}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 830,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "id": "489bfeed123bee07",
        "type": "inject",
        "z": "cc6fe24bc46bf95c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 580,
        "y": 300,
        "wires": [
            [
                "99f21333636e0231"
            ]
        ]
    }
]
4 Likes

Bugger - my two screens are due to arrive next week and we are going on 4 weeks holiday (overseas) so will not have any time to play with them - getting excited for this though !

Craig

2 Likes