Skip to content

Instantly share code, notes, and snippets.

@skylord123
Created April 22, 2025 16:03
Show Gist options
  • Save skylord123/d6db72f39898723c6769d33342d87a7c to your computer and use it in GitHub Desktop.
Save skylord123/d6db72f39898723c6769d33342d87a7c to your computer and use it in GitHub Desktop.
node-red-pebble-timeline: Reminder to feed doggo
[{"id":"14338f6e58ce5717","type":"group","z":"pebble-boot-flow","name":"Reminder to feed doggo every day at 6:30PM","style":{"label":true},"nodes":["557116a85f07911b","e6a10e8e69a36faf","4f9584170c460bda","154f80960cd8b1cb","f65f21a1a468c49a","3cf9ac67fd60db28"],"x":94,"y":1799,"w":792,"h":142},{"id":"557116a85f07911b","type":"pebble-timeline-add","z":"pebble-boot-flow","g":"14338f6e58ce5717","name":"","config":"c94cbbf4395a9abe","apiUrl":"null","apiUrlType":"msg","token":"null","tokenType":"msg","pinId":"payload.id","pinIdType":"msg","time":"payload.time","timeType":"msg","duration":"payload.duration","durationType":"msg","layoutType":"genericPin","title":"topic","titleType":"msg","subtitle":"payload.subtitle","subtitleType":"msg","body":"payload.body","bodyType":"msg","tinyIcon":"payload.tinyIcon","tinyIconType":"msg","smallIcon":"payload.smallIcon","smallIconType":"msg","largeIcon":"payload.largeIcon","largeIconType":"msg","primaryColor":"payload.primaryColor","primaryColorType":"msg","secondaryColor":"payload.secondaryColor","secondaryColorType":"msg","backgroundColor":"payload.backgroundColor","backgroundColorType":"msg","createNotification":false,"updateNotification":false,"headings":"null","headingsType":"jsonata","paragraphs":"null","paragraphsType":"jsonata","lastUpdated":"null","lastUpdatedType":"jsonata","createNotificationTitle":"payload.createNotification.title","createNotificationTitleType":"msg","createNotificationBody":"payload.createNotification.body","createNotificationBodyType":"msg","createNotificationTinyIcon":"payload.createNotification.tinyIcon","createNotificationTinyIconType":"msg","updateNotificationTime":"payload.updateNotification.time","updateNotificationTimeType":"msg","updateNotificationTitle":"payload.updateNotification.title","updateNotificationTitleType":"msg","updateNotificationBody":"payload.updateNotification.body","updateNotificationBodyType":"msg","updateNotificationTinyIcon":"payload.updateNotification.tinyIcon","updateNotificationTinyIconType":"msg","locationName":"payload.locationName","locationNameType":"msg","shortTitle":"payload.shortTitle","shortTitleType":"msg","shortSubtitle":"payload.shortSubtitle","shortSubtitleType":"msg","displayTime":"pin","rankAway":"payload.rankAway","rankAwayType":"msg","rankHome":"payload.rankHome","rankHomeType":"msg","nameAway":"payload.nameAway","nameAwayType":"msg","nameHome":"payload.nameHome","nameHomeType":"msg","recordAway":"payload.recordAway","recordAwayType":"msg","recordHome":"payload.recordHome","recordHomeType":"msg","scoreAway":"payload.scoreAway","scoreAwayType":"msg","scoreHome":"payload.scoreHome","scoreHomeType":"msg","sportsGameState":"pre-game","reminders":true,"reminderData":"payload.reminders","reminderDataType":"msg","actions":false,"actionData":"payload.actions","actionDataType":"msg","x":610,"y":1840,"wires":[["3cf9ac67fd60db28"]]},{"id":"e6a10e8e69a36faf","type":"inject","z":"pebble-boot-flow","g":"14338f6e58ce5717","name":"","props":[],"repeat":"","crontab":"00 04 * * *","once":false,"onceDelay":0.1,"topic":"","x":190,"y":1840,"wires":[["4f9584170c460bda"]]},{"id":"4f9584170c460bda","type":"function","z":"pebble-boot-flow","g":"14338f6e58ce5717","name":"Build Reminders","func":"// Configuration - Set dog dinner time here (24-hour format)\nconst DOG_DINNER_TIME = \"18:30\";\n\n// Function to format date as MM-DD-YYYY\nfunction formatDate(date) {\n const month = String(date.getMonth() + 1).padStart(2, '0');\n const day = String(date.getDate()).padStart(2, '0');\n const year = date.getFullYear();\n return `${month}-${day}-${year}`;\n}\n\n// Parse the dinner time\nconst [hours, minutes] = DOG_DINNER_TIME.split(':').map(Number);\n\n// Get current date and time\nconst now = new Date();\nconst currentHour = now.getHours();\nconst currentMinute = now.getMinutes();\n\n// Count how many reminders we've sent\nlet remindersSent = 0;\nconst remindersNeeded = 3;\n\n// Create reminders for the next several days (until we have 3)\nfor (let i = 0; remindersSent < remindersNeeded; i++) {\n // Create a new date object for each day\n const reminderDate = new Date(now);\n reminderDate.setDate(now.getDate() + i);\n\n // Set the reminder time to the configured dinner time\n reminderDate.setHours(hours);\n reminderDate.setMinutes(minutes);\n reminderDate.setSeconds(0);\n reminderDate.setMilliseconds(0);\n\n // If it's today and the time has already passed, skip this day\n if (i === 0 &&\n (currentHour > hours || (currentHour === hours && currentMinute >= minutes))) {\n continue;\n }\n\n // Create a unique ID using the formatted date\n const formattedDate = formatDate(reminderDate);\n const uniqueId = `feed-aggie-${formattedDate}`;\n\n // Create a new message using RED.util.cloneMessage\n const newMsg = RED.util.cloneMessage(msg);\n newMsg.topic = 'Feed Aggie';\n newMsg.payload = {\n id: uniqueId,\n time: reminderDate.toISOString(),\n tinyIcon: \"system://images/NOTIFICATION_GENERIC\"\n };\n\n // Send the message\n node.send(newMsg);\n\n // Increment our counter\n remindersSent++;\n}\n\n// Return null to prevent the original message from being passed through\nreturn null;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":1840,"wires":[["557116a85f07911b"]]},{"id":"154f80960cd8b1cb","type":"catch","z":"pebble-boot-flow","g":"14338f6e58ce5717","name":"","scope":["557116a85f07911b"],"uncaught":false,"x":630,"y":1900,"wires":[["f65f21a1a468c49a"]]},{"id":"f65f21a1a468c49a","type":"debug","z":"pebble-boot-flow","g":"14338f6e58ce5717","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":1900,"wires":[]},{"id":"3cf9ac67fd60db28","type":"debug","z":"pebble-boot-flow","g":"14338f6e58ce5717","name":"debug 14","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":1840,"wires":[]},{"id":"c94cbbf4395a9abe","type":"pebble-timeline-config","name":"Rebble - Home Assistant","apiUrl":"https://timeline-api.rebble.io"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment