Hi, I have created an input_datetime helper in HA to set a time able to launch/trigger a flow in nodered… but I don’t know how to do this… what type of node should I use to test if the current time is = to the time set in my input_datetime helper ?
Thanks a lot for help.
I have the time_date sensor in my configuration to get the current time and timestamp:
- platform: time_date
display_options:
- "time"
- "date_time_iso"
I would store the selected time inside a flow variable, so NR don’t have to get it from HA every minute.
You can do this with a move node and select flow
from the move to dropdown.
Optionally, you can store the current time inside a global variable, so you can access it inside every flow.
Now you can use a function Node that checks the current time against the selected time every time the current time changes. This could look something like this:
var current_time = msg.payload; #from a statechange node of the current time sensor created above
var selected_time = flow.get("selected_time"); #the selected time stored via move node
if (current_time == selected_time)
{
msg = {"payload":true};
return msg;
}
Optionally, you can store the current time inside a global variable, so you can access it inside every flow.
Thanks a lot for your help. I had issue with flow variable (I am a newbie) therefore I tried another way, moreover format of the time of my input_datetime is different than the format of the sensor.time.
I have done this:
- The trigger is sensor.time (therefore it is triggered every minute)
- Convert to HH:mm and store in msg.current_time
- current state node to get the time of my input_datetime
- Convert to HH:mm and store in msg.start_time
- Function node to compare msg.current_time and msg.start_time
I am a bit surprised that it is so complicated to do a basic thing…
Isn’t possible to test the value of a sensor in a function node as it is possible in yaml (is_state(‘binary_sensor.door_contact’, ‘off’)) ?
Thanks anyway for your much appreciated help.
The time node was built to do exactly what you’re looking for.
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/time.html
OK, thanks. How to use this time node ? Thx
[{"id":"1bfe504b99b1cd0c","type":"ha-time","z":"ffbd7f06.4a014","name":"","server":"","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.date_and_time","property":"state","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"payload":"$entity().state","payloadType":"jsonata","debugenabled":false,"x":266,"y":1776,"wires":[["eb47d758a0789aa5"]]},{"id":"eb47d758a0789aa5","type":"debug","z":"ffbd7f06.4a014","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":508,"y":1776,"wires":[]}]