Is the sensor date today? If not ignore that. Nodered help please

Hi,
I am a master copy/paster/modifier but a very useless coder. I tried my best and I can’t crack this…

I’m using a calendar sensor that outputs - in Nodered - the date of my next event. For example
payload="2022-02-25T18:30:00+01:00"

I’ve got a nice alarm all setup and working… except it only looks at the time… So this one above just triggered at the good time… but it’s for tomorrow and not today. I can’t crack the function to check if the date is today…

Help? (Here’s a nodered with the exact same payload)

[{"id":"3ee9e3f12eb71586","type":"debug","z":"fc970e5b.238d6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":4640,"wires":[]},{"id":"2c01d85856cc8edf","type":"inject","z":"fc970e5b.238d6","name":"Inject Same payload as sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2022-02-25T18:30:00+01:00","payloadType":"str","x":230,"y":4640,"wires":[["3ee9e3f12eb71586"]]}]

I’ll reply to myself as I believe I found the solution (and I’m a bit proud)…

// create a variable called day from the system "time"
var d = new Date();
d.setDate(d.getDate());
var year = d.getFullYear();
var month = d.getMonth()+1; 
var day = d.getDate();

//create a variable from the sensor date called "sensorday"
var sensorday = flow.get('sensorday')

//subsctract both to see if = 0 (it's today) if not 0 (it's not today)
msg.payload = sensorday - day

return msg;
[{"id":"14e58ddadc1b2c81","type":"function","z":"fc970e5b.238d6","name":"Function to check","func":"// create a variable called day from the system \"time\"\nvar d = new Date();\nd.setDate(d.getDate());\nvar year = d.getFullYear();\nvar month = d.getMonth()+1; \nvar day = d.getDate();\n\n//create a variable from the sensor date called \"sensorday\"\nvar sensorday = flow.get('sensorday')\n\n//subsctract both to see if = 0 (it's today) if not 0 (it's not today)\nmsg.payload = sensorday - day\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":4680,"wires":[["372d850b0f930828"]]},{"id":"28100e820a087fa7","type":"inject","z":"fc970e5b.238d6","name":"Inject Same payload as sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2022-02-24T18:30:00+01:00","payloadType":"str","x":190,"y":4680,"wires":[["72ba3b538e759edf"]]},{"id":"72ba3b538e759edf","type":"change","z":"fc970e5b.238d6","name":"extract the day sensor","rules":[{"t":"set","p":"sensorday","pt":"flow","to":"$number($substring(payload,8,2))\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":4680,"wires":[["14e58ddadc1b2c81"]]},{"id":"3ee9e3f12eb71586","type":"debug","z":"fc970e5b.238d6","name":"Not Today","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":4700,"wires":[]},{"id":"372d850b0f930828","type":"switch","z":"fc970e5b.238d6","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"neq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":4680,"wires":[["020f99916334107d"],["3ee9e3f12eb71586"]]},{"id":"020f99916334107d","type":"debug","z":"fc970e5b.238d6","name":"Today","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":970,"y":4640,"wires":[]}]

You may want to look at the time node

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/time.html

This is actually the culprit of my drama. I am using it but I had to do serious workaround to since it doesn’t seem to care about the date… - only the time.

  • Today is Feb 24
  • Sensor data in HA is 2022-02-25T18:30:00+01:00
  • Note that that sensor data is for tomorrow

Result? At 18h30 today - it will trigger. It ignores the fact that the date is for tomorrow.

Do you have “repeat daily” checked? If so it ignores the date and only uses the time.

Really… omg.
I thought this was a filter where I could only set it to work during week days…