Last active
June 16, 2020 21:06
-
-
Save nickknissen/aff0f5cd4aff87c6980eff6817f30f79 to your computer and use it in GitHub Desktop.
Turn on and Connect Octoprint node-red
This file contains 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": "14bcab32.46ba15", | |
"type": "subflow", | |
"name": "Octoprint set temperature", | |
"info": "", | |
"category": "", | |
"in": [ | |
{ | |
"x": 120, | |
"y": 80, | |
"wires": [ | |
{ | |
"id": "62e23ad8.739f14" | |
} | |
] | |
} | |
], | |
"out": [], | |
"env": [ | |
{ | |
"name": "temperature", | |
"type": "num", | |
"value": "", | |
"ui": { | |
"label": { | |
"en-US": "Temperature" | |
}, | |
"type": "input", | |
"opts": { | |
"types": [ | |
"num" | |
] | |
} | |
} | |
}, | |
{ | |
"name": "target", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": { | |
"en-US": "target" | |
}, | |
"type": "select", | |
"opts": { | |
"opts": [ | |
{ | |
"l": { | |
"en-US": "bed" | |
}, | |
"v": "bed" | |
}, | |
{ | |
"l": { | |
"en-US": "tool0" | |
}, | |
"v": "tool0" | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"name": "octoprint_api_url", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": { | |
"en-US": "Octoprint api url" | |
}, | |
"type": "input", | |
"opts": { | |
"types": [ | |
"str", | |
"num", | |
"bool", | |
"json", | |
"bin", | |
"env" | |
] | |
} | |
} | |
}, | |
{ | |
"name": "octoprint_api_key", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": { | |
"en-US": "Octoprint api key" | |
}, | |
"type": "input", | |
"opts": { | |
"types": [ | |
"str", | |
"num", | |
"bool", | |
"json", | |
"bin", | |
"env" | |
] | |
} | |
} | |
} | |
], | |
"color": "#DDAA99", | |
"status": { | |
"x": 900, | |
"y": 240, | |
"wires": [ | |
{ | |
"id": "6183be23.f0722", | |
"port": 0 | |
} | |
] | |
} | |
}, | |
{ | |
"id": "6183be23.f0722", | |
"type": "http request", | |
"z": "14bcab32.46ba15", | |
"name": "POST /api/printer/bed", | |
"method": "POST", | |
"ret": "txt", | |
"paytoqs": false, | |
"url": "", | |
"tls": "", | |
"persist": false, | |
"proxy": "", | |
"authType": "", | |
"x": 640, | |
"y": 80, | |
"wires": [ | |
[ | |
"75ce3f18.a4568", | |
"a903144f.d89fb8" | |
] | |
] | |
}, | |
{ | |
"id": "75ce3f18.a4568", | |
"type": "switch", | |
"z": "14bcab32.46ba15", | |
"name": "", | |
"property": "statusCode", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "409", | |
"vt": "str" | |
} | |
], | |
"checkall": "true", | |
"repair": false, | |
"outputs": 1, | |
"x": 850, | |
"y": 80, | |
"wires": [ | |
[ | |
"b44e9652.bd0018" | |
] | |
] | |
}, | |
{ | |
"id": "b44e9652.bd0018", | |
"type": "delay", | |
"z": "14bcab32.46ba15", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "1", | |
"timeoutUnits": "seconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "2", | |
"randomLast": "7", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 1080, | |
"y": 80, | |
"wires": [ | |
[ | |
"62e23ad8.739f14" | |
] | |
] | |
}, | |
{ | |
"id": "62e23ad8.739f14", | |
"type": "function", | |
"z": "14bcab32.46ba15", | |
"name": "", | |
"func": "msg.payload = { \n \"target\": env.get('temperature'), \n \"command\": \"target\"\n}\nmsg.url = `${env.get('octoprint_api_url')}/api/printer/${env.get('target')}?apikey=${env.get('octoprint_api_key')}`\n\nif (env.get('target') != \"bed\") {\n msg.payload = { command:\"target\", targets: {} }\n msg.payload.targets[env.get('target')] = env.get('temperature')\n msg.url = `${env.get('octoprint_api_url')}/api/printer/tool?apikey=${env.get('octoprint_api_key')}`\n}\n\n\n\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 370, | |
"y": 80, | |
"wires": [ | |
[ | |
"6183be23.f0722", | |
"a903144f.d89fb8" | |
] | |
] | |
}, | |
{ | |
"id": "a903144f.d89fb8", | |
"type": "debug", | |
"z": "14bcab32.46ba15", | |
"name": "", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"x": 710, | |
"y": 280, | |
"wires": [] | |
}, | |
{ | |
"id": "8c74bf65.3cf46", | |
"type": "subflow:14bcab32.46ba15", | |
"z": "4b5a6c7d.9f3aa4", | |
"name": "Set tool 205", | |
"env": [ | |
{ | |
"name": "temperature", | |
"value": "205", | |
"type": "num" | |
}, | |
{ | |
"name": "target", | |
"value": "tool0", | |
"type": "str" | |
}, | |
{ | |
"name": "octoprint_api_url", | |
"value": "http://192.168.1.174/", | |
"type": "str" | |
}, | |
{ | |
"name": "Temperature", | |
"value": "50", | |
"type": "num" | |
}, | |
{ | |
"name": "Target", | |
"value": "bed", | |
"type": "str" | |
}, | |
{ | |
"name": "Tool", | |
"value": "bed", | |
"type": "str" | |
}, | |
{ | |
"name": "Octoprint api url", | |
"value": "http://192.168.1.174/api/connection", | |
"type": "str" | |
}, | |
{ | |
"name": "Octoprint api key", | |
"value": "", | |
"type": "str" | |
} | |
], | |
"x": 850, | |
"y": 360, | |
"wires": [] | |
} | |
] |
This file contains 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": "afa241e.094c7c", | |
"type": "subflow", | |
"name": "Turn on and Connect Octoprint", | |
"info": "", | |
"category": "", | |
"in": [ | |
{ | |
"x": 80, | |
"y": 80, | |
"wires": [ | |
{ | |
"id": "cc087f84.563ff" | |
} | |
] | |
} | |
], | |
"out": [ | |
{ | |
"x": 1600, | |
"y": 200, | |
"wires": [ | |
{ | |
"id": "48131421.f9a7ac", | |
"port": "0" | |
} | |
] | |
} | |
], | |
"env": [ | |
{ | |
"name": "relay", | |
"type": "str", | |
"value": "switch.shp6_02_relay" | |
}, | |
{ | |
"name": "octoprint_api_url", | |
"type": "str", | |
"value": "http://192.168.1.174", | |
"ui": { | |
"label": { | |
"en-US": "octoprint_api_key" | |
}, | |
"type": "input", | |
"opts": { | |
"types": [ | |
"str", | |
"num", | |
"bool", | |
"json", | |
"bin", | |
"env" | |
] | |
} | |
} | |
}, | |
{ | |
"name": "octoprint_api_key", | |
"type": "str", | |
"value": "B185E256A98E495F9FC5518E37E4D09F" | |
} | |
], | |
"color": "#DDAA99", | |
"status": { | |
"x": 960, | |
"y": 400, | |
"wires": [ | |
{ | |
"id": "460a4882.d3def8", | |
"port": 0 | |
}, | |
{ | |
"id": "1eb9ad89.f3a662", | |
"port": 0 | |
} | |
] | |
} | |
}, | |
{ | |
"id": "cc0f8e12.ac24b", | |
"type": "switch", | |
"z": "afa241e.094c7c", | |
"name": "", | |
"property": "payload", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "off", | |
"vt": "str" | |
}, | |
{ | |
"t": "eq", | |
"v": "on", | |
"vt": "str" | |
} | |
], | |
"checkall": "true", | |
"repair": false, | |
"outputs": 2, | |
"x": 430, | |
"y": 140, | |
"wires": [ | |
[ | |
"c38fe2b2.0587c" | |
], | |
[ | |
"62f839ce.632868" | |
] | |
] | |
}, | |
{ | |
"id": "c38fe2b2.0587c", | |
"type": "api-call-service", | |
"z": "afa241e.094c7c", | |
"name": "Turn on 3d printer", | |
"server": "22c0bc21.a11184", | |
"version": 1, | |
"debugenabled": false, | |
"service_domain": "switch", | |
"service": "turn_on", | |
"entityId": "${relay}", | |
"data": "", | |
"dataType": "json", | |
"mergecontext": "", | |
"output_location": "", | |
"output_location_type": "none", | |
"mustacheAltTags": false, | |
"x": 630, | |
"y": 120, | |
"wires": [ | |
[ | |
"19bf122d.6533de" | |
] | |
] | |
}, | |
{ | |
"id": "19bf122d.6533de", | |
"type": "delay", | |
"z": "afa241e.094c7c", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "1", | |
"timeoutUnits": "seconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 840, | |
"y": 120, | |
"wires": [ | |
[ | |
"bb2b682b.fbc698" | |
] | |
] | |
}, | |
{ | |
"id": "1eb9ad89.f3a662", | |
"type": "http request", | |
"z": "afa241e.094c7c", | |
"name": "POST /api/connection", | |
"method": "POST", | |
"ret": "txt", | |
"paytoqs": false, | |
"url": "", | |
"tls": "", | |
"persist": false, | |
"proxy": "", | |
"authType": "", | |
"x": 1280, | |
"y": 120, | |
"wires": [ | |
[ | |
"62f839ce.632868" | |
] | |
] | |
}, | |
{ | |
"id": "460a4882.d3def8", | |
"type": "http request", | |
"z": "afa241e.094c7c", | |
"name": "GET", | |
"method": "GET", | |
"ret": "obj", | |
"paytoqs": false, | |
"url": "", | |
"tls": "", | |
"persist": false, | |
"proxy": "", | |
"authType": "", | |
"x": 810, | |
"y": 220, | |
"wires": [ | |
[ | |
"48131421.f9a7ac", | |
"4502b13a.5e158" | |
] | |
] | |
}, | |
{ | |
"id": "48131421.f9a7ac", | |
"type": "switch", | |
"z": "afa241e.094c7c", | |
"name": "", | |
"property": "payload.current.state", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "Operational", | |
"vt": "str" | |
}, | |
{ | |
"t": "else" | |
} | |
], | |
"checkall": "true", | |
"repair": false, | |
"outputs": 2, | |
"x": 970, | |
"y": 220, | |
"wires": [ | |
[], | |
[ | |
"19bf122d.6533de" | |
] | |
] | |
}, | |
{ | |
"id": "cc087f84.563ff", | |
"type": "api-current-state", | |
"z": "afa241e.094c7c", | |
"name": "relay", | |
"server": "22c0bc21.a11184", | |
"version": 1, | |
"outputs": 1, | |
"halt_if": "", | |
"halt_if_type": "str", | |
"halt_if_compare": "is", | |
"override_topic": false, | |
"entity_id": "${relay}", | |
"state_type": "str", | |
"state_location": "payload", | |
"override_payload": "msg", | |
"entity_location": "data", | |
"override_data": "msg", | |
"blockInputOverrides": false, | |
"x": 290, | |
"y": 140, | |
"wires": [ | |
[ | |
"cc0f8e12.ac24b" | |
] | |
] | |
}, | |
{ | |
"id": "62f839ce.632868", | |
"type": "function", | |
"z": "afa241e.094c7c", | |
"name": "create url", | |
"func": "msg.url = `${env.get('octoprint_api_url')}/api/connection?apikey=${env.get('octoprint_api_key')}`\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 640, | |
"y": 220, | |
"wires": [ | |
[ | |
"460a4882.d3def8" | |
] | |
] | |
}, | |
{ | |
"id": "bb2b682b.fbc698", | |
"type": "function", | |
"z": "afa241e.094c7c", | |
"name": "create url", | |
"func": "msg.url = `${env.get('octoprint_api_url')}/api/connection?apikey=${env.get('octoprint_api_key')}`\nmsg.payload = {\"port\":\"AUTO\",\"baudrate\":250000,\"printerProfile\":\"_default\",\"autoconnect\":false,\"command\":\"connect\"}\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 1040, | |
"y": 120, | |
"wires": [ | |
[ | |
"1eb9ad89.f3a662" | |
] | |
] | |
}, | |
{ | |
"id": "4502b13a.5e158", | |
"type": "debug", | |
"z": "afa241e.094c7c", | |
"name": "", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "false", | |
"x": 1120, | |
"y": 400, | |
"wires": [] | |
}, | |
{ | |
"id": "22c0bc21.a11184", | |
"type": "server", | |
"z": "", | |
"name": "Home Assistant", | |
"legacy": false, | |
"addon": true, | |
"rejectUnauthorizedCerts": true, | |
"ha_boolean": "y|yes|true|on|home|open", | |
"connectionDelay": true, | |
"cacheJson": false | |
}, | |
{ | |
"id": "9b88c0cb.a744f", | |
"type": "subflow:afa241e.094c7c", | |
"z": "5b05a5dc.d9f8ac", | |
"name": "Turn on and connect", | |
"env": [ | |
{ | |
"name": "octoprint_api_key", | |
"value": "", | |
"type": "str" | |
} | |
], | |
"x": 780, | |
"y": 440, | |
"wires": [ | |
[] | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment