Use variable for inject time


Hey all, I want to make an alarm clock and need to trigger it at a certain time, but set that time in Home-Assistant. So using the inject node, how can I dynamically set the time with a variable etc.



Probably better on the home-assistant forum - we really need to know what functionality you are planning to have in HA and what in Node-red.

As a simple answer - capture the time set in HA and send it across as an MQTT string, parse that string and store it as a Flow/Global variable (as appropriate)

Run a flow to check that variable every minute and then act if it is equal to the current time




Yeah I know I can achieve that logic, I'm not sure if I'd go down that route or just stick with manually setting it in node-red. I'm all about minimising setup at the minute and this get's rid of a lot of code I have in HA.

The question is more node-red based though. Yes I can get an update from HA to update a flow variable. The question is, is there syntax to be able to use that directly in the inject node rather than having to query and compare every minute. It just seems running it 1440 a day is a bit overkill just for that one time it needs to fire. Or is this just something I shouldn't worry about as it's such a small query.



If you are gfoing to run it at a certian time each day, you can configure the inject node to run at a specific time and date.



If I understand correctly, you want to:

  • set the alarm time in HA
  • have the alarm execute in NR
  • have the alarm fire just once a day

Instead of using an inject node, you might take a look at node-red-contrib-schedex. The time sent from HA can be used to program it, as in this flow. (I've added stuff to make it act more like an alarm clock. :slightly_smiling_face:)

[{"id":"6d19fa46.1a46bc","type":"schedex","z":"303954f6.eff9ac","name":"alarm clock","suspended":false,"lat":"38.897517","lon":"-77.036542","ontime":"","ontopic":"","onpayload":"wake up!","onoffset":0,"onrandomoffset":0,"offtime":"","offtopic":"","offpayload":"wake up!!","offoffset":"","offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":490,"y":100,"wires":[["6ef3b6c5.215be8"]]},{"id":"b49e739f.c26a4","type":"inject","z":"303954f6.eff9ac","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":100,"wires":[["3b06217a.51b59e"]]},{"id":"3b06217a.51b59e","type":"change","z":"303954f6.eff9ac","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"ontime\":\"11:40\",\"offtime\":\"11:40\",\"offoffset\":\".5\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":100,"wires":[["6d19fa46.1a46bc"]]},{"id":"6ef3b6c5.215be8","type":"debug","z":"303954f6.eff9ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":100,"wires":[]}]
1 Like