In short: I have a time that comes as a spoken decimal "9.51" and I need to
- Convert in a time (solved below)
- Check time "now" and convert to 24hrs if needed
- (if time now is earlier than 9, then leave it as is, else, add 12hours to it)
My project: I have several google speakers and I'm trying to do what google cant:
Ask google to "ping me on all speakers at a specific time". (an alarm that rings on all speakers sort of).
I'm stuck at time conversion. Google, via IFTTT lets me speaks a number and a string and passes it on.
Main problem: I will say "9.51" when I mean 21:51 hrs - I need to smart convert it - and I have no use for dates.
So this works - I speak to google, it goes to IFTTT, comes back as webhookrelay, time is split into an alarm that waits and then text is released as casting to google.
(the Inject node has the ouput that IFTTT sends me - to test)
[
{
"id": "fa2f6841.a631b8",
"type": "tab",
"label": "Flow 5",
"disabled": false,
"info": ""
},
{
"id": "fc018262.379eb",
"type": "webhookrelay",
"z": "fa2f6841.a631b8",
"buckets": "gactions",
"x": 130,
"y": 220,
"wires": [
[
"9f58bb33.4d4bb8"
]
]
},
{
"id": "9f58bb33.4d4bb8",
"type": "function",
"z": "fa2f6841.a631b8",
"name": "extract body",
"func": "return {\n payload: msg.payload.body\n};",
"outputs": 1,
"noerr": 0,
"x": 310,
"y": 200,
"wires": [
[
"dffeeb79.6fc858"
]
]
},
{
"id": "dffeeb79.6fc858",
"type": "json",
"z": "fa2f6841.a631b8",
"name": "",
"property": "payload",
"action": "",
"pretty": true,
"x": 490,
"y": 200,
"wires": [
[
"99de2126.f06bc"
]
]
},
{
"id": "c1fd9702.f5d0b8",
"type": "inject",
"z": "fa2f6841.a631b8",
"name": "",
"topic": "",
"payload": "{\"type\":\"webhook\",\"meta\":{\"id\":\"815a9995-208e-44fd-be82-45ec2112dd6f\",\"bucked_id\":\"1ecec89d-b44e-4c53-87c5-f2abcc38392d\",\"bucket_name\":\"gactions\",\"input_id\":\"68922408-5099-4ab7-89b5-844210568a24\",\"input_name\":\"Default public endpoint\",\"output_name\":\"\",\"output_destination\":\"\"},\"headers\":{\"X-Newrelic-Id\":[\"VwAOU1RRGwAFUFZUAwQE\"],\"X-Newrelic-Transaction\":[\"PxQGUgNUClYGB1lWVgFSUUYdUFIOFQZOElMLBw8KUQRQXQ0AAQQEQEgUUQMDW1kEVQZDPw==\"],\"Content-Type\":[\"application/json\"],\"Content-Length\":[\"58\"]},\"query\":\"\",\"body\":\"{ \\\"time_google\\\": \\\"22.07\\\", \\\"message_google\\\": \\\"about potatoes\\\" }\",\"method\":\"POST\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 130,
"y": 180,
"wires": [
[
"9f58bb33.4d4bb8"
]
]
},
{
"id": "cb6697ab.006328",
"type": "cast-to-client",
"z": "fa2f6841.a631b8",
"name": "",
"url": "",
"contentType": "",
"message": "",
"language": "en",
"ip": "192.168.86.247",
"port": "",
"volume": "",
"x": 860,
"y": 320,
"wires": [
[]
]
},
{
"id": "99de2126.f06bc",
"type": "function",
"z": "fa2f6841.a631b8",
"name": "Convert to Payload and change to variables needed later",
"func": "var msg = {payload:{ontime: msg.payload.time_google, message: msg.payload.message_google}};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 790,
"y": 200,
"wires": [
[
"7b0cd13d.dd3c4"
]
]
},
{
"id": "7c7ea65e.0ff4a8",
"type": "schedex",
"z": "fa2f6841.a631b8",
"name": "alarm clock",
"suspended": false,
"lat": "",
"lon": "",
"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": 650,
"y": 320,
"wires": [
[
"cb6697ab.006328"
]
]
},
{
"id": "7b0cd13d.dd3c4",
"type": "change",
"z": "fa2f6841.a631b8",
"name": "convert decimals to time",
"rules": [
{
"t": "change",
"p": "payload.ontime",
"pt": "msg",
"from": ".",
"fromt": "str",
"to": ":",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 690,
"y": 260,
"wires": [
[
"3fb820a.0ff20e"
]
]
},
{
"id": "3fb820a.0ff20e",
"type": "moment",
"z": "fa2f6841.a631b8",
"name": "",
"topic": "",
"input": "payload.ontime",
"inputType": "msg",
"inTz": "Europe/Amsterdam",
"adjAmount": 0,
"adjType": "days",
"adjDir": "add",
"format": "",
"locale": "C",
"output": "",
"outputType": "msg",
"outTz": "Europe/Amsterdam",
"x": 940,
"y": 260,
"wires": [
[
"7c7ea65e.0ff4a8"
]
]
}
]
But I fail (since I'm useless in coding) to do the time calculation with the if/else to add the 12 hours.