Hallo Vincent,
habe einen Flow angepasst mit dem kann ich den shelly schalten. Ich weiss aber noch nicht wieso :-).
Kannst es ja mal anschauen.
Lieber Gruss
Martin
[
{
"id": "7b0f914798b66d94",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "4ad6479.c8cc3b8",
"type": "mqtt in",
"z": "7b0f914798b66d94",
"name": "power readings",
"topic": "shellies/shelly1pm-BA1936/relay/0/power",
"qos": "2",
"datatype": "auto",
"broker": "3ecd7f11.4d3dd",
"inputs": 0,
"x": 165,
"y": 125,
"wires": [
[
"13fb1305.e290fd"
]
]
},
{
"id": "13fb1305.e290fd",
"type": "debug",
"z": "7b0f914798b66d94",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 375,
"y": 125,
"wires": []
},
{
"id": "5c2ed097.9529b",
"type": "debug",
"z": "7b0f914798b66d94",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 565,
"y": 695,
"wires": []
},
{
"id": "abe24fc8.c374f",
"type": "comment",
"z": "7b0f914798b66d94",
"name": "flow to accumulate power readings",
"info": "",
"x": 215,
"y": 655,
"wires": []
},
{
"id": "f1974e0c.c5bde",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "Clear",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "num",
"x": 254,
"y": 745,
"wires": [
[
"70dee9e2.463c68"
]
]
},
{
"id": "244f4b1.616beb4",
"type": "mqtt in",
"z": "7b0f914798b66d94",
"name": "Shelly - Energy",
"topic": "shellies/shellyRelay1/relay/0/energy",
"qos": "2",
"datatype": "auto",
"broker": "aa11e6d8.6cd088",
"nl": false,
"rap": false,
"inputs": 0,
"x": 155,
"y": 695,
"wires": [
[
"d0fc7a46.8e75a8"
]
]
},
{
"id": "d0fc7a46.8e75a8",
"type": "function",
"z": "7b0f914798b66d94",
"name": "Total Energy",
"func": "// Given current total energy from Shelly in msg.payload as a string\npayload = parseInt(msg.payload)\n// check that it has converted ok (so it is not not-a-number)\nif (!isNaN(payload)) {\n let runningTotalEnergy = flow.get(\"runningTotalEnergy\") || 0\n let previousShellyValue = flow.get(\"previousShellyValue\") || 0\n // test whether the Shelly has reset since last input\n if (payload < previousShellyValue) {\n // yes it has, just add new value to the total\n runningTotalEnergy += payload\n } else {\n // no so add the difference between this and last to the running total\n runningTotalEnergy += payload - previousShellyValue\n }\n flow.set(\"previousShellyValue\", payload)\n flow.set(\"runningTotalEnergy\",runningTotalEnergy)\n // Convert watt/minutes to watt/hours\n msg.payload = (runningTotalEnergy/60)\n} else {\n // an illegal string passed in so ignore it, don't pass on anything\n msg = null\n}\nreturn msg;",
"outputs": 1,
"noerr": 6,
"initialize": "",
"finalize": "",
"libs": [],
"x": 345,
"y": 695,
"wires": [
[
"5c2ed097.9529b"
]
]
},
{
"id": "c73eee2b.44d47",
"type": "mqtt in",
"z": "7b0f914798b66d94",
"name": "Shelly announcements",
"topic": "shellies/#",
"qos": "2",
"datatype": "auto",
"broker": "3ecd7f11.4d3dd",
"inputs": 0,
"x": 185,
"y": 75,
"wires": [
[
"13fb1305.e290fd"
]
]
},
{
"id": "c2b8ddab.31cb4",
"type": "mqtt out",
"z": "7b0f914798b66d94",
"name": "",
"topic": "",
"qos": "2",
"retain": "false",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aa11e6d8.6cd088",
"x": 355,
"y": 265,
"wires": []
},
{
"id": "fee0bdf6.ce384",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "shellies/shelly1pm-BA1936/relay/0/command",
"payload": "on",
"payloadType": "str",
"x": 155,
"y": 225,
"wires": [
[
"c2b8ddab.31cb4"
]
]
},
{
"id": "7aeb348d.ebaa4c",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "",
"repeat": "",
"crontab": "00 23 * * *",
"once": false,
"onceDelay": 0.1,
"topic": "shellies/shelly1pm-BA1936/relay/0/command",
"payload": "off",
"payloadType": "str",
"x": 155,
"y": 265,
"wires": [
[
"c2b8ddab.31cb4"
]
]
},
{
"id": "4114738a.fe5d5c",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "Report status",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "shellies/command",
"payload": "update",
"payloadType": "str",
"x": 175,
"y": 305,
"wires": [
[
"c2b8ddab.31cb4"
]
]
},
{
"id": "753c1c9e.1150c4",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "ON",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "on",
"payloadType": "str",
"x": 165,
"y": 505,
"wires": [
[
"e4e6cfa1.b88ea"
]
]
},
{
"id": "e4e6cfa1.b88ea",
"type": "function",
"z": "7b0f914798b66d94",
"name": "turn relay on/off",
"func": "var x = msg.payload;\nvar IP = \"192.168.178.111\";\nmsg.url= \"http://\"+ IP + \"/relay/0\";\n\nmsg.payload = \"turn=\" + x;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 405,
"y": 525,
"wires": [
[
"cf4b0b9c.2e3788"
]
]
},
{
"id": "f73044cd.de8df8",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "OFF",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "off",
"payloadType": "str",
"x": 165,
"y": 545,
"wires": [
[
"e4e6cfa1.b88ea"
]
]
},
{
"id": "97ac4109.5ddb2",
"type": "function",
"z": "7b0f914798b66d94",
"name": "get device status",
"func": "\nvar IP = \"192.168.178.111\";\nmsg.url= \"http://\"+ IP + \"/status\";\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 415,
"y": 465,
"wires": [
[
"cf4b0b9c.2e3788"
]
]
},
{
"id": "36814aad.047cb6",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "str",
"x": 165,
"y": 465,
"wires": [
[
"97ac4109.5ddb2"
]
]
},
{
"id": "3434812a.ff7f9e",
"type": "function",
"z": "7b0f914798b66d94",
"name": "change mqtt update period",
"func": "var x = msg.payload;\nvar IP = \"192.168.178.111\";\nmsg.url= \"http://\"+ IP + \"/settings\";\n\nmsg.payload = \"mqtt_update_period=\" + x;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 445,
"y": 425,
"wires": [
[
"cf4b0b9c.2e3788"
]
]
},
{
"id": "cf4b0b9c.2e3788",
"type": "http request",
"z": "7b0f914798b66d94",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"senderr": false,
"headers": [],
"x": 665,
"y": 515,
"wires": [
[
"cf280268.e0c2a"
]
]
},
{
"id": "cf280268.e0c2a",
"type": "debug",
"z": "7b0f914798b66d94",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 855,
"y": 515,
"wires": []
},
{
"id": "f25f81e4.86b0a",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "MQTT update period",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "300",
"payloadType": "num",
"x": 205,
"y": 425,
"wires": [
[
"3434812a.ff7f9e"
]
]
},
{
"id": "77129295.530c9c",
"type": "comment",
"z": "7b0f914798b66d94",
"name": "http requests",
"info": "",
"x": 155,
"y": 385,
"wires": []
},
{
"id": "f717b6e4.beb698",
"type": "mqtt in",
"z": "7b0f914798b66d94",
"name": "Relay status",
"topic": "shellies/shelly1pm-BA1936/relay/0",
"qos": "2",
"datatype": "auto",
"broker": "3ecd7f11.4d3dd",
"inputs": 0,
"x": 155,
"y": 175,
"wires": [
[
"13fb1305.e290fd"
]
]
},
{
"id": "70dee9e2.463c68",
"type": "change",
"z": "7b0f914798b66d94",
"name": "Reset energy counter",
"rules": [
{
"t": "set",
"p": "runningTotalEnergy",
"pt": "flow",
"to": "0",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 445,
"y": 745,
"wires": [
[]
]
},
{
"id": "9087142f.0b8a88",
"type": "function",
"z": "7b0f914798b66d94",
"name": "reboot device",
"func": "var IP = \"192.168.175.111\";\nmsg.url= \"http://\"+ IP + \"/reboot\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 405,
"y": 585,
"wires": [
[
"cf4b0b9c.2e3788"
]
]
},
{
"id": "61fdbcd.868c344",
"type": "inject",
"z": "7b0f914798b66d94",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "str",
"x": 165,
"y": 585,
"wires": [
[
"9087142f.0b8a88"
]
]
},
{
"id": "eb2a8afb.78f218",
"type": "comment",
"z": "7b0f914798b66d94",
"name": "mqtt",
"info": "",
"x": 135,
"y": 35,
"wires": []
},
{
"id": "3ecd7f11.4d3dd",
"type": "mqtt-broker",
"name": "paul_broker",
"broker": "192.168.1.8",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "aa11e6d8.6cd088",
"type": "mqtt-broker",
"name": "Local server",
"broker": "192.168.178.57",
"port": "1885",
"clientid": "Local node-RED",
"autoConnect": true,
"usetls": false,
"compatmode": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "admin",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "Hello from Local node-RED",
"birthMsg": {},
"closeTopic": "admin",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "Local node-RED is about to exit",
"closeMsg": {},
"willTopic": "admin",
"willQos": "0",
"willRetain": "false",
"willPayload": "Local node-RED has now exited",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]