shelly-strompreis-berechnung/flow.json
2022-08-20 10:55:07 +00:00

2 lines
5.8 KiB
JSON

[{"id":"25b11cba.cef60c","type":"subflow","name":"topic filter","info":"## MQTT Topic filter\n\n### Description\nFilters messages based on the value of `msg.topic` using standard MQTT topic filter notation.\n* `#` match all\n* `+` match one level\n\n### example filters\n* `home/+/temperature` \n * will match `home/bedroom/temperature`\n * will match `home/livingroom/temperature`\n * will not match `home/room/1/temperature`\n * will not match `room/1/temperature`\n* `home/#` \n * will match `home/location`\n * will match `home/livingroom/temperature`\n * will match `home/livingroom/humidity`\n * will not match `room/1/temperature`\n\n\n### Outputs\n\n#### Output 1 - match\nMessages with a topic that matches the `topic filter` will be sent out this output.\n\n#### Output 2 - no match\nMessages with a topic that does not match the `topic filter` will be sent out this output to permit next level filtering\n","category":"function","in":[{"x":68,"y":80,"wires":[{"id":"8635ef98.051688"}]}],"out":[{"x":340,"y":48,"wires":[{"id":"8635ef98.051688","port":0}]},{"x":340,"y":96,"wires":[{"id":"8635ef98.051688","port":1}]}],"env":[{"name":"filter","type":"str","value":"","ui":{"label":{"en-US":"Topic filter"},"type":"input","opts":{"types":["str"]}}},{"name":"status","type":"bool","value":"true","ui":{"label":{"en-US":"Show topic"},"type":"input","opts":{"types":["bool"]}}}],"color":"#D8BFD8","outputLabels":["Match","No Match"],"icon":"font-awesome/fa-filter","status":{"x":548,"y":160,"wires":[{"id":"45101d0d.e1f88c","port":0},{"id":"ddfcc22.bc6bc4","port":0}]}},{"id":"8635ef98.051688","type":"function","z":"25b11cba.cef60c","name":"filter","func":"var a = msg.topic;\nvar b = env.get(\"filter\") || '#';\n\nif(a===b) { return [msg, null]; }\nif(b==='#') { \n if(a) return [msg, null]; //if topic is something, OK\n return [null, msg];//otherwise, fail!\n}\nvar nameSegments = a.split('/');\nvar filterSegments = b.split('/');\nfor (var i = 0; i < filterSegments.length; i++) {\n var topicSegment = nameSegments[i];\n var patternSegment = filterSegments[i];\n var match = false;\n if(topicSegment === patternSegment) { match = true; }\n if(patternSegment === '+') { match = true; }\n if(patternSegment === '#') { return [msg, null]; }\n if(match === false) { return [null, msg]; }\n}\nif(nameSegments.length !== filterSegments.length) { return [null, msg]; }\n\nreturn [msg, null];\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":192,"y":80,"wires":[[],[]]},{"id":"7d929e05.684e","type":"inject","z":"25b11cba.cef60c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":148,"y":160,"wires":[["c9d341ce.724848"]]},{"id":"45101d0d.e1f88c","type":"function","z":"25b11cba.cef60c","name":"","func":"var b = env.get(\"filter\") || '#';\nnode.status({text:b})\nmsg.payload = b;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":428,"y":144,"wires":[[]]},{"id":"c9d341ce.724848","type":"switch","z":"25b11cba.cef60c","name":"","property":"status","propertyType":"env","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":160,"wires":[["45101d0d.e1f88c"],["ddfcc22.bc6bc4"]]},{"id":"ddfcc22.bc6bc4","type":"function","z":"25b11cba.cef60c","name":"","func":"node.status({})\ndelete msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":428,"y":192,"wires":[[]]},{"id":"fc1284a2e6c86aba","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"b2fc4766b5d3d5c7","type":"mqtt in","z":"fc1284a2e6c86aba","name":"","topic":"shellies/#","qos":"2","datatype":"auto-detect","broker":"328cb412ae8d5e45","nl":false,"rap":true,"rh":0,"inputs":0,"x":140,"y":100,"wires":[["fc65ebdb6746a883"]]},{"id":"fc65ebdb6746a883","type":"subflow:25b11cba.cef60c","z":"fc1284a2e6c86aba","name":"","env":[{"name":"filter","value":"shellies/shellyplug-s-0C60C9/relay/0/energy","type":"str"}],"x":320,"y":100,"wires":[["d7937a68367e78b2"],[]]},{"id":"d7937a68367e78b2","type":"function","z":"fc1284a2e6c86aba","name":"Leistung in KWh","func":"var energy = msg.payload\nvar energy1 = (energy / 60 / 1000 ).toFixed(3);\nvar msg = { payload: energy1 };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":100,"wires":[["573c0fca26411024","e8e0bb6db8478887"]]},{"id":"573c0fca26411024","type":"function","z":"fc1284a2e6c86aba","name":"Preisberechnung","func":"var energy = msg.payload\nvar energy1 = (energy * 0.287 ).toFixed(3);\nvar msg = { payload: energy1 };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":180,"wires":[["d392f19a4b98f9f2"]]},{"id":"e8e0bb6db8478887","type":"ui_text","z":"fc1284a2e6c86aba","group":"1a12d18ca3de7370","order":0,"width":0,"height":0,"name":"Watt","label":"KWh: ","format":"{{msg.payload}}","layout":"row-left","className":"","x":730,"y":100,"wires":[]},{"id":"d392f19a4b98f9f2","type":"ui_text","z":"fc1284a2e6c86aba","group":"1a12d18ca3de7370","order":1,"width":0,"height":0,"name":"","label":"Kosten €: ","format":"{{msg.payload}}","layout":"row-left","className":"","x":740,"y":180,"wires":[]},{"id":"328cb412ae8d5e45","type":"mqtt-broker","name":"","broker":"mqtt","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":{},"userProps":"","sessionExpiry":""},{"id":"1a12d18ca3de7370","type":"ui_group","name":"Standard","tab":"d2e8aa17cfafa6c5","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"d2e8aa17cfafa6c5","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]