Skip to content

Instantly share code, notes, and snippets.

@luismalves
Last active December 7, 2020 00:08
Show Gist options
  • Select an option

  • Save luismalves/484ecedb8c98fecffa8a18fc29d0e218 to your computer and use it in GitHub Desktop.

Select an option

Save luismalves/484ecedb8c98fecffa8a18fc29d0e218 to your computer and use it in GitHub Desktop.
Node-red flow to get Google Home alarm using Google Home Local API
[
{
"id": "ab40c601.105e48",
"type": "exec",
"z": "88b833e7.f1a62",
"command": "curl --insecure https://<google-home-ip>:8443/setup/assistant/alarms",
"addpay": true,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "",
"x": 710,
"y": 640,
"wires": [
[
"b171da2d.279a48"
],
[],
[]
]
},
{
"id": "b171da2d.279a48",
"type": "json",
"z": "88b833e7.f1a62",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 530,
"y": 700,
"wires": [
[
"4cb6f03a.a2f4d"
]
]
},
{
"id": "de24d75f.b9b208",
"type": "function",
"z": "88b833e7.f1a62",
"name": "Set Header",
"func": "// Setup variables\nconst HA = global.get('homeassistant');\nlet newmsg = {};\n\nif(HA.homeAssistant.states[\"input_text.google_tokens\"] === undefined) {\n newmsg.payload = 'is undefined';\n \n return [null, newmsg]; \n}\n\nif(HA.homeAssistant.states[\"input_text.google_tokens\"].state == 'Tokening finished'){\n newmsg.payload = '-H \"cast-local-authorization-token: ' + HA.homeAssistant.states[\"input_text.google_tokens\"].attributes.token_Clock + '\"';\n\n return [newmsg, null];\n}",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 350,
"y": 640,
"wires": [
[
"ab40c601.105e48"
],
[
"ff354f77.58f8a"
]
]
},
{
"id": "c400f967.8d9e08",
"type": "ha-api",
"z": "88b833e7.f1a62",
"name": "",
"server": "6d95e658.976b48",
"debugenabled": false,
"protocol": "http",
"method": "post",
"path": "states/sensor.next_alarm",
"data": "payload",
"dataType": "jsonata",
"location": "payload",
"locationType": "msg",
"responseType": "json",
"x": 1250,
"y": 760,
"wires": [
[]
]
},
{
"id": "23213906.e3e406",
"type": "moment",
"z": "88b833e7.f1a62",
"name": "Format fire time",
"topic": "",
"input": "payload.alarm[0].fire_time",
"inputType": "msg",
"inTz": "Europe/Lisbon",
"adjAmount": 0,
"adjType": "days",
"adjDir": "add",
"format": "",
"locale": "en-US",
"output": "payload.next_alarm",
"outputType": "msg",
"outTz": "Europe/Lisbon",
"x": 880,
"y": 700,
"wires": [
[
"dde8e0ee.e9145"
]
]
},
{
"id": "4cb6f03a.a2f4d",
"type": "switch",
"z": "88b833e7.f1a62",
"name": "Has alarms?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "jsonata_exp",
"v": "$count(payload.alarm) > 0",
"vt": "jsonata"
},
{
"t": "else"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 690,
"y": 700,
"wires": [
[
"23213906.e3e406"
],
[]
]
},
{
"id": "dde8e0ee.e9145",
"type": "function",
"z": "88b833e7.f1a62",
"name": "Configure entity",
"func": "let newmsg = {payload: {}}\n\nnewmsg.payload = {\n state: 'Alarm set',\n attributes: {\n friendly_name: 'Next alarm in Bedroom Clock',\n next_alarm: msg.payload.next_alarm,\n next_alarm_epoch: msg.payload.alarm[0].fire_time,\n device_class: \"timestamp\"\n }\n}\n\nreturn newmsg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 1080,
"y": 700,
"wires": [
[
"c400f967.8d9e08"
]
]
},
{
"id": "e2f5c1e0.4cc01",
"type": "comment",
"z": "88b833e7.f1a62",
"name": "Fetch information from Clock",
"info": "",
"x": 180,
"y": 580,
"wires": []
},
{
"id": "e3ebb85b.ce7fc8",
"type": "server-state-changed",
"z": "88b833e7.f1a62",
"name": "Change in token",
"server": "6d95e658.976b48",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "input_text.google_tokens",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "Tokening finished",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"output_only_on_state_change": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": true,
"ignoreCurrentStateUnavailable": true,
"x": 140,
"y": 640,
"wires": [
[
"de24d75f.b9b208"
],
[]
]
},
{
"id": "ff354f77.58f8a",
"type": "function",
"z": "88b833e7.f1a62",
"name": "Configure entity",
"func": "let newmsg = {payload: {}}\n\nnewmsg.payload = {\n state: 'Failed to fetch token',\n attributes: {\n friendly_name: 'Next alarm in Bedroom Clock',\n next_alarm: '',\n next_alarm_epoch: '',\n device_class: \"timestamp\"\n }\n}\n\nreturn newmsg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 560,
"y": 760,
"wires": [
[
"c400f967.8d9e08"
]
]
},
{
"id": "6d95e658.976b48",
"type": "server",
"name": "Home Assistant",
"legacy": false,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment