Useful automations inspired by GPT

 
 

These automations are examples of how GPT can be used to achieve some useful automations. They use AI-Intent which are special nodes that communicate to OpenAI.


Bath-time Stories

Create an automation that can generate creative stories for your little one.

[{"id":"f395988f674691e8","type":"group","z":"e798dd74dc6d028f","name":"Shower time story","style":{"stroke":"#0070c0","fill":"#a4a4a4","label":true,"label-position":"n","color":"#ffffff"},"nodes":["9137a541a079fbb0","23a6576c6f1b82e7","98c4d3ce041f277e","e683eba5b7265350"],"x":654,"y":99,"w":252,"h":202},{"id":"9137a541a079fbb0","type":"api-call-service","z":"e798dd74dc6d028f","g":"f395988f674691e8","name":"play rue's music","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"tts","service":"cloud_say","areaId":[],"deviceId":[],"entityId":["media_player.master_bath_speaker"],"data":"{\"message\": msg.payload.choices[0].message.content}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":800,"y":260,"wires":[[]]},{"id":"23a6576c6f1b82e7","type":"ha-button","z":"e798dd74dc6d028f","g":"f395988f674691e8","name":"Start Bath Time Story","version":0,"debugenabled":false,"outputs":1,"entityConfig":"87e54604e0c705e5","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":780,"y":140,"wires":[["98c4d3ce041f277e"]]},{"id":"98c4d3ce041f277e","type":"OpenAI User","z":"e798dd74dc6d028f","g":"f395988f674691e8","name":"","content":"Create a short bath-time story for a 3 year old","x":810,"y":180,"wires":[["e683eba5b7265350"]]},{"id":"e683eba5b7265350","type":"OpenAI Chat","z":"e798dd74dc6d028f","g":"f395988f674691e8","name":"","token":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":810,"y":220,"wires":[["9137a541a079fbb0"]]},{"id":"228d3d53.df8e02","type":"server","name":"Home Assistant","addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false},{"id":"87e54604e0c705e5","type":"ha-entity-config","server":"228d3d53.df8e02","deviceConfig":"","name":"Story Time","version":"6","entityType":"button","haConfig":[{"property":"name","value":"Story Time Button"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false}]

Email Guardian

Use GPT to analyze you're email and alert you about specific occurrences you care about

[{"id":"b19b0bbc1566de4b","type":"group","z":"6161d870e25ec591","name":"Email Guardian","style":{"label":true,"fill":"#ffffff"},"nodes":["40ce0341ee0eae74","c03b879e983613b4","61b56e591c3cd0a7","7aa6a99a3cd3e85c","fde614500f10c5c6","3dfaa2791328604c","16ed0cf93923aea1","368805bbdb18eafe","281d94bfa0464e24","119a22244439905d","442c9ae2f1b2b21d","2465ce29a50c6d26","9ccb6d5078852ba1","153d49dc6dfaeff9","911afa4eb9f5ee93"],"x":74,"y":1559,"w":972,"h":382},{"id":"656499388a4aa37d","type":"subflow","name":"Telegram Facade","info":"","category":"","in":[{"x":80,"y":40,"wires":[{"id":"44693c7b4594740b"}]}],"out":[{"x":940,"y":140,"wires":[{"id":"c3da1d823169d296","port":0}]}],"env":[{"name":"Method","type":"str","value":"sendMessage","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"Send Message"},"v":"sendMessage"},{"l":{"en-US":"Edit Message"},"v":"editMessage"},{"l":{"en-US":"Typing Status"},"v":"typing"}]}}},{"name":"Message key","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"Use message key as prompt","type":"bool","value":"false","ui":{"type":"checkbox"}},{"name":"Inline_Keyboard key","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","json"]}}},{"name":"Use inline_keyboard as value","type":"bool","value":"false","ui":{"type":"checkbox"}},{"name":"Keyboard key","type":"str","value":""},{"name":"Use keyboard key as value","type":"bool","value":"false","ui":{"type":"checkbox"}},{"name":"debounce","type":"num","value":"","ui":{"type":"input","opts":{"types":["num"]}}}],"meta":{},"color":"#DDAA99"},{"id":"c71f58691e6b25ac","type":"function","z":"656499388a4aa37d","name":"Normalize Data","func":"const useMessageKeyAsPrompt = env.get(\"Use message key as prompt\");\nconst useKeyboardKeyAsValue = env.get(\"Use keyboard key as value\");\nconst useInlineKeyboardKeyAsValue = env.get(\"Use inline_keyboard as value\");\nlet message = sugar.Object.get(msg, env.get(\"Message key\"))\nlet inline_keyboard = sugar.Object.get(msg, env.get(\"Inline_Keyboard key\")) || []\nlet keyboard = sugar.Object.get(msg, env.get(\"Keyboard key\")) || []\nconst payload = {\n    method: env.get(\"Method\"),\n    body: { \n        chat_id: Number(global.get(\"GROUP_CHAT_ID\")),\n        }\n    \n}\nlet reply_markup = {}\n\nmsg.telegram = {message, keyboard, inline_keyboard}\n\nif (useMessageKeyAsPrompt) {\n    message = env.get(\"Message key\")\n    msg.telegram.message = env.get(\"Message key\")\n}\n\nif (useKeyboardKeyAsValue) {\n    keyboard = env.get(\"Keyboard key\") || []\n    msg.telegram.keyboard = env.get(\"Keyboard key\") || []\n}\n\nif (useInlineKeyboardKeyAsValue) {\n    inline_keyboard = env.get(\"Inline_Keyboard key\") || []\n    msg.telegram.inline_keyboard = env.get(\"Inline_Keyboard key\") || []\n}\nif(inline_keyboard.length){\n    // inline_keyboard = createReplyKeyboard(inline_keyboard)\n    msg.telegram.inline_keyboard = inline_keyboard\n    delete msg.telegram.keyboard\n    reply_markup = {\n        keyboard:[],\n        inline_keyboard\n    }\n}\n\nif (keyboard.length) {\n    // keyboard = createReplyKeyboard(keyboard)\n    msg.telegram.keyboard = keyboard\n    delete msg.telegram.inline_keyboard\n    reply_markup = {\n        one_time_keyboard: true,\n        resize_keyboard: true,\n        keyboard: keyboard,\n    }\n}\n\nif(!keyboard.length && ! inline_keyboard.length){\n    delete msg.telegram.inline_keyboard\n    delete msg.telegram.keyboard\n    // payload.response.speech.plain.speech\n}\n\n\n\n\nif ([\"sendMessage\", \"editMessage\"].includes(env.get(\"Method\"))) {\n    payload.body.text = message;\n    payload.body.parse_mode = \"html\",\n    msg.telegram.parse_mode = \"html\"\n        payload.body.reply_markup = reply_markup\n}else{\n    payload.body.action = env.get(\"Method\");\n    payload.method = \"sendChatAction\"\n} \n\nif (env.get(\"Method\") === \"editMessage\") {\n    payload.body.message_id = global.get(\"message_id\");\n    msg.telegram.message_id = global.get(\"message_id\");\n}\n\nmsg.data = payload\n\nreturn msg;\n\n\nfunction createReplyKeyboard(buttons = []){\n    const keyboard = []\n    \n    buttons.forEach(button => {\n        if(typeof button === \"string\"){\n            const commands = []\n            button.split(\",\").forEach(item => {\n                const [text =\"\", callback_data =\"\"] = item.split(\":\")\n\n               commands.push({ text: text.trim(), callback_data: callback_data?.trim() })\n            })\n    keyboard.push(commands)\n           \n        }else if(Array.isArray(button)){\n           const keyboardInputs = button.reduce((agg, item) => {\n                const buttons = item.split(\",\");\n                const commands = [];\n\n                buttons.forEach(item => {\n                    const [text = \"\", callback_data = \"\"] = item.split(\":\")\n                    \n                    commands.push({ text: text.trim(), callback_data: callback_data.trim() })\n                })\n                agg.push(commands)\n                \n                return agg\n            },[]);\n\n            keyboard.push(keyboardInputs)\n        }\n    })\n\n    return keyboard\n}","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[{"var":"sugar","module":"sugar"}],"x":260,"y":80,"wires":[["09ece744e725aa5a"]]},{"id":"c3da1d823169d296","type":"change","z":"656499388a4aa37d","name":"Clean up","rules":[{"t":"set","p":"payload","pt":"msg","to":"cache","tot":"msg","dc":true},{"t":"delete","p":"cache","pt":"msg"},{"t":"delete","p":"data","pt":"msg"},{"t":"delete","p":"telegram","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":140,"wires":[[]]},{"id":"44693c7b4594740b","type":"change","z":"656499388a4aa37d","name":"Cache Payload","rules":[{"t":"set","p":"cache","pt":"msg","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":40,"wires":[["c71f58691e6b25ac"]]},{"id":"43c30b643c3df338","type":"ha-api","z":"656499388a4aa37d","d":true,"name":"Send Thinking Status","server":"228d3d53.df8e02","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"https://api.telegram.org/bot{{global.TELEGRAM}}/{{data.method}}","data":"msg.data.body","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":280,"y":220,"wires":[[]]},{"id":"64aba95844f48d22","type":"api-call-service","z":"656499388a4aa37d","name":"Send Message","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"telegram_bot","service":"send_message","areaId":[],"deviceId":[],"entityId":[],"data":"msg.telegram","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":100,"wires":[["c3da1d823169d296"]]},{"id":"09ece744e725aa5a","type":"switch","z":"656499388a4aa37d","name":"","property":"Method","propertyType":"env","rules":[{"t":"eq","v":"sendMessage","vt":"str"},{"t":"eq","v":"editMessage","vt":"str"},{"t":"eq","v":"typing","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":290,"y":140,"wires":[["64aba95844f48d22"],["b2cea0faea5a9a9d"],[]]},{"id":"b2cea0faea5a9a9d","type":"api-call-service","z":"656499388a4aa37d","name":"Edit Message","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"telegram_bot","service":"edit_message","areaId":[],"deviceId":[],"entityId":[],"data":"msg.telegram","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":140,"wires":[["c3da1d823169d296"]]},{"id":"40ce0341ee0eae74","type":"server-events","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"Email Recieved","server":"228d3d53.df8e02","version":3,"exposeAsEntityConfig":"","eventType":"imap_content","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":180,"y":1600,"wires":[["c03b879e983613b4"]]},{"id":"c03b879e983613b4","type":"function","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"Regex","func":"msg.title = msg.payload.event.subject\nmsg.body = msg.payload.event.text.replaceAll(\"/n\", \"\").trim()\nmsg.payload = {\n    isCompromised: msg.body\n        .search(/(Password)|(account)|(unauthorized)/i) >= 0\n    }\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":150,"y":1640,"wires":[["16ed0cf93923aea1"]]},{"id":"61b56e591c3cd0a7","type":"json","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"convert to JSON","property":"payload","action":"obj","pretty":false,"x":450,"y":1780,"wires":[["7aa6a99a3cd3e85c"]]},{"id":"7aa6a99a3cd3e85c","type":"switch","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"is compromised","property":"payload.isCompromised","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":1820,"wires":[["281d94bfa0464e24","119a22244439905d"]]},{"id":"fde614500f10c5c6","type":"subflow:656499388a4aa37d","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"","env":[{"name":"Message key","value":"message","type":"str"}],"x":450,"y":1900,"wires":[[]]},{"id":"3dfaa2791328604c","type":"api-call-service","z":"6161d870e25ec591","d":true,"g":"b19b0bbc1566de4b","name":"change color","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.ambient_lights","light.master_bedroom_light"],"data":"{\"color_name\": \"violet\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":1780,"wires":[[]]},{"id":"16ed0cf93923aea1","type":"switch","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"is compromised","property":"payload.isCompromised","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":180,"y":1680,"wires":[["9ccb6d5078852ba1"]]},{"id":"368805bbdb18eafe","type":"api-call-service","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"Send Critical Notification","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_3","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"title\": \"Check your email!\",\t   \"message\": \"I suspect you are being hacked.\",\t   \"data\": {\t       \"push\": {\t           \"sound\": {\t               \"name\": \"default\",\t               \"critical\": 1,\t               \"volume\": 1.0\t            }      \t        }      \t    }  \t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1820,"wires":[[]]},{"id":"281d94bfa0464e24","type":"time-range-switch","z":"6161d870e25ec591","d":true,"g":"b19b0bbc1566de4b","name":"","lat":"47.31871183713576","lon":"-122.3449164874551","startTime":"00:00","endTime":"7:30","startOffset":0,"endOffset":0,"x":670,"y":1820,"wires":[["3dfaa2791328604c","368805bbdb18eafe"],[]]},{"id":"119a22244439905d","type":"change","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"create message","rules":[{"t":"set","p":"message","pt":"msg","to":"\"You need to check your email for suspcious activity. Look for the email titled: \" & msg.title","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1860,"wires":[["fde614500f10c5c6"]]},{"id":"442c9ae2f1b2b21d","type":"OpenAI Chat","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"","token":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":170,"y":1800,"wires":[["153d49dc6dfaeff9"]]},{"id":"2465ce29a50c6d26","type":"OpenAI User","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"GPT analyze title","content":"Does the title indicate activity on my \naccount, or that my account is being \naccessed or my password is changing? \nRespond using the following JSON format \n{{\"isCompromised\": boolean}}","x":190,"y":1760,"wires":[["442c9ae2f1b2b21d"]]},{"id":"9ccb6d5078852ba1","type":"OpenAI System","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"Add title to system","instruction":"Email Title: {title}","x":190,"y":1720,"wires":[["2465ce29a50c6d26"]]},{"id":"153d49dc6dfaeff9","type":"OpenAI Response","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"","x":190,"y":1840,"wires":[["911afa4eb9f5ee93"]]},{"id":"911afa4eb9f5ee93","type":"change","z":"6161d870e25ec591","g":"b19b0bbc1566de4b","name":"simplify payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].args.response","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":1880,"wires":[["61b56e591c3cd0a7"]]},{"id":"228d3d53.df8e02","type":"server","name":"Home Assistant","addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

 
 

Event Summary

The JSON below contain the 4 levels seen in the video.

[{"id":"47b5d4c494ababd1","type":"ical-upcoming","z":"b9203c19c137b9ca","confignode":"e80d28315447b9e8","timeout":"0","timeoutUnits":"seconds","cron":"","name":"look at Michael/Oriana's calendar","offsettype":"","offset":"","offsetUnitstype":"","offsetUnits":"","eventtypes":"events","eventtypestype":"eventtypes","calendar":"","calendartype":"str","triggertype":"trigger","trigger":"always","timezone":"","timezonetype":"str","dateformat":"{ \"timeStyle\": \"short\", \"dateStyle\": \"short\" }","dateformattype":"json","language":"en","languagetype":"language","filterProperty":"summary","filterPropertytype":"filterProperty","filterOperator":"between","filterOperatortype":"filterOperator","filtertype":"str","filter2type":"str","filter2":"","filter":"","checkall":false,"endpreview":"","endpreviewUnits":"","previewtype":"num","preview":"16","previewUnitstype":"previewUnits","previewUnits":"hours","pastviewtype":"num","pastview":"","pastviewUnits":"days","pastviewUnitstype":"pastviewUnits","x":680,"y":200,"wires":[["e0553790276a2205"]]},{"id":"33e199e9dbcd3a3d","type":"api-render-template","z":"b9203c19c137b9ca","name":"Create task template","server":"228d3d53.df8e02","version":0,"template":"\nThe current time is {{now()}}\n{ \n  dishwasher: '{{ states('input_select.dishwasher_state') }}',\n  events: EVENTS,\n}\n\n","resultsLocation":"yaml","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":720,"y":160,"wires":[["47b5d4c494ababd1"]]},{"id":"bf6cfdd30acf53aa","type":"OpenAI System","z":"b9203c19c137b9ca","name":"","instruction":"You are a personal assistant that \nreminds me tasks and events. \n\nOnly mention the dishwasher if the state is dirty,\notherwise don't say anything about the dishwasher.\n\nOnly mention events the start date for that event is\nhappening within 24 hours of the current time.\nIf the event start date is in the past or if the event start date\nis more than 24 hours away, say nothing about it.\n\nWhenever you mention the date time, use the 12-hour human readable format.\n\nBelow is the current state of the dishwasher and list of upcoming events\n{yaml}","x":740,"y":280,"wires":[["75d40839f21a0ac9"]]},{"id":"eab7eb9b4d8b08a9","type":"OpenAI Chat","z":"b9203c19c137b9ca","name":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":750,"y":360,"wires":[["7dfb4aabd9e9eb58"]]},{"id":"e0553790276a2205","type":"function","z":"b9203c19c137b9ca","name":"merge Events","func":"\nconst events = msg.payload.map(event => {\n    const {summary, date} = event\n    \n    return {summary, date}\n})\n\nmsg.yaml = msg.yaml.replace(\"EVENTS\", `${JSON.stringify(events)}`)\n \nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[{"var":"Sugar","module":"sugar"}],"x":740,"y":240,"wires":[["bf6cfdd30acf53aa"]],"outputLabels":["Available Events"]},{"id":"75d40839f21a0ac9","type":"OpenAI User","z":"b9203c19c137b9ca","name":"","content":"Summarize the following events in a simple easy to understand way","x":750,"y":320,"wires":[["eab7eb9b4d8b08a9"]]},{"id":"7dfb4aabd9e9eb58","type":"OpenAI Response","z":"b9203c19c137b9ca","name":"","x":730,"y":400,"wires":[["5698c8cfe683481b"]]},{"id":"33d231df6b919864","type":"inject","z":"b9203c19c137b9ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":760,"y":120,"wires":[["33e199e9dbcd3a3d"]]},{"id":"5698c8cfe683481b","type":"debug","z":"b9203c19c137b9ca","name":"debug 151","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":440,"wires":[]},{"id":"1018a1a726ef5d0f","type":"api-render-template","z":"b9203c19c137b9ca","name":"Create task template","server":"228d3d53.df8e02","version":0,"template":"\nThe current time is {{now()}}\n{ \n  dishwasher: '{{ states('input_select.dishwasher_state') }}',\n  events: EVENTS,\n}\n\n","resultsLocation":"yaml","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1100,"y":200,"wires":[["6832d8b2c1874e9d"]]},{"id":"d801c7bec1d8db81","type":"OpenAI System","z":"b9203c19c137b9ca","name":"","instruction":"You are a personal assistant that \nreminds me tasks and events. \n\nOnly mention the dishwasher if the state is dirty,\notherwise don't say anything about the dishwasher.\n\nOnly mention events the start date for that event is\nhappening within 24 hours of the current time.\nIf the event start date is in the past or if the event start date\nis more than 24 hours away, say nothing about it.\n\nConvert any Dates you see written in ISO 8601 standard to Pacific Standard Time\nbefore you determine if it is within the 24 hour limit.\n\nWhenever you mention the date time, use the 12-hour human readable format.\n\nBelow is the current state of the dishwasher and list of upcoming events\n{yaml}","x":1120,"y":280,"wires":[["52d02354078e1b55"]]},{"id":"b4f4040a9684254d","type":"OpenAI Chat","z":"b9203c19c137b9ca","name":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":1130,"y":360,"wires":[["484dba7463fd40a0"]]},{"id":"6832d8b2c1874e9d","type":"function","z":"b9203c19c137b9ca","name":"merge Events","func":"\n\nmsg.yaml = msg.yaml.replace(\"EVENTS\", `${JSON.stringify(msg.payload.events)}`)\n \nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[{"var":"Sugar","module":"sugar"}],"x":1120,"y":240,"wires":[["d801c7bec1d8db81"]],"outputLabels":["Available Events"]},{"id":"52d02354078e1b55","type":"OpenAI User","z":"b9203c19c137b9ca","name":"","content":"Summarize the following events in a simple easy to understand way","x":1130,"y":320,"wires":[["b4f4040a9684254d"]]},{"id":"484dba7463fd40a0","type":"OpenAI Response","z":"b9203c19c137b9ca","name":"","x":1110,"y":400,"wires":[["1b469ca946112201"]]},{"id":"103c61c86fd3ce9e","type":"inject","z":"b9203c19c137b9ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1140,"y":120,"wires":[["fe28bbef5350bf99"]]},{"id":"1b469ca946112201","type":"debug","z":"b9203c19c137b9ca","name":"debug 152","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1130,"y":440,"wires":[]},{"id":"fe28bbef5350bf99","type":"api-call-service","z":"b9203c19c137b9ca","name":"","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"calendar","service":"list_events","areaId":[],"deviceId":[],"entityId":[],"data":"{\"duration\": \"24:00:00\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":1110,"y":160,"wires":[["1018a1a726ef5d0f"]]},{"id":"4b1cad8575098bac","type":"api-render-template","z":"b9203c19c137b9ca","name":"Create task template","server":"228d3d53.df8e02","version":0,"template":"\nThe current time is {{now()}}\n{ \n  dishwasher: '{{ states('input_select.dishwasher_state') }}',\n  events: EVENTS,\n  {% for state in states.sensor | sort(attribute='entity_id') | selectattr('entity_id', 'contains', 'battery' ) %}\n    {{state_attr(state.entity_id, 'friendly_name')}}:{{ state.state }},\n  {% endfor %}\n  {% for lights in expand(states.light) | selectattr('state','==','unavailable') %}\n    {{state_attr(lights.entity_id, 'friendly_name')}}:{{ lights.state }} \n  {% endfor %}\n}\n\n","resultsLocation":"yaml","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1480,"y":200,"wires":[["3a2b00d535ccab31"]]},{"id":"571803922575dead","type":"OpenAI System","z":"b9203c19c137b9ca","name":"","instruction":"You are a personal assistant that \nreminds me tasks and events. \n\nOnly mention the dishwasher if the state is dirty,\notherwise don't say anything about the dishwasher.\n\nOnly mention events the start date for that event is\nhappening within 24 hours of the current time.\nIf the event start date is in the past or if the event start date\nis more than 24 hours away, say nothing about it.\n\nConvert any Dates you see written in ISO 8601 standard to Pacific Standard Time\nbefore you determine if it is within the 24 hour limit.\n\nWhenever you mention the date time, use the 12-hour human readable format.\n\nOnly batteries at or below 10%. Say nothing about batteries if they are all above 10%.\n\nLastly, list any devices that are unavailable.\n\nBelow is the current state of the dishwasher and list of upcoming events\n{yaml}","x":1500,"y":280,"wires":[["566b3357d89c9615"]]},{"id":"f7b720d92e23716e","type":"OpenAI Chat","z":"b9203c19c137b9ca","name":"","tool_choice":"auto","token":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":1510,"y":360,"wires":[["b64ed43343bba82b"]]},{"id":"3a2b00d535ccab31","type":"function","z":"b9203c19c137b9ca","name":"merge Events","func":"\n// const events = msg.payload.events.map(event => {\n//     const {summary, start} = event\n    \n//     return {summary, start}\n// })\n\nmsg.yaml = msg.yaml.replace(\"EVENTS\", `${JSON.stringify(msg.payload.events)}`)\n \nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[{"var":"Sugar","module":"sugar"}],"x":1500,"y":240,"wires":[["571803922575dead"]],"outputLabels":["Available Events"]},{"id":"566b3357d89c9615","type":"OpenAI User","z":"b9203c19c137b9ca","name":"","content":"Summarize the following events in a simple easy to understand way","x":1510,"y":320,"wires":[["f7b720d92e23716e"]]},{"id":"b64ed43343bba82b","type":"OpenAI Response","z":"b9203c19c137b9ca","name":"","x":1490,"y":400,"wires":[["feea763c10518144"]]},{"id":"8a489dd580d343f6","type":"inject","z":"b9203c19c137b9ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1520,"y":120,"wires":[["42b821a233208e37"]]},{"id":"feea763c10518144","type":"debug","z":"b9203c19c137b9ca","name":"debug 153","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1510,"y":440,"wires":[]},{"id":"42b821a233208e37","type":"api-call-service","z":"b9203c19c137b9ca","name":"","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"calendar","service":"list_events","areaId":[],"deviceId":[],"entityId":[],"data":"{\"duration\": \"24:00:00\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":1490,"y":160,"wires":[["4b1cad8575098bac"]]},{"id":"930bdd8aad71b135","type":"comment","z":"b9203c19c137b9ca","name":"Level 2 ","info":"","x":710,"y":60,"wires":[]},{"id":"9b3decee1eb92d29","type":"comment","z":"b9203c19c137b9ca","name":"Level 2.5","info":"","x":1120,"y":60,"wires":[]},{"id":"90eb7586e5464dc8","type":"comment","z":"b9203c19c137b9ca","name":"Level 3","info":"","x":1490,"y":60,"wires":[]},{"id":"e29b898a6148b10d","type":"inject","z":"b9203c19c137b9ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1860,"y":100,"wires":[["6acb89d1a3e0d32c"]]},{"id":"6acb89d1a3e0d32c","type":"api-call-service","z":"b9203c19c137b9ca","name":"","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"todo","service":"get_items","areaId":[],"deviceId":[],"entityId":["todo.voicemail"],"data":"{\"status\":\"needs_action\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"todos","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":1840,"y":140,"wires":[["5be85dd404df0b7d"]]},{"id":"0f3dfe65a625a306","type":"api-render-template","z":"b9203c19c137b9ca","name":"Create task template","server":"228d3d53.df8e02","version":0,"template":"\nThe current time is {{now()}}\n{ \n  dishwasher: '{{ states('input_select.dishwasher_state') }}',\n  events: EVENTS,\n  todos: TODOS,\n  {% for state in states.sensor | sort(attribute='entity_id') | selectattr('entity_id', 'contains', 'battery' ) %}\n    {{state_attr(state.entity_id, 'friendly_name')}}:{{ state.state }},\n  {% endfor %}\n  {% for lights in expand(states.light) | selectattr('state','==','unavailable') %}\n    {{state_attr(lights.entity_id, 'friendly_name')}}:{{ lights.state }} \n  {% endfor %}\n}\n\n","resultsLocation":"yaml","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1820,"y":220,"wires":[["b43803c3c2c7bfdf"]]},{"id":"93a0345d158f07e7","type":"OpenAI System","z":"b9203c19c137b9ca","name":"","instruction":"You are a personal assistant that \nreminds me tasks and events. \n\nOnly mention the dishwasher if the state is dirty,\notherwise don't say anything about the dishwasher.\n\nOnly mention events the start date for that event is\nhappening within 24 hours of the current time.\nIf the event start date is in the past or if the event start date\nis more than 24 hours away, say nothing about it.\n\nConvert any Dates you see written in ISO 8601 standard to Pacific Standard Time\nbefore you determine if it is within the 24 hour limit.\n\nWhenever you mention the date time, use the 12-hour human readable format but don't mention\nwhat format it is in.\n\nOnly batteries at or below 10%. Say nothing about batteries if they are all above 10%.\n\nOnly mention todos who's \"due\" property date is today, yesterday or tomorrow.  \nOnly tell me the number of todos who's due date is more than 1 day old.\n\nDo not use any functions to complete your tasks.\n\nLastly, list any devices that are unavailable.\n\nBelow is the current state of the dishwasher and list of upcoming events\n{yaml}","x":1840,"y":300,"wires":[["4fcdec5734f161c4"]]},{"id":"75cfad24f34be4c5","type":"OpenAI Chat","z":"b9203c19c137b9ca","name":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":1850,"y":380,"wires":[["846e1e3ccbbb111b"]]},{"id":"b43803c3c2c7bfdf","type":"function","z":"b9203c19c137b9ca","name":"merge Events","func":"\n\nmsg.yaml = msg.yaml\n.replace(\"EVENTS\", `${JSON.stringify(msg.calendar.events)}`)\n    .replace(\"TODOS\", `${JSON.stringify(msg.todos[\"todo.voicemail\"].items)}`)\n \nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[{"var":"Sugar","module":"sugar"}],"x":1840,"y":260,"wires":[["93a0345d158f07e7"]],"outputLabels":["Available Events"]},{"id":"4fcdec5734f161c4","type":"OpenAI User","z":"b9203c19c137b9ca","name":"","content":"what should i know about?","x":1850,"y":340,"wires":[["75cfad24f34be4c5"]]},{"id":"846e1e3ccbbb111b","type":"OpenAI Response","z":"b9203c19c137b9ca","name":"","x":1830,"y":420,"wires":[["be58ca97d49391a1"]]},{"id":"be58ca97d49391a1","type":"debug","z":"b9203c19c137b9ca","name":"debug 154","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1850,"y":460,"wires":[]},{"id":"5be85dd404df0b7d","type":"api-call-service","z":"b9203c19c137b9ca","name":"","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"calendar","service":"list_events","areaId":[],"deviceId":[],"entityId":[],"data":"{\"duration\": \"24:00:00\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"calendar","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":1830,"y":180,"wires":[["0f3dfe65a625a306"]]},{"id":"2675f479dca1a02e","type":"comment","z":"b9203c19c137b9ca","name":"Level 4","info":"","x":1870,"y":60,"wires":[]},{"id":"49a20f10cd9ee8d6","type":"Register Intent","z":"b9203c19c137b9ca","name":"summarize_my_tasks","description":"creates a summary of all the tasks, events, todos and states of all the devices in the smart home","excludeFromOpenAi":true,"x":2300,"y":100,"wires":[["befe2b185ddb398c"]]},{"id":"befe2b185ddb398c","type":"change","z":"b9203c19c137b9ca","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"data","pt":"msg"},{"t":"delete","p":"template","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2320,"y":140,"wires":[["9574d5395bf6af71"]]},{"id":"0317d8d218a902b1","type":"inject","z":"b9203c19c137b9ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2120,"y":180,"wires":[["9574d5395bf6af71"]]},{"id":"9574d5395bf6af71","type":"api-call-service","z":"b9203c19c137b9ca","name":"","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"todo","service":"get_items","areaId":[],"deviceId":[],"entityId":["todo.voicemail"],"data":"{\"status\":\"needs_action\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"todos","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":2320,"y":180,"wires":[["1d771460db9b6aee"]]},{"id":"dd36a8fee09ba207","type":"api-render-template","z":"b9203c19c137b9ca","name":"Create task template","server":"228d3d53.df8e02","version":0,"template":"\nThe current time is {{now()}}\n{ \n  dishwasher: '{{ states('input_select.dishwasher_state') }}',\n  events: EVENTS,\n  todos: TODOS,\n  {% for state in states.sensor | sort(attribute='entity_id') | selectattr('entity_id', 'contains', 'battery' ) %}\n    {{state_attr(state.entity_id, 'friendly_name')}}:{{ state.state }},\n  {% endfor %}\n  {% for lights in expand(states.light) | selectattr('state','==','unavailable') %}\n    {{state_attr(lights.entity_id, 'friendly_name')}}:{{ lights.state }} \n  {% endfor %}\n}\n\n","resultsLocation":"yaml","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":2300,"y":260,"wires":[["c49cf917ed736d70"]]},{"id":"513e3847104eb84a","type":"OpenAI System","z":"b9203c19c137b9ca","name":"","instruction":"You are a personal assistant that \nreminds me tasks and events. \n\nOnly mention the dishwasher if the state is dirty,\notherwise don't say anything about the dishwasher.\n\nOnly mention events the start date for that event is\nhappening within 24 hours of the current time.\nIf the event start date is in the past or if the event start date\nis more than 24 hours away, say nothing about it.\n\nConvert any Dates you see written in ISO 8601 standard to Pacific Standard Time\nbefore you determine if it is within the 24 hour limit.\n\nWhenever you mention the date time, use the 12-hour human readable format but don't mention\nwhat format it is in.\n\nOnly batteries at or below 10%. Say nothing about batteries if they are all above 10%.\n\nOnly mention todos who's \"due\" property date is today, yesterday or tomorrow.  \nOnly tell me the number of todos who's due date is more than 1 day old.\n\nDo not use any functions to complete your tasks.\n\nLastly, list any devices that are unavailable.\n\nBelow is the current state of the dishwasher and list of upcoming events\n{yaml}","x":2320,"y":340,"wires":[["9bbee33a44b4ccca"]]},{"id":"9b900a1f96dc4258","type":"OpenAI Chat","z":"b9203c19c137b9ca","name":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":2330,"y":420,"wires":[["77290d07c15ec33b"]]},{"id":"c49cf917ed736d70","type":"function","z":"b9203c19c137b9ca","name":"merge Events","func":"\n\nmsg.yaml = msg.yaml\n.replace(\"EVENTS\", `${JSON.stringify(msg.calendar.events)}`)\n    .replace(\"TODOS\", `${JSON.stringify(msg.todos[\"todo.voicemail\"].items)}`)\n \nreturn msg\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[{"var":"Sugar","module":"sugar"}],"x":2320,"y":300,"wires":[["513e3847104eb84a"]],"outputLabels":["Available Events"]},{"id":"9bbee33a44b4ccca","type":"OpenAI User","z":"b9203c19c137b9ca","name":"","content":"what should i know about?","x":2330,"y":380,"wires":[["9b900a1f96dc4258"]]},{"id":"77290d07c15ec33b","type":"OpenAI Response","z":"b9203c19c137b9ca","name":"","x":2310,"y":460,"wires":[["c9802397259fca98"]]},{"id":"c9802397259fca98","type":"debug","z":"b9203c19c137b9ca","name":"debug 160","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2330,"y":500,"wires":[]},{"id":"1d771460db9b6aee","type":"api-call-service","z":"b9203c19c137b9ca","name":"","server":"228d3d53.df8e02","version":5,"debugenabled":false,"domain":"calendar","service":"list_events","areaId":[],"deviceId":[],"entityId":[],"data":"{\"duration\": \"24:00:00\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"calendar","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":2310,"y":220,"wires":[["dd36a8fee09ba207"]]},{"id":"5d676799fe86b6b8","type":"comment","z":"b9203c19c137b9ca","name":"Level 4.5","info":"","x":2360,"y":60,"wires":[]},{"id":"45899563cb233c22","type":"OpenAI System","z":"b9203c19c137b9ca","name":"","instruction":"You are a personal assistant that \nreminds me tasks and events. \n\nOnly mention the dishwasher if the state is dirty,\notherwise don't say anything about the dishwasher.\n\nOnly mention events the start date for that event is\nhappening within 24 hours of the current time.\nIf the event start date is in the past or if the event start date\nis more than 24 hours away, say nothing about it.\n\nConvert any Dates you see written in ISO 8601 standard to Pacific Standard Time\nbefore you determine if it is within the 24 hour limit.\n\nWhenever you mention the date time, use the 12-hour human readable format.\n\nBelow is the current state of the dishwasher and list of upcoming events\n\nThe current time is Jan 15, 2024 10:00pm\n{{ \n  dishwasher: 'dirty',\n  events: [{{\n    summary: \"soccer practice\"\n    date: \"1/15/24, 4:00 – 5:00 PM\"\n  }}, {{\n    summary: \"Physical Therapy\"\n    date: \"1/16/24, 1:30 – 2:30 PM\"\n  }},\n  {{\n    summary: \"Music Lessons\"\n    eventStart: \"1/15/24, 10:00 – 11:00 AM\"\n  }}]\n}}\n\n","x":340,"y":280,"wires":[["242c845a284645b1"]]},{"id":"24f1284f7f791988","type":"OpenAI Chat","z":"b9203c19c137b9ca","name":"","tool_choice":"auto","token":"","model":"gpt-4-1106-preview","temperature":0.7,"max_tokens":1200,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"x":350,"y":360,"wires":[["440c0ce969bafa8f"]]},{"id":"242c845a284645b1","type":"OpenAI User","z":"b9203c19c137b9ca","name":"","content":"Summarize the following events in a simple easy to understand way","x":350,"y":320,"wires":[["24f1284f7f791988"]]},{"id":"440c0ce969bafa8f","type":"OpenAI Response","z":"b9203c19c137b9ca","name":"","x":330,"y":400,"wires":[["48b2c1501e551cb8"]]},{"id":"4c2edb04cc18d458","type":"inject","z":"b9203c19c137b9ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":360,"y":240,"wires":[["45899563cb233c22"]]},{"id":"48b2c1501e551cb8","type":"debug","z":"b9203c19c137b9ca","name":"debug 150","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":350,"y":440,"wires":[]},{"id":"4ea12185d5ef3332","type":"comment","z":"b9203c19c137b9ca","name":"Level 1","info":"","x":330,"y":180,"wires":[]},{"id":"e80d28315447b9e8","type":"ical-config","url":"","caldav":"","caltype":"ical","name":"","replacedates":false,"usecache":false,"username":"","password":"","calendar":"","pastWeeks":"0","futureWeeks":"4"},{"id":"228d3d53.df8e02","type":"server","name":"Home Assistant","addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

SPECIAL NOTE: The Call Service node for the calendar events uses a deprecated method called "List Events". The method made it easy to demonstrate the code. However you will need to use the "Get Events" service. This will also require an update to the Merge Events node as the payload the Call Service returns will be slightly different.

Previous
Previous

Easily Use GPT in your automations with this plugin

Next
Next

ESPresence Automations