How to trigger based on entity time in Node Red

Hi All,

This might be a simple question but I am really struggling to find the right search terms to find an answer, so I am hoping someone can point me in the right direction.

I am new to both Home Assistant and Node Red and I have just started using Node Red for my HA automations. Its awesome!

I want to understand how I can use node red to run a sequence at a time specified in an entity. I have created some helpers in HA that allow me to specify time variables that I use to trigger automations. I am using a value template in HA automations to trigger the automation when the current time equals the helper time.

My question is, how would I achieve the same thing in Node Red?

You can achieve this a few ways.

But one way I would do this is using node-red-contrib-cron-plus.

You can set a time by injecting a message into the Cron node.

It also has built in examples (use the node red import menu) demonstrating most of its features.

There is a dashboard demo I did showing how you might achieve it.

Hi Steve-Mcl,

Thanks for the reply! I have been taking a look at your suggestion today but to be honest I'm finding it a little hard to follow.... I'm really a novice. Are you able to give me a few pointers in the right direction for how I could use cron-plus for this?

I also was tinkering with this flow (included below) last night but unfortunately, I couldn't get it to work. I am not sure if I am on the right track with this approach, but any feedback would be appreciated.

Thanks for your help.

[{"id":"792130b3.d1564","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8f4623af.41fff","type":"inject","z":"792130b3.d1564","name":"","props":[{"p":"payload"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":160,"wires":[["a8f66c20.b0e9f"]]},{"id":"2ca077b6.619ef8","type":"poll-state","z":"792130b3.d1564","name":"","server":"666b1cf9.686414","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"1","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"input_datetime.graterontime","state_type":"str","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":210,"y":260,"wires":[["36875f48.dc894"]]},{"id":"1ea04f7b.6df4e1","type":"function","z":"792130b3.d1564","name":"","func":"var trueMsg = {payload: \"true\"};\nvar falseMsg = {payload: \"false\"};\n\nif('msg.currentTime' == 'msg.triggerTime') {\n   return [ trueMsg ];\n} else {\n   return [ falseMsg ];\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":200,"wires":[["a67a8f29.4ee33"]]},{"id":"a67a8f29.4ee33","type":"debug","z":"792130b3.d1564","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":970,"y":200,"wires":[]},{"id":"a8f66c20.b0e9f","type":"simpletime","z":"792130b3.d1564","name":"","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":true,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":350,"y":160,"wires":[["102a4d7c.bcbf03"]]},{"id":"9c5ae0f.88cf22","type":"debug","z":"792130b3.d1564","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"currentTime","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":100,"wires":[]},{"id":"9b4b3075.55fa5","type":"debug","z":"792130b3.d1564","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"triggerTime","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":320,"wires":[]},{"id":"36875f48.dc894","type":"change","z":"792130b3.d1564","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"triggerTime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":260,"wires":[["9b4b3075.55fa5","1ea04f7b.6df4e1"]]},{"id":"102a4d7c.bcbf03","type":"change","z":"792130b3.d1564","name":"","rules":[{"t":"move","p":"mytimes","pt":"msg","to":"currentTime","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":160,"wires":[["1ea04f7b.6df4e1","9c5ae0f.88cf22"]]},{"id":"666b1cf9.686414","type":"server","z":"","name":"Home Assistant","addon":true}]

Have you looked at the NR red Add-on for HA that presents webhooks and entitiy states/reflections ?

Have a look at this thread

Its a long read but well worthwhile - lots of good examples and explanation of how he hooks entity states and changes etc

Craig

Thanks Craig! I’ll check it out.

Thanks for your time @Steve-Mcl and @craigcurtin. I also received some advice from the HA community on this issue and this ended up being the best solve for me.

Thanks for your assistance, I really appreciate it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.