I am trying to get the current date and time in my timezone to be used as part of a message in a flow. I have created a basic function containing this:
var d = new Date();
msg.payload = d.getTime();
return msg;
and this is how I am using it for testing purposes:
it works but is giving me the wrong time.
This is my current flow where I am planning to use such function:
My timezone is EST America/New_York and I have that configured in my configuration.yml
file:
homeassistant:
name: Home
latitude: !secret latitude_home
longitude: !secret longitude_home
elevation: 0
unit_system: imperial
temperature_unit: F
time_zone: America/New_York
currency: USD
internal_url: !secret internal_url
external_url: !secret external_url
what I am missing here? Is there a more easy/proper way to get the current date and time?
Here is the entire flow:
[
{
"id": "49ea54fced633ba6",
"type": "function",
"z": "b0037499.3da95",
"name": "Get Current Time",
"func": "var d = new Date();\nmsg.payload = d.getTime();\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 320,
"wires": [
[
"cce7c7f6bb5ec54b"
]
]
},
{
"id": "cce7c7f6bb5ec54b",
"type": "moment",
"z": "b0037499.3da95",
"name": "",
"topic": "",
"input": "payload",
"inputType": "msg",
"inTz": "Europe/Oslo",
"adjAmount": "1",
"adjType": "hours",
"adjDir": "add",
"format": "LLL",
"locale": "",
"output": "payload",
"outputType": "msg",
"outTz": "Europe/Oslo",
"x": 620,
"y": 320,
"wires": [
[
"36dc85d182937076"
]
]
},
{
"id": "36dc85d182937076",
"type": "debug",
"z": "b0037499.3da95",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 320,
"wires": []
},
{
"id": "9f95a86341468825",
"type": "inject",
"z": "b0037499.3da95",
"name": "Timestamp",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 200,
"y": 320,
"wires": [
[
"49ea54fced633ba6"
]
]
}
]