Created
March 18, 2023 21:47
-
-
Save holnburger/8b118973d28e01c7c0820372f888420c to your computer and use it in GitHub Desktop.
Node Red Export for Home Assistant + Alexa Actionable Notifications + ChatGPT
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": "c2ccbafbeb0f79d3", | |
"type": "inject", | |
"z": "98f3bced.07a83", | |
"name": "", | |
"props": [ | |
{ | |
"p": "payload" | |
}, | |
{ | |
"p": "topic", | |
"vt": "str" | |
} | |
], | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"onceDelay": 0.1, | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"x": 200, | |
"y": 1080, | |
"wires": [ | |
[ | |
"7bad15cbc3856eed" | |
] | |
] | |
}, | |
{ | |
"id": "7bad15cbc3856eed", | |
"type": "function", | |
"z": "98f3bced.07a83", | |
"name": "format data for ChatGPT", | |
"func": "const prompt = `You are Friday, an artificial intelligence like the one in the Iron Man movies. You are used to automate Joe's apartment. You are always a bit funny and ironic, but always a help.\nAsk Joe if an alarm clock should be set for tomorrow at 07:30.`\n\nconst message = [\n { \"role\": \"system\", \"content\": prompt },\n]\n\nmsg.payload = {\n model: \"gpt-3.5-turbo\",\n messages: message, \n max_tokens: 200\n}\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 410, | |
"y": 1080, | |
"wires": [ | |
[ | |
"ad1660a1dbf93dc7" | |
] | |
] | |
}, | |
{ | |
"id": "ad1660a1dbf93dc7", | |
"type": "http request", | |
"z": "98f3bced.07a83", | |
"name": "openai request", | |
"method": "POST", | |
"ret": "obj", | |
"paytoqs": "ignore", | |
"url": "https://api.openai.com/v1/chat/completions", | |
"tls": "", | |
"persist": false, | |
"proxy": "", | |
"insecureHTTPParser": false, | |
"authType": "bearer", | |
"senderr": false, | |
"headers": [], | |
"x": 640, | |
"y": 1080, | |
"wires": [ | |
[ | |
"0453c824f1d61771" | |
] | |
] | |
}, | |
{ | |
"id": "0453c824f1d61771", | |
"type": "function", | |
"z": "98f3bced.07a83", | |
"name": "format output", | |
"func": "const gptAnswer = msg.payload.choices[0].message.content.replace(/['\"]+/g, '').replace(/(\\r\\n|\\n|\\r)/gm, \"\")\n\nmsg.payload = gptAnswer\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 680, | |
"y": 1140, | |
"wires": [ | |
[ | |
"7f751275941e2fa1" | |
] | |
] | |
}, | |
{ | |
"id": "5517b2b36160d9ca", | |
"type": "comment", | |
"z": "98f3bced.07a83", | |
"name": "Insert your API Key in the Bearer Auth", | |
"info": "", | |
"x": 710, | |
"y": 1040, | |
"wires": [] | |
}, | |
{ | |
"id": "7f751275941e2fa1", | |
"type": "api-call-service", | |
"z": "98f3bced.07a83", | |
"name": "notify via Alexa", | |
"server": "e78c2b0.2b5c2d8", | |
"version": 5, | |
"debugenabled": false, | |
"domain": "notify", | |
"service": "alexa_media", | |
"areaId": [], | |
"deviceId": [], | |
"entityId": [], | |
"data": "{ \"message\": payload, \"target\": \"media_player.wohnzimmer_dot\" }", | |
"dataType": "jsonata", | |
"mergeContext": "", | |
"mustacheAltTags": false, | |
"outputProperties": [], | |
"queue": "none", | |
"x": 860, | |
"y": 1140, | |
"wires": [ | |
[ | |
"f658f73792e09ea3" | |
] | |
] | |
}, | |
{ | |
"id": "f658f73792e09ea3", | |
"type": "api-call-service", | |
"z": "98f3bced.07a83", | |
"name": "Actionable Notification", | |
"server": "e78c2b0.2b5c2d8", | |
"version": 5, | |
"debugenabled": false, | |
"domain": "script", | |
"service": "activate_alexa_actionable_notification", | |
"areaId": [], | |
"deviceId": [], | |
"entityId": [], | |
"data": "{ \"text\": \" \", \"event_id\": \"gpt-test\", \"alexa_device\": \"media_player.wohnzimmer_dot\"}", | |
"dataType": "jsonata", | |
"mergeContext": "", | |
"mustacheAltTags": false, | |
"outputProperties": [], | |
"queue": "none", | |
"x": 1080, | |
"y": 1140, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "5a57d38b65949143", | |
"type": "comment", | |
"z": "98f3bced.07a83", | |
"name": "Insert specific event_id", | |
"info": "", | |
"x": 1080, | |
"y": 1100, | |
"wires": [] | |
}, | |
{ | |
"id": "c9db3d8eeafe80fb", | |
"type": "server-events", | |
"z": "98f3bced.07a83", | |
"name": "Alexa actionable event listener", | |
"server": "e78c2b0.2b5c2d8", | |
"version": 1, | |
"event_type": "alexa_actionable_notification", | |
"exposeToHomeAssistant": false, | |
"haConfig": [ | |
{ | |
"property": "name", | |
"value": "" | |
}, | |
{ | |
"property": "icon", | |
"value": "" | |
} | |
], | |
"waitForRunning": true, | |
"outputProperties": [ | |
{ | |
"property": "payload", | |
"propertyType": "msg", | |
"value": "", | |
"valueType": "eventData" | |
}, | |
{ | |
"property": "topic", | |
"propertyType": "msg", | |
"value": "$outputData(\"eventData\").event_type", | |
"valueType": "jsonata" | |
} | |
], | |
"x": 1100, | |
"y": 1240, | |
"wires": [ | |
[ | |
"b22744a2933f7f16" | |
] | |
] | |
}, | |
{ | |
"id": "92ed07e558cba607", | |
"type": "comment", | |
"z": "98f3bced.07a83", | |
"name": "reuse event_id", | |
"info": "", | |
"x": 1360, | |
"y": 1200, | |
"wires": [] | |
}, | |
{ | |
"id": "b22744a2933f7f16", | |
"type": "switch", | |
"z": "98f3bced.07a83", | |
"name": "check event_id", | |
"property": "payload.event.event_id", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "gpt-test", | |
"vt": "str" | |
} | |
], | |
"checkall": "true", | |
"repair": false, | |
"outputs": 1, | |
"x": 1360, | |
"y": 1240, | |
"wires": [ | |
[ | |
"bb035f653cd54bb1" | |
] | |
] | |
}, | |
{ | |
"id": "bb035f653cd54bb1", | |
"type": "switch", | |
"z": "98f3bced.07a83", | |
"name": "answers", | |
"property": "payload.event.event_response_type", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "ResponseYes", | |
"vt": "str" | |
}, | |
{ | |
"t": "eq", | |
"v": "ResponseNone", | |
"vt": "str" | |
}, | |
{ | |
"t": "eq", | |
"v": "ResponseNo", | |
"vt": "str" | |
}, | |
{ | |
"t": "else" | |
} | |
], | |
"checkall": "true", | |
"repair": false, | |
"outputs": 4, | |
"x": 1540, | |
"y": 1240, | |
"wires": [ | |
[ | |
"5e60e06a00f321a6" | |
], | |
[ | |
"cbed6ee78bc0b5a3" | |
], | |
[ | |
"8241b5143ee75f57" | |
], | |
[ | |
"259f7f6dad9e8aca" | |
] | |
] | |
}, | |
{ | |
"id": "5e60e06a00f321a6", | |
"type": "debug", | |
"z": "98f3bced.07a83", | |
"name": "yes_debug", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 1710, | |
"y": 1200, | |
"wires": [] | |
}, | |
{ | |
"id": "cbed6ee78bc0b5a3", | |
"type": "debug", | |
"z": "98f3bced.07a83", | |
"name": "no_debug", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 1700, | |
"y": 1240, | |
"wires": [] | |
}, | |
{ | |
"id": "8241b5143ee75f57", | |
"type": "debug", | |
"z": "98f3bced.07a83", | |
"name": "no_respsone_debug", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 1740, | |
"y": 1280, | |
"wires": [] | |
}, | |
{ | |
"id": "259f7f6dad9e8aca", | |
"type": "debug", | |
"z": "98f3bced.07a83", | |
"name": "others_debug", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "payload", | |
"targetType": "msg", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 1720, | |
"y": 1320, | |
"wires": [] | |
}, | |
{ | |
"id": "e78c2b0.2b5c2d8", | |
"type": "server", | |
"name": "Home Assistant", | |
"version": 2, | |
"rejectUnauthorizedCerts": true, | |
"ha_boolean": "y|yes|true|on|home|open", | |
"connectionDelay": true, | |
"cacheJson": true, | |
"heartbeat": false, | |
"heartbeatInterval": 30 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment