I've been struggling to understand why I'm getting the wrong date/time, having read through a large number of threads and guides on this site and many others. I don't like to ask for help until I don't know where to turn, preferring to try and resolve it through other's questions. But I don't know what to do.
It looks like Node-RED thinks Europe/London is +60 minutes from GMT, but that ended on 31 October 2021.
The TimeHelper gets the time from Home Assistant, the time under the node is showing correctly.
The function gets the string from the Helper as "06:06:00". Splits it by the 'colon' and extracts hours and minutes. It then creates a new date beginning from 1970-01-01 with the hours and minutes added on. I've listed the hours and minutes separately to demonstrate that it is collecting the right information, and also the timezone to show it's not reporting correctly.
The Date/Time Formatter is given the string 1970-01-01T07:00 and the timezone 'Europe/London' (currently GMT+0). If I delete either Timezone and leave it as '[determined by system]', moving off the field automatically converts it to 'Europe/London'
The times of the debug log entry (e.g. 01:52:08) are correct for GMT.
If I change the Input/Output Timezone in the Date/Time Formatter to 'ETC/GMT', it outputs it correctly.
If I change the Input/Output Timezone in the Date/Time Formatter to 'Portugal', it outputs it incorrectly, just like London (they're both the same +1 hour).
(Wikipedia)
Is there something obvious I've missed?
Many thanks,
Aubs
.
For convenience, here's my flow:
The function is
var Data=msg.payload;
var data=Data.split(":")
var hours=data[0]
var minutes=data[1]
var d= new Date(1970,01,01,hours,minutes);
msg.payload=d.getTime()/1000;
msg.timestamp=d;
msg.hour=hours;
msg.minute=minutes;
msg.timezone=d.getTimezoneOffset();
return msg;
My flow is below if needed:
[{"id":"042d05d87a27157a","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"2672831b.1236ac","type":"inject","z":"042d05d87a27157a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":230,"y":220,"wires":[["882eb0d5e5a4c695","eaefd2d6b83f40b7"]]},{"id":"d3ec7afe.0c2968","type":"debug","z":"042d05d87a27157a","name":"Output time","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":180,"wires":[]},{"id":"882eb0d5e5a4c695","type":"api-current-state","z":"042d05d87a27157a","name":"TimeHelper","server":"a3a41549.e2ab08","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.bedroom_weekday_morning_start","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":120,"wires":[["ce1fac79bac14841"]]},{"id":"ce1fac79bac14841","type":"function","z":"042d05d87a27157a","name":"","func":"var Data=msg.payload;\nvar data=Data.split(\":\")\nvar hours=data[0]\nvar minutes=data[1]\n\nvar d= new Date(1970,01,01,hours,minutes);\nmsg.payload=d.getTime()/1000;\nmsg.timestamp=d;\nmsg.hour=hours;\nmsg.minute=minutes;\nmsg.timezone=d.getTimezoneOffset();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":200,"wires":[["d3ec7afe.0c2968"]]},{"id":"f1176666ceb9c9e8","type":"debug","z":"042d05d87a27157a","name":"OutputDateTime","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":260,"wires":[]},{"id":"eaefd2d6b83f40b7","type":"moment","z":"042d05d87a27157a","name":"","topic":"","input":"1970-01-01T07:00","inputType":"str","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"C","output":"","outputType":"msg","outTz":"Europe/London","x":440,"y":300,"wires":[["f1176666ceb9c9e8"]]},{"id":"a3a41549.e2ab08","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]
[Admin Edit] backticks moved onto separate lines to correctly format the flow