Created
March 15, 2020 17:30
-
-
Save virgafox/a72e8d8d798c648153159048eb1a9a45 to your computer and use it in GitHub Desktop.
NodeRed flow - Shelly roller target position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "962a6866.a08c1", | |
"type": "tab", | |
"label": "Homekit roller", | |
"disabled": false, | |
"info": "" | |
}, | |
{ | |
"id": "6342b342.4cc514", | |
"type": "mqtt in", | |
"z": "962a6866.a08c1", | |
"name": "Position State", | |
"topic": "shellies/shellyswitch25-XXXXXX/roller/0", | |
"qos": "0", | |
"datatype": "utf8", | |
"broker": "2dff00a1.22e8e", | |
"x": 130, | |
"y": 120, | |
"wires": [ | |
[ | |
"7cfe0504.2067bc" | |
] | |
] | |
}, | |
{ | |
"id": "7cfe0504.2067bc", | |
"type": "function", | |
"z": "962a6866.a08c1", | |
"name": "Manage position state", | |
"func": "var currentPosition = flow.get('currentPosition') || null;\nvar requestedPosition = flow.get('requestedPosition') || null;\n\nif (msg.payload === 'open' && requestedPosition === null) {\n return { payload: 100 };\n} else if (msg.payload === 'close' && requestedPosition === null) {\n return { payload: 0 };\n} else if (msg.payload === 'stop' && currentPosition !== null) {\n flow.set('requestedPosition', null);\n return { payload: currentPosition };\n} else {\n return null;\n}", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 380, | |
"y": 120, | |
"wires": [ | |
[ | |
"358ce827.1dcf98" | |
] | |
] | |
}, | |
{ | |
"id": "358ce827.1dcf98", | |
"type": "mqtt out", | |
"z": "962a6866.a08c1", | |
"name": "target position", | |
"topic": "shellies/shellyswitch25-XXXXXX/roller/0/targetPos", | |
"qos": "", | |
"retain": "", | |
"broker": "2dff00a1.22e8e", | |
"x": 660, | |
"y": 120, | |
"wires": [] | |
}, | |
{ | |
"id": "e78754d9.5938c8", | |
"type": "mqtt in", | |
"z": "962a6866.a08c1", | |
"name": "Current Position", | |
"topic": "shellies/shellyswitch25-XXXXXX/roller/0/pos", | |
"qos": "0", | |
"datatype": "utf8", | |
"broker": "2dff00a1.22e8e", | |
"x": 140, | |
"y": 180, | |
"wires": [ | |
[ | |
"89bd1a00.8b5458" | |
] | |
] | |
}, | |
{ | |
"id": "89bd1a00.8b5458", | |
"type": "function", | |
"z": "962a6866.a08c1", | |
"name": "Save current position", | |
"func": "flow.set('currentPosition', parseInt(msg.payload));", | |
"outputs": 0, | |
"noerr": 0, | |
"x": 380, | |
"y": 180, | |
"wires": [] | |
}, | |
{ | |
"id": "4069885b.3ffd28", | |
"type": "mqtt in", | |
"z": "962a6866.a08c1", | |
"name": "Requested Position", | |
"topic": "shellies/shellyswitch25-XXXXXX/roller/0/command/pos", | |
"qos": "0", | |
"datatype": "utf8", | |
"broker": "2dff00a1.22e8e", | |
"x": 150, | |
"y": 60, | |
"wires": [ | |
[ | |
"6f109085.cc2db8" | |
] | |
] | |
}, | |
{ | |
"id": "6f109085.cc2db8", | |
"type": "function", | |
"z": "962a6866.a08c1", | |
"name": "Manage Requested Position", | |
"func": "flow.set('requestedPosition', parseInt(msg.payload))\nreturn { payload: msg.payload }", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 400, | |
"y": 60, | |
"wires": [ | |
[ | |
"358ce827.1dcf98" | |
] | |
] | |
}, | |
{ | |
"id": "2dff00a1.22e8e", | |
"type": "mqtt-broker", | |
"z": "", | |
"name": "Mosquitto", | |
"broker": "localhost", | |
"port": "1883", | |
"clientid": "", | |
"usetls": false, | |
"compatmode": false, | |
"keepalive": "60", | |
"cleansession": true, | |
"birthTopic": "", | |
"birthQos": "0", | |
"birthRetain": "false", | |
"birthPayload": "", | |
"closeTopic": "", | |
"closeQos": "0", | |
"closeRetain": "false", | |
"closePayload": "", | |
"willTopic": "", | |
"willQos": "0", | |
"willRetain": "false", | |
"willPayload": "" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment