Hey everyone! I’ve been working on a garage door reminder system using Node-RED, and I wanted to share my journey and solution in case others are facing similar challenges. The goal was to send push notifications that include the time the garage door was opened, using msg.open_since in the notification string. Initially, I struggled with getting the time to display correctly, but here’s how I sorted it out!
First, I confirmed that msg.open_since was holding the correct time value by using debug nodes. It was there, but I couldn’t get it to appear in the notification string. I tried various syntaxes and even passed the time as a payload, but nothing worked until I found the right approach.
The key was to structure the JSON payload correctly. I realized that using double curly braces {{ }} around the variable wasn’t the right syntax in this context. Instead, I needed to ensure that the variable was properly referenced within the JSON object. Here’s the working setup:
javascript
{
“data”: {
“message”: "Garage door has been open since " + msg.open_since + “.”,
“actions”: [
{
“action”: “close_garage”,
“title”: “Close Door”
},
{
“action”: “stop_garage_loop”,
“title”: “Stop Alerts”
}
],
“tag”: “garage_reminder”
}
}
By concatenating the string with msg.open_since, the time displays perfectly in the notification. This setup also allows for clear actions to close the door or stop the alerts, making it user-friendly.
I hope this helps anyone else trying to incorporate dynamic data into their Node-RED notifications. It was a bit of a puzzle, but breaking it down step by step made it manageable. Happy coding! ![]()