flic / node-red-contrib-hal2

A set of nodes to help with basic home automation logic
2 stars 1 forks source link

Egress not working #31

Closed alexsahka closed 1 year ago

alexsahka commented 1 year ago

I modified your example (added inject input to change the relay state)

But nothing coming out of the hal2Thing node, what is wrong?

image

[ { "id": "271cde287e3f7233", "type": "hal2Thing", "z": "12c0857ff1958a83", "eventHandler": "e228014191d14be6", "thingType": "ff3452746b32087f", "name": "Example Relay", "attributes": [], "topicFilter": "shellies/example-relay/#", "topicFilterType": "mqtt", "topicPrefix": "shellies/example-relay", "notes": "Shelly 2.5 Double Relay", "outputs": "1", "x": 720, "y": 1880, "wires": [ [ "427440a37faa39b1" ] ] }, { "id": "8f8717d36bd85d2b", "type": "comment", "z": "12c0857ff1958a83", "name": "Example relay and dimmer", "info": "", "x": 330, "y": 1840, "wires": [] }, { "id": "a4e7f9bb5bce2dc3", "type": "inject", "z": "12c0857ff1958a83", "name": "Init", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payloadType": "date", "x": 290, "y": 1880, "wires": [ [ "aa65cf82014e0709" ] ] }, { "id": "aa65cf82014e0709", "type": "function", "z": "12c0857ff1958a83", "name": "Emulate values from MQTT", "func": "// Emulate values\nlet relay0 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/0\"\n}\nlet power0 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/0/power\"\n}\nlet relay1 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/1\"\n}\nlet power1 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/1/power\"\n}\nlet temperature = {\n payload: 58,\n topic: \"shellies/example-relay/temperature\"\n}\nlet online = {\n payload: \"true\",\n topic: \"shellies/example-relay/online\"\n}\n\nreturn [[relay0,relay1,power0,power1,temperature,online]];\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 480, "y": 1880, "wires": [ [ "271cde287e3f7233" ] ] }, { "id": "427440a37faa39b1", "type": "debug", "z": "12c0857ff1958a83", "name": "Emulate publishing message to MQTT", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1050, "y": 1900, "wires": [] }, { "id": "9353a79d83574a4b", "type": "inject", "z": "12c0857ff1958a83", "name": "Init", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payloadType": "date", "x": 290, "y": 1920, "wires": [ [ "b1ae4081cedc696d" ] ] }, { "id": "b1ae4081cedc696d", "type": "function", "z": "12c0857ff1958a83", "name": "Emulate values from MQTT", "func": "// Emulate values\nlet relay0 = {\n payload: \"on\",\n topic: \"shellies/example-relay/relay/0\"\n}\nlet power0 = {\n payload: 1,\n topic: \"shellies/example-relay/relay/0/power\"\n}\nlet relay1 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/1\"\n}\nlet power1 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/1/power\"\n}\nlet temperature = {\n payload: 58,\n topic: \"shellies/example-relay/temperature\"\n}\nlet online = {\n payload: \"true\",\n topic: \"shellies/example-relay/online\"\n}\n\nreturn [[relay0,relay1,power0,power1,temperature,online]];\n", "outputs": 1, "noerr": 0, "initialize":"", "finalize": "", "libs": [], "x": 480, "y": 1920, "wires": [ [ "271cde287e3f7233" ] ] }, { "id": "e228014191d14be6", "type": "hal2EventHandler", "name": "Event handler", "maxlisteners": "50", "heartbeat": "10" }, { "id": "ff3452746b32087f", "type": "hal2ThingType", "name": "Shelly Relay", "contextStore": "filesystem", "nodestatus": "💡 [0] %Relay0% (%Power0%w)💡 [1] %Relay1% (%Power1%w) 🌡 %Temperature%°C", "nodestatusType": "str", "statusFn": "// item & attribute objects are\n// passed to function as objects\n\nreturn '';", "items": [ { "name": "Relay0", "id": "45880dc6.a24df4", "topicFilterType": "str", "topicFilterValue": "./relay/0", "topicSuffix": "./relay/0/command", "type": "both", "ingress": "aaf12047.8d497", "egress": "b0499ab0.270728", "notes": "", "output": "1" }, { "name": "Relay1", "id": "4d304056.9c77b", "topicFilterType": "str", "topicFilterValue": "./relay/1", "topicSuffix": "./relay/1/command", "type": "both", "ingress": "aaf12047.8d497", "egress": "b0499ab0.270728", "notes": "", "output": "1" }, { "name": "Power0", "id": "279e85eb.c15aaa", "topicFilterType": "str", "topicFilterValue": "./relay/0/power", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Power1", "id": "81cf9caf.b6fb4", "topicFilterType": "str", "topicFilterValue": "./relay/1/power", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Energy0", "id": "f491f1b0.11302", "topicFilterType": "str", "topicFilterValue": "./relay/0/energy", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Energy1", "id": "44ed47e4.5664f8", "topicFilterType": "str", "topicFilterValue": "./relay/1/energy", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Input0", "id": "54e0d4ec.a2c6dc", "topicFilterType": "str", "topicFilterValue": "./input/0", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Input1", "id": "a8ac48cd.9a9608", "topicFilterType": "str", "topicFilterValue": "./input/1", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Longpush0", "id": "f7c9cffe.eb9dc", "topicFilterType": "str", "topicFilterValue": "./longpush/0", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Longpush1", "id": "f73320d6.4b44f", "topicFilterType": "str", "topicFilterValue": "./longpush/1", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Temperature", "id": "abf17780.8c9ff8", "topicFilterType": "str", "topicFilterValue": "./temperature", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Temperature F", "id": "77edb762.97a038", "topicFilterType": "str", "topicFilterValue": "./temperature_f", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "New Firmware", "id": "bed60fff.b612a", "topicFilterType": "str", "topicFilterValue": "./announce", "topicSuffix": "./command", "type": "both", "ingress": "4bf3ad0b.ee1184", "egress": "5e055328.81229c", "notes": "", "output": "1" }, { "name": "Overtemperature", "id": "7165e795.7c8ee8", "topicFilterType": "str", "topicFilterValue": "./overtemperature", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Temperature Status", "id": "560378d5.0b9628", "topicFilterType": "str", "topicFilterValue": "./temperature_status", "topicSuffix": "", "type": "status", "ingress": "8b40061c.c71688", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Voltage", "id": "4ea0c29c.a2047c", "topicFilterType": "str", "topicFilterValue": "./voltage", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Alive", "id": "1", "topicFilterType": "str", "topicFilterValue": "./online", "topicSuffix": "", "readOnly": true, "type": "status", "ingress": "723376c2.8f69a8", "egress": "" } ], "attributes": [], "ingress": [ { "name": "Pass-through", "id": "8b40061c.c71688", "fn": "// msg & attribute objects are\n// passed to function\n\nreturn msg.payload;" }, { "name": "Shelly Relay", "id": "aaf12047.8d497", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload == \"on\");\nreturn msg.payload;" }, { "name": "Convert to Number", "id": "46b4038e.514b5c", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = Number(msg.payload);\nreturn msg.payload;" }, { "name": "Convert to Boolean", "id": "723376c2.8f69a8", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload === 'true');\nreturn msg.payload;" }, { "name": "Shelly Firmware", "id": "4bf3ad0b.ee1184", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = JSON.parse(msg.payload).new_fw;\nreturn msg.payload;" }, { "name": "Number to Boolean", "id": "52a65ce9.552aa4", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload == 1);\nreturn msg.payload;" } ], "egress": [ { "name": "Pass-through", "id": "a9adc959.52dea8", "fn": "// msg & attribute objects are\n// passed to function\n\nreturn msg;" }, { "name": "Shelly Relay", "id": "b0499ab0.270728", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = msg.payload ? \"on\" : \"off\";\nreturn msg;" }, { "name": "Shelly Update Firmware", "id": "5e055328.81229c", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = \"update_fw\";\nreturn msg;" } ], "thingStatus": true, "thingCommand": true, "thingOutput": true, "hbCheck": true, "hbType": "lwt", "hbTTL": "", "hbLWT": "723376c2.8f69a8", "hbFilterVal": "./online", "hbFilterType": "str", "hbPropVal": "payload", "hbPropType": "msg", "filterFunction": "0", "outputs": "1" } ]

flic commented 1 year ago

The only way you'll get output from a Thing node is by using an Action node:

Skärmavbild 2023-03-19 kl  11 27 58

[ { "id": "16d551ba168b5c7e", "type": "hal2Thing", "z": "a12b67b864e2c98f", "eventHandler": "e228014191d14be6", "thingType": "f6315aac7f58c018", "name": "Example Relay", "attributes": [], "topicFilter": "shellies/example-relay/#", "topicFilterType": "mqtt", "topicPrefix": "shellies/example-relay", "notes": "Shelly 2.5 Double Relay", "outputs": "1", "x": 540, "y": 1400, "wires": [ [ "f4681279a091b5ab" ] ] }, { "id": "5594ed7c8f9df7b4", "type": "comment", "z": "a12b67b864e2c98f", "name": "Example relay and dimmer", "info": "", "x": 150, "y": 1360, "wires": [] }, { "id": "ec81db162c53408e", "type": "inject", "z": "a12b67b864e2c98f", "name": "Init", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payloadType": "date", "x": 110, "y": 1400, "wires": [ [ "d52e13a5b395f89e" ] ] }, { "id": "d52e13a5b395f89e", "type": "function", "z": "a12b67b864e2c98f", "name": "Emulate values from MQTT", "func": "// Emulate values\nlet relay0 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/0\"\n}\nlet power0 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/0/power\"\n}\nlet relay1 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/1\"\n}\nlet power1 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/1/power\"\n}\nlet temperature = {\n payload: 58,\n topic: \"shellies/example-relay/temperature\"\n}\nlet online = {\n payload: \"true\",\n topic: \"shellies/example-relay/online\"\n}\n\nreturn [[relay0,relay1,power0,power1,temperature,online]];\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 300, "y": 1400, "wires": [ [ "16d551ba168b5c7e" ] ] }, { "id": "f4681279a091b5ab", "type": "debug", "z": "a12b67b864e2c98f", "name": "Emulate publishing message to MQTT", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 870, "y": 1420, "wires": [] }, { "id": "d57f321704d645f2", "type": "inject", "z": "a12b67b864e2c98f", "name": "Init", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payloadType": "date", "x": 110, "y": 1440, "wires": [ [ "0916202ae11bef84" ] ] }, { "id": "0916202ae11bef84", "type": "function", "z": "a12b67b864e2c98f", "name": "Emulate values from MQTT", "func": "// Emulate values\nlet relay0 = {\n payload: \"on\",\n topic: \"shellies/example-relay/relay/0\"\n}\nlet power0 = {\n payload: 1,\n topic: \"shellies/example-relay/relay/0/power\"\n}\nlet relay1 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/1\"\n}\nlet power1 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/1/power\"\n}\nlet temperature = {\n payload: 58,\n topic: \"shellies/example-relay/temperature\"\n}\nlet online = {\n payload: \"true\",\n topic: \"shellies/example-relay/online\"\n}\n\nreturn [[relay0,relay1,power0,power1,temperature,online]];\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 300, "y": 1440, "wires": [ [ "16d551ba168b5c7e" ] ] }, { "id": "ae4b49cf80ad4543", "type": "hal2Action", "z": "a12b67b864e2c98f", "eventHandler": "e228014191d14be6", "name": "Trigger Example Relay egress", "commandset": [ { "category": "hal2Thing", "thing": "16d551ba168b5c7e", "item": "45880dc6.a24df4", "value": "payload", "type": "msg", "onchange": false } ], "ratelimit": 0, "passthru": false, "outputs": 0, "x": 590, "y": 1520, "wires": [] }, { "id": "054c4a6a7e3c1d05", "type": "inject", "z": "a12b67b864e2c98f", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "true", "payloadType": "bool", "x": 350, "y": 1500, "wires": [ [ "ae4b49cf80ad4543" ] ] }, { "id": "266fd5d9987a6d17", "type": "inject", "z": "a12b67b864e2c98f", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "false", "payloadType": "bool", "x": 350, "y": 1540, "wires": [ [ "ae4b49cf80ad4543" ] ] }, { "id": "e228014191d14be6", "type": "hal2EventHandler", "name": "Event handler", "contextStore": "memory", "maxlisteners": "51", "heartbeat": "10" }, { "id": "f6315aac7f58c018", "type": "hal2ThingType", "name": "Shelly Relay", "contextStore": "filesystem", "nodestatus": "💡 [0] %Relay0% (%Power0%w)💡 [1] %Relay1% (%Power1%w) 🌡 %Temperature%°C", "nodestatusType": "str", "statusFn": "// item & attribute objects are\n// passed to function as objects\n\nreturn '';", "items": [ { "name": "Relay0", "id": "45880dc6.a24df4", "topicFilterType": "str", "topicFilterValue": "./relay/0", "topicSuffix": "./relay/0/command", "type": "both", "ingress": "aaf12047.8d497", "egress": "b0499ab0.270728", "notes": "", "output": "1" }, { "name": "Relay1", "id": "4d304056.9c77b", "topicFilterType": "str", "topicFilterValue": "./relay/1", "topicSuffix": "./relay/1/command", "type": "both", "ingress": "aaf12047.8d497", "egress": "b0499ab0.270728", "notes": "", "output": "1" }, { "name": "Power0", "id": "279e85eb.c15aaa", "topicFilterType": "str", "topicFilterValue": "./relay/0/power", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Power1", "id": "81cf9caf.b6fb4", "topicFilterType": "str", "topicFilterValue": "./relay/1/power", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Energy0", "id": "f491f1b0.11302", "topicFilterType": "str", "topicFilterValue": "./relay/0/energy", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Energy1", "id": "44ed47e4.5664f8", "topicFilterType": "str", "topicFilterValue": "./relay/1/energy", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Input0", "id": "54e0d4ec.a2c6dc", "topicFilterType": "str", "topicFilterValue": "./input/0", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Input1", "id": "a8ac48cd.9a9608", "topicFilterType": "str", "topicFilterValue": "./input/1", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Longpush0", "id": "f7c9cffe.eb9dc", "topicFilterType": "str", "topicFilterValue": "./longpush/0", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Longpush1", "id": "f73320d6.4b44f", "topicFilterType": "str", "topicFilterValue": "./longpush/1", "topicSuffix": "", "type": "status", "ingress": "52a65ce9.552aa4", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Temperature", "id": "abf17780.8c9ff8", "topicFilterType": "str", "topicFilterValue": "./temperature", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Temperature F", "id": "77edb762.97a038", "topicFilterType": "str", "topicFilterValue": "./temperature_f", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "New Firmware", "id": "bed60fff.b612a", "topicFilterType": "str", "topicFilterValue": "./announce", "topicSuffix": "./command", "type": "both", "ingress": "4bf3ad0b.ee1184", "egress": "5e055328.81229c", "notes": "", "output": "1" }, { "name": "Overtemperature", "id": "7165e795.7c8ee8", "topicFilterType": "str", "topicFilterValue": "./overtemperature", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Temperature Status", "id": "560378d5.0b9628", "topicFilterType": "str", "topicFilterValue": "./temperature_status", "topicSuffix": "", "type": "status", "ingress": "8b40061c.c71688", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Voltage", "id": "4ea0c29c.a2047c", "topicFilterType": "str", "topicFilterValue": "./voltage", "topicSuffix": "", "type": "status", "ingress": "46b4038e.514b5c", "egress": "a9adc959.52dea8", "notes": "", "output": "1" }, { "name": "Alive", "id": "1", "topicFilterType": "str", "topicFilterValue": "./online", "topicSuffix": "", "readOnly": true, "type": "status", "ingress": "723376c2.8f69a8", "egress": "" } ], "attributes": [], "ingress": [ { "name": "Pass-through", "id": "8b40061c.c71688", "fn": "// msg & attribute objects are\n// passed to function\n\nreturn msg.payload;" }, { "name": "Shelly Relay", "id": "aaf12047.8d497", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload == \"on\");\nreturn msg.payload;" }, { "name": "Convert to Number", "id": "46b4038e.514b5c", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = Number(msg.payload);\nreturn msg.payload;" }, { "name": "Convert to Boolean", "id": "723376c2.8f69a8", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload === 'true');\nreturn msg.payload;" }, { "name": "Shelly Firmware", "id": "4bf3ad0b.ee1184", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = JSON.parse(msg.payload).new_fw;\nreturn msg.payload;" }, { "name": "Number to Boolean", "id": "52a65ce9.552aa4", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload == 1);\nreturn msg.payload;" } ], "egress": [ { "name": "Pass-through", "id": "a9adc959.52dea8", "fn": "// msg & attribute objects are\n// passed to function\n\nreturn msg;" }, { "name": "Shelly Relay", "id": "b0499ab0.270728", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = msg.payload ? \"on\" : \"off\";\nreturn msg;" }, { "name": "Shelly Update Firmware", "id": "5e055328.81229c", "fn": "// msg & attribute objects are\n// passed to function\n\nmsg.payload = \"update_fw\";\nreturn msg;" } ], "thingStatus": true, "thingCommand": true, "thingOutput": true, "hbCheck": true, "hbType": "lwt", "hbTTL": "", "hbLWT": "723376c2.8f69a8", "hbFilterVal": "./online", "hbFilterType": "str", "hbPropVal": "payload", "hbPropType": "msg", "filterFunction": "0", "outputs": "1" } ]

alexsahka commented 1 year ago

I don't get it then, this is even easier

image

[{"id":"e55deec215301738","type":"hal2Thing","z":"12c0857ff1958a83","eventHandler":"e228014191d14be6","thingType":"f593d03dacc87f3d","name":"Example Relay","attributes":[],"topicFilter":"shellies/example-relay/#","topicFilterType":"mqtt","topicPrefix":"shellies/example-relay","notes":"Shelly 2.5 Double Relay","outputs":"1","x":800,"y":2980,"wires":[[]]},{"id":"6e8850bab7c40882","type":"comment","z":"12c0857ff1958a83","name":"Example relay and dimmer","info":"","x":410,"y":2940,"wires":[]},{"id":"c0f40877f8800270","type":"inject","z":"12c0857ff1958a83","name":"Init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":370,"y":2980,"wires":[["2a19de73928c01c3"]]},{"id":"2a19de73928c01c3","type":"function","z":"12c0857ff1958a83","name":"Emulate values from MQTT","func":"// Emulate values\nlet relay0 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/0\"\n}\nlet power0 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/0/power\"\n}\nlet relay1 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/1\"\n}\nlet power1 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/1/power\"\n}\nlet temperature = {\n payload: 58,\n topic: \"shellies/example-relay/temperature\"\n}\nlet online = {\n payload: \"true\",\n topic: \"shellies/example-relay/online\"\n}\n\nreturn [[relay0,relay1,power0,power1,temperature,online]];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":2980,"wires":[["e55deec215301738"]]},{"id":"440c2789e4f9389c","type":"debug","z":"12c0857ff1958a83","name":"Emulate publishing message to MQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1190,"y":3040,"wires":[]},{"id":"dda2db5a7843dcec","type":"inject","z":"12c0857ff1958a83","name":"Init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":370,"y":3020,"wires":[["5fd360900e1dfe19"]]},{"id":"5fd360900e1dfe19","type":"function","z":"12c0857ff1958a83","name":"Emulate values from MQTT","func":"// Emulate values\nlet relay0 = {\n payload: \"on\",\n topic: \"shellies/example-relay/relay/0\"\n}\nlet power0 = {\n payload: 1,\n topic: \"shellies/example-relay/relay/0/power\"\n}\nlet relay1 = {\n payload: \"off\",\n topic: \"shellies/example-relay/relay/1\"\n}\nlet power1 = {\n payload: 0,\n topic: \"shellies/example-relay/relay/1/power\"\n}\nlet temperature = {\n payload: 58,\n topic: \"shellies/example-relay/temperature\"\n}\nlet online = {\n payload: \"true\",\n topic: \"shellies/example-relay/online\"\n}\n\nreturn [[relay0,relay1,power0,power1,temperature,online]];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":3020,"wires":[["e55deec215301738"]]},{"id":"b92cfb4ab69d5a15","type":"hal2Event","z":"12c0857ff1958a83","eventHandler":"e228014191d14be6","name":"","topic":"","thing":"e55deec215301738","typeSel":"hal2Thing","item":"45880dc6.a24df4","operator":"always","change":"1","compareValue":"","compareType":"num","outputValue":"payload","outputType":"state","ratelimit":false,"ratetype":"all","rate":"1","rateUnits":"hour","delay":false,"delayExtend":false,"delayReset":false,"delayValue":5,"x":770,"y":3040,"wires":[["e589d595f6467ad9"]]},{"id":"e589d595f6467ad9","type":"function","z":"12c0857ff1958a83","name":"Converter","func":"msg.payload = (msg.payload == true) ? 'on' : 'off';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":920,"y":3040,"wires":[["440c2789e4f9389c"]]},{"id":"e228014191d14be6","type":"hal2EventHandler","name":"Event handler","maxlisteners":"50","heartbeat":"10"},{"id":"f593d03dacc87f3d","type":"hal2ThingType","name":"Shelly Relay","contextStore":"filesystem","nodestatus":"💡 [0] %Relay0% (%Power0%w)💡 [1] %Relay1% (%Power1%w) 🌡 %Temperature%°C","nodestatusType":"str","statusFn":"// item & attribute objects are\n// passed to function as objects\n\nreturn '';","items":[{"name":"Relay0","id":"45880dc6.a24df4","topicFilterType":"str","topicFilterValue":"./relay/0","topicSuffix":"./relay/0/command","type":"both","ingress":"aaf12047.8d497","egress":"b0499ab0.270728","notes":"","output":"1"},{"name":"Relay1","id":"4d304056.9c77b","topicFilterType":"str","topicFilterValue":"./relay/1","topicSuffix":"./relay/1/command","type":"both","ingress":"aaf12047.8d497","egress":"b0499ab0.270728","notes":"","output":"1"},{"name":"Power0","id":"279e85eb.c15aaa","topicFilterType":"str","topicFilterValue":"./relay/0/power","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Power1","id":"81cf9caf.b6fb4","topicFilterType":"str","topicFilterValue":"./relay/1/power","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Energy0","id":"f491f1b0.11302","topicFilterType":"str","topicFilterValue":"./relay/0/energy","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Energy1","id":"44ed47e4.5664f8","topicFilterType":"str","topicFilterValue":"./relay/1/energy","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Input0","id":"54e0d4ec.a2c6dc","topicFilterType":"str","topicFilterValue":"./input/0","topicSuffix":"","type":"status","ingress":"52a65ce9.552aa4","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Input1","id":"a8ac48cd.9a9608","topicFilterType":"str","topicFilterValue":"./input/1","topicSuffix":"","type":"status","ingress":"52a65ce9.552aa4","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Longpush0","id":"f7c9cffe.eb9dc","topicFilterType":"str","topicFilterValue":"./longpush/0","topicSuffix":"","type":"status","ingress":"52a65ce9.552aa4","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Longpush1","id":"f73320d6.4b44f","topicFilterType":"str","topicFilterValue":"./longpush/1","topicSuffix":"","type":"status","ingress":"52a65ce9.552aa4","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Temperature","id":"abf17780.8c9ff8","topicFilterType":"str","topicFilterValue":"./temperature","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Temperature F","id":"77edb762.97a038","topicFilterType":"str","topicFilterValue":"./temperature_f","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"New Firmware","id":"bed60fff.b612a","topicFilterType":"str","topicFilterValue":"./announce","topicSuffix":"./command","type":"both","ingress":"4bf3ad0b.ee1184","egress":"5e055328.81229c","notes":"","output":"1"},{"name":"Overtemperature","id":"7165e795.7c8ee8","topicFilterType":"str","topicFilterValue":"./overtemperature","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Temperature Status","id":"560378d5.0b9628","topicFilterType":"str","topicFilterValue":"./temperature_status","topicSuffix":"","type":"status","ingress":"8b40061c.c71688","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Voltage","id":"4ea0c29c.a2047c","topicFilterType":"str","topicFilterValue":"./voltage","topicSuffix":"","type":"status","ingress":"46b4038e.514b5c","egress":"a9adc959.52dea8","notes":"","output":"1"},{"name":"Alive","id":"1","topicFilterType":"str","topicFilterValue":"./online","topicSuffix":"","readOnly":true,"type":"status","ingress":"723376c2.8f69a8","egress":""}],"attributes":[],"ingress":[{"name":"Pass-through","id":"8b40061c.c71688","fn":"// msg & attribute objects are\n// passed to function\n\nreturn msg.payload;"},{"name":"Shelly Relay","id":"aaf12047.8d497","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload == \"on\");\nreturn msg.payload;"},{"name":"Convert to Number","id":"46b4038e.514b5c","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = Number(msg.payload);\nreturn msg.payload;"},{"name":"Convert to Boolean","id":"723376c2.8f69a8","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload === 'true');\nreturn msg.payload;"},{"name":"Shelly Firmware","id":"4bf3ad0b.ee1184","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = JSON.parse(msg.payload).new_fw;\nreturn msg.payload;"},{"name":"Number to Boolean","id":"52a65ce9.552aa4","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload == 1);\nreturn msg.payload;"}],"egress":[{"name":"Pass-through","id":"a9adc959.52dea8","fn":"// msg & attribute objects are\n// passed to function\n\nreturn msg;"},{"name":"Shelly Relay","id":"b0499ab0.270728","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = msg.payload ? \"on\" : \"off\";\nreturn msg;"},{"name":"Shelly Update Firmware","id":"5e055328.81229c","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = \"update_fw\";\nreturn msg;"}],"thingStatus":true,"thingCommand":true,"thingOutput":true,"hbCheck":true,"hbType":"lwt","hbTTL":"","hbLWT":"723376c2.8f69a8","hbFilterVal":"./online","hbFilterType":"str","hbPropVal":"payload","hbPropType":"msg","filterFunction":"0","outputs":"1"}]

flic commented 1 year ago

Well, depends on what you want to achieve. The underlying thought is that the Thing node should be a virtual representation of a physical device and should handle all the messy translations from "device-speak" to something with a higher level of abstraction, more easily manipulated in Node-RED. It shouldn't matter to you when you build your flows in Node-RED if the device is a Shelly dimmer or a zigbee IKEA lamp, you just use them as interchangeable dimmable lamps in your flows and manipulate them using Event-, Gate-, Value- and Action nodes regardless of brand and underlying technology. If you build your ThingTypes right you should never need to bother, or even know, about the underlying hardware when you construct your flows.

The device sends a message of some sort, usually over MQTT in my case but it could be over any channel, and the ingress functions converts it into an item status that you can take action on using event-, value- or gate nodes. Same thing in the other direction, you shouldn't need to worry that your Shelly dimmer wants {"turn": "on","brightness":msg.payload} and you Hue lights expects {"state": "ON","brightness": Math.round(msg.payload / 2.55)}, that's the job of the egress function to handle, you just use an action node and send the same dim command to the Shelly and the Hue alike and the Thing creates the correct MQTT message for you based on the underlying ThingType.