Feedback TCP Request Send to MQTT

I will process the feedback data from TCP request to MQTT. I send command via terminal and TCP request result as in picture, but in switch "matches regex" no result.

I will take feedback data from TCP Request to send to MQTT (switch on/off)
switch On
zone/878
Level:100
SwitchedLevel:On

switch Off
zone/878
Level:0
SwitchedLevel:Off

thak's

[{"id":"fddf94689565f33f","type":"inject","z":"65926043be73d021","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":120,"wires":[["ce972602ec7da656"]]},{"id":"ce972602ec7da656","type":"change","z":"65926043be73d021","name":"On","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"CommuniqueType\":\"CreateRequest\",\"Header\":{\"Url\":\"/zone/878/commandprocessor\"},\"Body\":{\"Command\":{\"CommandType\":\"GoToSwitchedLevel\",\"SwitchedLevelParameters\":{\"SwitchedLevel\":\"On\"}}}}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":120,"wires":[["e1c9e1c102213bb0"]]},{"id":"e1c9e1c102213bb0","type":"function","z":"65926043be73d021","name":"","func":"msg.payload += \"\\n\"\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":160,"wires":[["5cb5b26f993b7537"]]},{"id":"5e34b1c978df002f","type":"change","z":"65926043be73d021","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"CommuniqueType\":\"CreateRequest\",\"Header\":{\"Url\":\"/zone/878/commandprocessor\"},\"Body\":{\"Command\":{\"CommandType\":\"GoToSwitchedLevel\",\"SwitchedLevelParameters\":{\"SwitchedLevel\":\"Off\"}}}}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":220,"wires":[["e1c9e1c102213bb0"]]},{"id":"5cb5b26f993b7537","type":"tcp request","z":"65926043be73d021","name":"","server":"192.168.16.205","port":"8081","out":"sit","ret":"string","splitc":" ","newline":"","tls":"1cacd90b0ba75079","x":630,"y":160,"wires":[["980de67adccde8b3","f78ef60c4369186d"]]},{"id":"89ee9b844b1ff6ce","type":"inject","z":"65926043be73d021","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":220,"wires":[["5e34b1c978df002f"]]},{"id":"980de67adccde8b3","type":"debug","z":"65926043be73d021","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":80,"wires":[]},{"id":"f78ef60c4369186d","type":"switch","z":"65926043be73d021","name":"","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"{\"CommuniqueType\":\"ReadResponse\",\"Header\":{\"MessageBodyType\":\"MultipleZoneStatus\",\"StatusCode\":\"200 OK\",\"Url\":\"/zone/status\"},\"Body\":{\"ZoneStatuses\":[{\"href\":\"/zone/878/status\",\"Level\":100,\"SwitchedLevel\":\"On\",\"Zone\":{\"href\":\"/zone/878\"},\"StatusAccuracy\":\"Good\"}]}}","vt":"str","case":true},{"t":"regex","v":"{\"CommuniqueType\":\"ReadResponse\",\"Header\":{\"MessageBodyType\":\"MultipleZoneStatus\",\"StatusCode\":\"200 OK\",\"Url\":\"/zone/status\"},\"Body\":{\"ZoneStatuses\":[{\"href\":\"/zone/878/status\",\"Level\":0,\"SwitchedLevel\":\"Off\",\"Zone\":{\"href\":\"/zone/878\"},\"StatusAccuracy\":\"Good\"}]}}","vt":"str","case":true}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":160,"wires":[["4ad07fac030fad21"],["9b86f82a73b2af92"]]},{"id":"4ad07fac030fad21","type":"template","z":"65926043be73d021","name":"On","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{\"CommuniqueType\":\"ReadResponse\",\"Header\":{\"MessageBodyType\":\"MultipleZoneStatus\",\"StatusCode\":\"200 OK\",\"Url\":\"/zone/status\"},\"Body\":{\"ZoneStatuses\":[{\"href\":\"/zone/878/status\",\"Level\":100,\"SwitchedLevel\":\"On\",\"Zone\":{\"href\":\"/zone/878\"},\"StatusAccuracy\":\"Good\"}]}}}} on","output":"str","x":950,"y":120,"wires":[["f75ec532509f601f","d1e9b00051945028"]]},{"id":"9b86f82a73b2af92","type":"template","z":"65926043be73d021","name":"Off","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{\"CommuniqueType\":\"ReadResponse\",\"Header\":{\"MessageBodyType\":\"MultipleZoneStatus\",\"StatusCode\":\"200 OK\",\"Url\":\"/zone/status\"},\"Body\":{\"ZoneStatuses\":[{\"href\":\"/zone/878/status\",\"Level\":0,\"SwitchedLevel\":\"Off\",\"Zone\":{\"href\":\"/zone/878\"},\"StatusAccuracy\":\"Good\"}]}}}} off","output":"str","x":950,"y":200,"wires":[["f75ec532509f601f","d1e9b00051945028"]]},{"id":"f75ec532509f601f","type":"debug","z":"65926043be73d021","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":120,"wires":[]},{"id":"d1e9b00051945028","type":"mqtt out","z":"65926043be73d021","name":"State","topic":"switch/state","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"6876d831.1398f8","x":1150,"y":180,"wires":[]},{"id":"1cacd90b0ba75079","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false,"alpnprotocol":""},{"id":"6876d831.1398f8","type":"mqtt-broker","name":"","broker":"192.168.16.20","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Why not convert the JSON string to an JSON object, then you can use the msg property in the switch node. Add a JSON node after the TCP node.
e.g.

[{"id":"f78ef60c4369186d","type":"switch","z":"bf9e1e33.030598","name":"","property":"payload.Body.ZoneStatuses[0].SwitchedLevel","propertyType":"msg","rules":[{"t":"eq","v":"On","vt":"str"},{"t":"eq","v":"Off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":940,"y":760,"wires":[["9a74d929.400fd8"],["55130476.8246e4"]]},{"id":"85c3ea59.c16598","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":810,"y":760,"wires":[["f78ef60c4369186d"]]},{"id":"9a74d929.400fd8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":720,"wires":[["f75ec532509f601f","d1e9b00051945028"]]},{"id":"55130476.8246e4","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":800,"wires":[["f75ec532509f601f","d1e9b00051945028"]]},{"id":"fddf94689565f33f","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"CommuniqueType\":\"ReadResponse\",\"Header\":{\"MessageBodyType\":\"MultipleZoneStatus\",\"StatusCode\":\"200 OK\",\"Url\":\"/zone/status\"},\"Body\":{\"ZoneStatuses\":[{\"href\":\"/zone/878/status\",\"Level\":100,\"SwitchedLevel\":\"On\",\"Zone\":{\"href\":\"/zone/878\"},\"StatusAccuracy\":\"Good\"}]}}","payloadType":"str","x":690,"y":720,"wires":[["85c3ea59.c16598"]]},{"id":"89ee9b844b1ff6ce","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"CommuniqueType\":\"ReadResponse\",\"Header\":{\"MessageBodyType\":\"MultipleZoneStatus\",\"StatusCode\":\"200 OK\",\"Url\":\"/zone/status\"},\"Body\":{\"ZoneStatuses\":[{\"href\":\"/zone/878/status\",\"Level\":0,\"SwitchedLevel\":\"Off\",\"Zone\":{\"href\":\"/zone/878\"},\"StatusAccuracy\":\"Good\"}]}}","payloadType":"str","x":670,"y":780,"wires":[["85c3ea59.c16598"]]},{"id":"f75ec532509f601f","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1300,"y":720,"wires":[]},{"id":"d1e9b00051945028","type":"mqtt out","z":"bf9e1e33.030598","name":"State","topic":"switch/state","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"6876d831.1398f8","x":1280,"y":780,"wires":[]},{"id":"6876d831.1398f8","type":"mqtt-broker","name":"","broker":"192.168.16.20","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Not sure what your template nodes were/are doing, you may need to explain that a little.

1 Like

so I have lighting control with TCP protocol. what I expect is when manual control either on/off or dimmer the feedback status will be managed by TCP Request and send to MQTT (either status on/off or 0-100%).


Working well...
thanks a lot

above test on/off lighting, next I will try dimmer with status 0-100%.

I have tried dimmer with MQTT send 0 – 100 (example 10).

I can't get feedback rating out of 10 to send MQTT.
image

thanks,

[
    {
        "id": "3b07b2c0ccefe564",
        "type": "mqtt in",
        "z": "741aef4.6e6c91",
        "name": "Set",
        "topic": "lutron/leap/light1/set",
        "qos": "0",
        "datatype": "auto",
        "broker": "6876d831.1398f8",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 560,
        "wires": [
            [
                "8b420a80f3556ef6"
            ]
        ]
    },
    {
        "id": "8b420a80f3556ef6",
        "type": "template",
        "z": "741aef4.6e6c91",
        "name": "Payload",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{\"CommuniqueType\":\"CreateRequest\",\"Header\":{\"Url\":\"/zone/1133/commandprocessor\"},\"Body\":{\"Command\":{\"CommandType\":\"GoToDimmedLevel\",\"DimmedLevelParameters\":{\"Level\":{{payload}}}}}}",
        "output": "json",
        "x": 260,
        "y": 560,
        "wires": [
            [
                "8705507b0567a69d"
            ]
        ]
    },
    {
        "id": "8705507b0567a69d",
        "type": "json",
        "z": "741aef4.6e6c91",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 390,
        "y": 560,
        "wires": [
            [
                "f3927954f16b9f44"
            ]
        ]
    },
    {
        "id": "f3927954f16b9f44",
        "type": "function",
        "z": "741aef4.6e6c91",
        "name": "",
        "func": "msg.payload += \"\\n\"\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 560,
        "wires": [
            [
                "210c3181826b9388"
            ]
        ]
    },
    {
        "id": "210c3181826b9388",
        "type": "tcp request",
        "z": "741aef4.6e6c91",
        "name": "",
        "server": "192.168.16.205",
        "port": "8081",
        "out": "sit",
        "ret": "string",
        "splitc": " ",
        "newline": "",
        "tls": "1cacd90b0ba75079",
        "x": 710,
        "y": 560,
        "wires": [
            [
                "1e5eb0037bc5bf72",
                "8ad6700f12bf437a"
            ]
        ]
    },
    {
        "id": "1e5eb0037bc5bf72",
        "type": "debug",
        "z": "741aef4.6e6c91",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 830,
        "y": 380,
        "wires": []
    },
    {
        "id": "8ad6700f12bf437a",
        "type": "json",
        "z": "741aef4.6e6c91",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 890,
        "y": 560,
        "wires": [
            [
                "f0a62fee65286a99",
                "e459d43e56fab924"
            ]
        ]
    },
    {
        "id": "f0a62fee65286a99",
        "type": "switch",
        "z": "741aef4.6e6c91",
        "name": "Slider",
        "property": "payload.Body.ZoneStatuses[0].Level",
        "propertyType": "msg",
        "rules": [
            {
                "t": "jsonata_exp",
                "v": "$number()",
                "vt": "jsonata"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1030,
        "y": 560,
        "wires": [
            [
                "457fd96da81a6eae"
            ]
        ]
    },
    {
        "id": "e459d43e56fab924",
        "type": "debug",
        "z": "741aef4.6e6c91",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1170,
        "y": 660,
        "wires": []
    },
    {
        "id": "457fd96da81a6eae",
        "type": "change",
        "z": "741aef4.6e6c91",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$number()",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1180,
        "y": 560,
        "wires": [
            [
                "d8ca21a4147bcfba",
                "d5de4c6e11952a9b"
            ]
        ]
    },
    {
        "id": "d8ca21a4147bcfba",
        "type": "mqtt out",
        "z": "741aef4.6e6c91",
        "name": "Stat",
        "topic": "lutron/leap/light1/stat",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "6876d831.1398f8",
        "x": 1370,
        "y": 520,
        "wires": []
    },
    {
        "id": "d5de4c6e11952a9b",
        "type": "debug",
        "z": "741aef4.6e6c91",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1390,
        "y": 600,
        "wires": []
    },
    {
        "id": "6876d831.1398f8",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.16.20",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "1cacd90b0ba75079",
        "type": "tls-config",
        "name": "",
        "cert": "",
        "key": "",
        "ca": "",
        "certname": "",
        "keyname": "",
        "caname": "",
        "servername": "",
        "verifyservercert": false,
        "alpnprotocol": ""
    }
]

$number() is trying to convert an object to a number, so you get error, it is not receiving payload.Body.ZoneStatuses[0].Level as you might think. try is of type then select number if you only want numbers to pass. or is between 0 and 100

working well...
thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.