Inserting date/time into helper

I dont know if I am going about this the right way or not. What i want to accomplish is create a helper that lists the last time my lawn irrigation ran.

I have a date/time formatter node in node red, I created a date/time helper in HA.

Need help passing info from date/time formatter node to the date/time helper.

Or another way to accomplish. I am going to use this date/time to display one of my HA pages to let me know the last time it ran succefully.
I really just need the date. Time isnt neccessary. So if it last ran today, id like it to say 07-09-2022

image

[{"id":"396b48ed81afeec4","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"d5afa121b2b0b5d6","type":"moment","z":"396b48ed81afeec4","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Chicago","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"date","outputType":"msg","outTz":"America/Chicago","x":445,"y":255,"wires":[["d61203f30e53d3b3"]]},{"id":"ec46b45411227aba","type":"inject","z":"396b48ed81afeec4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":225,"y":255,"wires":[["d5afa121b2b0b5d6"]]},{"id":"929b87b9547de87f","type":"debug","z":"396b48ed81afeec4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":920,"y":255,"wires":[]},{"id":"d61203f30e53d3b3","type":"api-call-service","z":"396b48ed81afeec4","name":"Set date/time helper","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_datetime","service":"set_datetime","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":695,"y":255,"wires":[["929b87b9547de87f"]]},{"id":"ab3e2c53.e3491","type":"server","name":"AvilaSmartHome","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

This should work, but you need to correct the entity, which seemed to be missing in your flow.
There probably is a way to actually do the calculation directly in the call service node, so you could skip the function node entirely, but I have not done that so much myself, so was struggling a bit with it.

[{"id":"ec46b45411227aba","type":"inject","z":"396b48ed81afeec4","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":215,"y":255,"wires":[["4bfe6a4e074f9075"]]},{"id":"929b87b9547de87f","type":"debug","z":"396b48ed81afeec4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":920,"y":255,"wires":[]},{"id":"d61203f30e53d3b3","type":"api-call-service","z":"396b48ed81afeec4","name":"Set date/time helper","server":"ab3e2c53.e3491","version":5,"debugenabled":false,"domain":"input_datetime","service":"set_datetime","areaId":[],"deviceId":[],"entityId":["input_datetime.bedroom_vacation_date"],"data":"{\"timestamp\": msg.payload }","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":685,"y":255,"wires":[["929b87b9547de87f"]]},{"id":"4bfe6a4e074f9075","type":"function","z":"396b48ed81afeec4","name":"Today","func":"msg.payload = (Date.now().toString()).substring(0,10);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":255,"wires":[["d61203f30e53d3b3"]]},{"id":"ab3e2c53.e3491","type":"server","name":"AvilaSmartHome","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]
1 Like

If you want to use the output from a trigger node or event state, set the field to jsonata and use
$now('[Y0001]-[M01]-[D01] [H01]:[m01]:[s01]')

What am I doing wrong here?

image

Use json instead with

{
    "datetime": "{{payload}}"
}

No go.

image

The J: first in the data field indicate its a J Expression.
You need {} there for it to be a JSON.

image

[{"id":"931452251ac8ec38","type":"inject","z":"91a80f99.6180e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":756,"y":192,"wires":[["6ddd922795fac8ef"]]},{"id":"6ddd922795fac8ef","type":"api-call-service","z":"91a80f99.6180e","name":"","server":"","version":5,"debugenabled":false,"domain":"input_datetime","service":"set_datetime","areaId":[],"deviceId":[],"entityId":["input_datetime.test"],"data":"{\"timestamp\": $millis() / 1000 }\t","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":972,"y":192,"wires":[[]]}]
2 Likes

That is nearly the most optimal solution.
You could just delete the 2 msg.parts in the inject to get it perfect. :slight_smile:

Thank you!