This works fine if I call the service directly from HA and it creates a file with timestamp but from node red it doesnt take the timestamp into account and creates bedroom.jpg as the file name. what am I missing?
This part of the syntax is python specific, it evaluates the current date time into a yyyy-mm-dd-hhmmss syntax. So you’ll need to replace that part by something that works in JavaScript/Node-RED. The double braces syntax here is specifically to the Jinja2 library in Python. Note that this might execute in JavaScript as Mustache, however the syntax that follows is meant for Python/Jinja2.
@afelix Looking around it seems it isnt straight forward to specify a datetime within json , can you give me some pointers please.
I could do a new date , format it and return if it was a function but not sure how to do it within a json string
var now = new Date();
// Create formatted time
var yyyy = now.getFullYear();
var mm = now.getMonth() < 9 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based
var dd = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
var hh = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
var mmm = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
var ss = now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
// file path with / at the end
var path = "/home/pi/node-red-static/"; // This is the path
var filename = "cam3_"+yyyy+mm+dd+"-"+hh+mm+ss+".jpg"; // file name
Thanks @edje11 , I was hoping to put something within the Data field of the call service node but then I can always include a function node before that and pass on the filename as an input to the call service node. Thanks
This is great but I still have a question. After constructing this file name I need to use the Cal, Service Snapshot node. How do I pass on the path and filename in my filename definition in this node ?
So the standard is :
{
"filename": "/config/www/somefilename.jpg"
}
How can I modify this and use var path and filename here ?