I have a short flow to trigger a camera entity snapshot service and would like to append the date/time to the filename so it does not get overwritten everytime.
I used the Developer Tools to create the string and I see it working:
I am now trying to move it to my flow in NodeRed, but for some reason, it is not working. I understand that the expression would need to change for JSON, but I have not been able to get it to work yet.
I even tried using {{payload}} instead of now()… but I get a blank string, so my filename is Snapshot_.jpg
This is my flow:
So the output of the inject node is msg.payload = timestamp.
But the service node does not seem to retrieve it and append it to the filename.
I also tried using $now(), etc…
This is my current JSONata expression: "filename":"/share/{{ entity_id.name }}/Snapshot_{{ payload }}.jpg"
I am not familiar with JSON, so any help on the syntax or even on the approach would help. I just need to have a unique filename for each picture, and in chronological order, so cannot be random. I will be using the images saved to create a timelapse GIF (which I still have not figured out, but part of the learning journey).
I got the file working with the timestamp appended at the end. Now I lost access to the {{ entity_id.name }}.
So the test I did:
If I use jsonata, I get access to the entity_id.name and not the payload.
If I used js, I can use payload but not the entity_id.name
If I use json and check the box for Use Alternative Template… shown in the picture, I get access to entity_id.name, but not payload.
Looks like the two do not work together. Any thoughts?
You have to use the message position, is the entity_id coming in msg.entity_id.name. You could also try triple brackets if it’s already coming in as msg.entity_id.name
I’m not sure how to do that. If the entity_id is not dynamic and doesn’t change, why not use the actual name?
You can set up a call service to have a dynamic entity field. Meaning if I have multiple cameras and I use their motion events to call a snapshot. The motion event will have the camera entity and in the entity field of the call service node you can use {{msg.path.to.camera}} and then use it again in the data field.
E. If you’re goal is to get the timestamp, you will likely have to manipulate the message that you use as a trigger. Meaning the timestamp will likely be an attribute and have to be moved to the msg.payload position.
btw have you tried {{ entity_id }} or {{{ entity_id }}}
@Mikefila, your comment about the entity_id not being dynamic triggered me to go down a path which led to a solution. If the entity_id was not dynamic, then let me make it do and then use it…here is the solution. Thanks!
Tried the {{{ }}} and no luck. So I went off and created a workaround. Not sure if it is a workaround r the best way to do it, but it works.
OK, just to make sure I have it here in case someone else is trying for the same thing, let me show the details.
I realized I wanted a timestamp format for the Date, so I added a Change node to replace time with timestamp.
Then in the service node, I created this filename path: