Formatting Time for timer input

My problem seems similar to some I have read on this forum but despite all of my reading here and on the web the final answer still eludes me. As many others here my programming skills are minimal as I am a hardware guy trying to stretch my wings a little. I have a text input set to time input running into a moment node which then runs into an eztimer node. When I format the time "correctly" the input is ignored as unsupported input. When I get the payload to payload.ontime or payload.duration it gives me an error of cannot read undefined property. So there actually are two problems or one with two issues. I know I have a problem with JSON string or object and changing the payload from payload to payload.ontime but despite all my reading and research I still haven't found the magic bullet. There are posts that say use a JSON node or use this notation but again, it still hasn't been dumbed down to a level I can comprehend. As this is my first post I have a flow and the rest but not sure how to post that if it is needed. Anyone take pity on a poor dumb noob and help?

1 Like

Welcome to Node-RED and remember we were all beginers at one point.

It is easy to post a flow and even a thread explaining how to insert it (to export it go to the hamburger menu and select export and copy it to paste into a flow)

Since you have determined it s actually rwo issues, explain each seperately and make sure - when using other than the base nodes - to give the full node name like node-red-contrib-moment etc.

[{"id":"8bd933ba.a5d5","type":"tab","label":"unused","disabled":false,"info":""},{"id":"7384352b.3597a4","type":"ui_text_input","z":"8bd933ba.a5d5","name":"","label":"","tooltip":"","group":"7264bb7c.9a78f4","order":3,"width":0,"height":0,"passthru":true,"mode":"time","delay":300,"topic":"","x":140,"y":140,"wires":[["755596e0.e031e8"]]},{"id":"755596e0.e031e8","type":"moment","z":"8bd933ba.a5d5","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Denver","adjAmount":"7","adjType":"hours","adjDir":"add","format":"","locale":"en_US","output":"","outputType":"msg","outTz":"America/Denver","x":360,"y":140,"wires":[["55f71841.f27c9"]]},{"id":"55f71841.f27c9","type":"eztimer","z":"8bd933ba.a5d5","name":"","autoname":"17:00 - dusk","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"50.30","lon":"116.02","timerType":"1","startupMessage":true,"ontype":"2","ontimesun":"dawn","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"2","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":false,"tue":false,"wed":false,"thu":false,"fri":false,"sat":false,"sun":false,"x":630,"y":140,"wires":[[]]},{"id":"7264bb7c.9a78f4","type":"ui_group","z":"","name":"Default","tab":"c3f57b34.668908","disp":true,"width":"6","collapse":false},{"id":"c3f57b34.668908","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Text input node set to time picker, moment node to format time and eztimer,
So... here is the basic flow minus all the different things I've tried. Which include a change node to try to set a JSON message, a function node to set the payload from payload to payload.ontime various other nodes I've tried in desparation. When I debug the input node I get a good formatted output of time. If I debug the moment node I get a nice formatted output of time but in payload not payload.ontime where it needs to be. When I send the output directly to eztimer like in this flow it says unsupported input. If I change the payload to payload.ontime it says undefined input and throws an error. Rather than set the days and time in the programmer I am trying to set them programmatically from the dashboard. Eventually setting the days, duration, ontimes etc. from the dashboard. If I can get this one piece to work I feel confident I can get the rest. I can set the days from the dashboard with a switch so I didn't include that part in the flow as it was working. Please let me know if there is anything else you need.
And thank you for the kind response.

forgot to say the node names
node-red-contrib-eztimer
node-red-contrib-moment
text input from the dashboard section

[{"id":"8bd933ba.a5d5","type":"tab","label":"unused","disabled":false,"info":""},{"id":"7384352b.3597a4","type":"ui_text_input","z":"8bd933ba.a5d5","name":"","label":"","tooltip":"","group":"7264bb7c.9a78f4","order":4,"width":0,"height":0,"passthru":true,"mode":"time","delay":300,"topic":"","x":140,"y":140,"wires":[["755596e0.e031e8","b5bbb500.233ab8"]]},{"id":"755596e0.e031e8","type":"moment","z":"8bd933ba.a5d5","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Denver","adjAmount":"7","adjType":"hours","adjDir":"add","format":"HH:mm:ss","locale":"en_US","output":"","outputType":"msg","outTz":"America/Denver","x":360,"y":140,"wires":[["55f71841.f27c9","7997c0b2.faf1e"]]},{"id":"55f71841.f27c9","type":"eztimer","z":"8bd933ba.a5d5","name":"","autoname":"17:00 - dusk","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"50.30","lon":"116.02","timerType":"1","startupMessage":true,"ontype":"2","ontimesun":"dawn","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"2","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":false,"tue":false,"wed":false,"thu":false,"fri":false,"sat":false,"sun":false,"x":630,"y":140,"wires":[[]]},{"id":"b5bbb500.233ab8","type":"debug","z":"8bd933ba.a5d5","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":300,"y":220,"wires":[]},{"id":"7997c0b2.faf1e","type":"debug","z":"8bd933ba.a5d5","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":220,"wires":[]},{"id":"7264bb7c.9a78f4","type":"ui_group","z":"","name":"Default","tab":"c3f57b34.668908","disp":true,"width":"6","collapse":false},{"id":"c3f57b34.668908","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]`Preformatted text`

The first flow had a few pieces missing so I posted a more accurate flow

In the last one you didn't copy the entire flow, it's missing something and can't be imported.
On the export one of the tabs is 'Current tab' which will grab all nodes in the tab.

[{"id":"8bd933ba.a5d5","type":"tab","label":"unused","disabled":false,"info":""},{"id":"7384352b.3597a4","type":"ui_text_input","z":"8bd933ba.a5d5","name":"","label":"","tooltip":"","group":"7264bb7c.9a78f4","order":4,"width":0,"height":0,"passthru":true,"mode":"time","delay":300,"topic":"","x":140,"y":140,"wires":[["755596e0.e031e8","b5bbb500.233ab8"]]},{"id":"755596e0.e031e8","type":"moment","z":"8bd933ba.a5d5","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Denver","adjAmount":"7","adjType":"hours","adjDir":"add","format":"HH:mm:ss","locale":"en_US","output":"","outputType":"msg","outTz":"America/Denver","x":360,"y":140,"wires":[["55f71841.f27c9","7997c0b2.faf1e"]]},{"id":"55f71841.f27c9","type":"eztimer","z":"8bd933ba.a5d5","name":"","autoname":"17:00 - dusk","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"50.30","lon":"116.02","timerType":"1","startupMessage":true,"ontype":"2","ontimesun":"dawn","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"2","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":false,"tue":false,"wed":false,"thu":false,"fri":false,"sat":false,"sun":false,"x":630,"y":140,"wires":[[]]},{"id":"b5bbb500.233ab8","type":"debug","z":"8bd933ba.a5d5","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":300,"y":220,"wires":[]},{"id":"7997c0b2.faf1e","type":"debug","z":"8bd933ba.a5d5","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":220,"wires":[]},{"id":"7264bb7c.9a78f4","type":"ui_group","z":"","name":"Default","tab":"c3f57b34.668908","disp":true,"width":"6","collapse":false},{"id":"c3f57b34.668908","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

here,
So also to elaborate on the problem the output from debug 2 is a nice formatted time which the eztimer doesn't like because it has the wrong payload name. If I can get the output from the moment into payload.ontime I think I'm golden.

If I can get the output from the moment into payload.ontime I think I'm golden
well since the moment node puts the data in msg.payload, you should look at this thread:
Using template node and mustache syntax simply

This is the point where I have to admit I'm a little thick. I see the template node and obviously can paste the code into it but questions remain. I can play a little more with it, and I have to admit this is one thread I did miss, but if I change payload into payload.ontime will it change the payload name and I'm not sure how to get the payload into the answer. There's a lot of info in there, do I just erase all that and put in payload? I will play but I'd like to reserve the option to come back here and ask questions.

ok, so here's where I am at. I leave the node in mustache template format and enter {payload.ontime:payload} in the template and get a weird payload. If I set the msg.payload.ontime in the node I get a time out but in the payload not payload.ontime. the example they give is fairly complex to me so I'm having trouble sorting out exactly what the template doing to information, not to mention how are they getting the info into it.

Googled mustache template and read the node-red doc on it. Next question, I use triple {{{}}} around it and use just payload, {{{payload}}} and I get an output formatted correctly but delivered as payload not payload.ontime, Setting the property to msg.payload.ontime doesn't seem to change it to my desired payload. Will this node change the property to payload.ontime and if so what am I missing?
thanks

One more thing I just noticed. In the debug it says the template node ouputs an object and the moment node outputs a string. That's a step in the right direction?

Yes that is part of the problem. The moment node sets msg.payload to a string but you need it to be an object. Here is one way: Use a change node to do it for you;

[{"id":"97319a6c.62dd98","type":"change","z":"c5e6332e.1e834","name":"","rules":[{"t":"set","p":"ontime","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.ontime","pt":"msg","to":"ontime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":180,"wires":[["748f39ee.2d0fc8","469a0f51.9962e"]]}]

are you sure?????

oops, typo

duh (head slap) fixed - I blame it in too little sleep, failing to get 2 1/2 yr old granddaughter to take a nap (I so wanted one) and sinus infection. Yeah thats my excuse and I'm sticking with it!

and

It's two mustaches not one or 3 (3 is just for special web type cases)

{{payload}} will give what is in msg.payload
{{payload.ontime}} will give what is in msg.payload.ontime

[{"id":"8bd933ba.a5d5","type":"tab","label":"unused","disabled":false,"info":""},{"id":"7384352b.3597a4","type":"ui_text_input","z":"8bd933ba.a5d5","name":"","label":"","tooltip":"","group":"7264bb7c.9a78f4","order":4,"width":0,"height":0,"passthru":true,"mode":"time","delay":300,"topic":"","x":100,"y":120,"wires":[["755596e0.e031e8","b5bbb500.233ab8"]]},{"id":"755596e0.e031e8","type":"moment","z":"8bd933ba.a5d5","name":"","topic":"","input":"","inputType":"msg","inTz":"America/Denver","adjAmount":"7","adjType":"hours","adjDir":"add","format":"HH:mm:ss","locale":"en_US","output":"","outputType":"msg","outTz":"America/Denver","x":320,"y":120,"wires":[["7997c0b2.faf1e","dda2d518.8524d"]]},{"id":"55f71841.f27c9","type":"eztimer","z":"8bd933ba.a5d5","name":"","autoname":"17:00 - dusk","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"50.30","lon":"116.02","timerType":"1","startupMessage":true,"ontype":"2","ontimesun":"dawn","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":1,"onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"2","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":false,"tue":false,"wed":false,"thu":false,"fri":false,"sat":false,"sun":false,"x":1010,"y":120,"wires":[[]]},{"id":"b5bbb500.233ab8","type":"debug","z":"8bd933ba.a5d5","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":260,"y":200,"wires":[]},{"id":"7997c0b2.faf1e","type":"debug","z":"8bd933ba.a5d5","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":200,"wires":[]},{"id":"17c01a3a.61e4c6","type":"debug","z":"8bd933ba.a5d5","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":200,"wires":[]},{"id":"dda2d518.8524d","type":"template","z":"8bd933ba.a5d5","name":"Format","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","output":"str","x":560,"y":120,"wires":[["14064ae1.505bdd","17c01a3a.61e4c6"]]},{"id":"c078076f.473a8","type":"debug","z":"8bd933ba.a5d5","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":990,"y":200,"wires":[]},{"id":"14064ae1.505bdd","type":"change","z":"8bd933ba.a5d5","name":"Payload to ontime","rules":[{"t":"set","p":"ontime","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.ontime","pt":"msg","to":"ontime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":120,"wires":[["55f71841.f27c9","c078076f.473a8"]]},{"id":"7264bb7c.9a78f4","type":"ui_group","z":"","name":"Default","tab":"c3f57b34.668908","disp":true,"width":"6","collapse":false},{"id":"c3f57b34.668908","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

So here is the flow I come up with, it doesn't generate any error messages but I'm not sure the timer is being set without more work. So for the time being I'm going with a victory. On a side note, that change node seems to take a lot of work but I follow what's going on.

The moment node will output to ANY msg property you like:

image

It will also take its input from any msg property.

If you want to output to a deeper property, I think that the higher level property needs to exist first. So you can create msg.payload as an object with a change node and then output to msg.payload.ontime directly.

Oh, I think I may have just found a bug in the moment node :blush:

Trying some outputs to different properties doesn't give the expected results.

I take that back. It is just that the input msg.payload is left on the output msg.payload if you change moment's output to a different property.

However, I was in the previous post that trying to output to msg.payload.ontime won't work since msg.payload is already set to a value. If it were set to an object, it would work:

image

[{"id":"b4d7d4f6.c46028","type":"inject","z":"23e2fc82.499784","name":"Test with payload as object","topic":"Test with payload as object","payload":"{\"in\":\"2019-05-25T15:30:42.526+00:00\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":180,"wires":[["7ad7a844.982ee8"]]},{"id":"7ad7a844.982ee8","type":"moment","z":"23e2fc82.499784","name":"","topic":"","input":"payload.in","inputType":"msg","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"en_GB","output":"payload.ontime","outputType":"msg","outTz":"Europe/London","x":580,"y":180,"wires":[["a2945ad9.85ee88"]]},{"id":"a2945ad9.85ee88","type":"debug","z":"23e2fc82.499784","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":180,"wires":[]}]