Here you go. This isn't the actual one I run, but a simplified flow with private info removed. It should give you an idea of how to get an oauth2 toke, refresh a token, and turn the Flume away mode on/off. There are other endpoints for fetching water use, etc, of course.
Edit the 2 oauth function nodes with your info. Edit the Set Location State and Get Location State node URLs and put in your clientid # and location #.
node red flow
[
{
"id": "c30e715.8ba869",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": ""
},
{
"id": "35055acc.f39056",
"type": "http request",
"z": "c30e715.8ba869",
"name": "Get Tokens",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.flumewater.com/oauth/token",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 470,
"y": 80,
"wires": [
[
"5a06d574.6d262c",
"9725c581.21d138",
"30dfe80.8bf0118"
]
]
},
{
"id": "ed82bfa9.80bb",
"type": "function",
"z": "c30e715.8ba869",
"name": "oauth2Request",
"func": "msg.headers='Content-Type: application/json'\n\nmsg.payload= {\n \"grant_type\":\"password\",\n \"client_id\":\"Enter_Client_ID_Here\",\n \"client_secret\":\"Enter_Client_Secret_Here\",\n \"username\":\"Enter_account_username_here\",\n \"password\":\"Enter_account_password_here\"\n}\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 280,
"y": 80,
"wires": [
[
"35055acc.f39056"
]
]
},
{
"id": "e678dae.b1a1d28",
"type": "inject",
"z": "c30e715.8ba869",
"name": "",
"props": [
{
"p": "payload",
"v": "",
"vt": "date"
},
{
"p": "topic",
"v": "",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 80,
"wires": [
[
"ed82bfa9.80bb"
]
]
},
{
"id": "5a06d574.6d262c",
"type": "debug",
"z": "c30e715.8ba869",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 80,
"wires": []
},
{
"id": "63868470.6c669c",
"type": "http request",
"z": "c30e715.8ba869",
"name": "Refresh Tokens",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.flumewater.com/oauth/token",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 480,
"y": 220,
"wires": [
[
"abef5ab6.d8d3c8",
"9725c581.21d138",
"30dfe80.8bf0118"
]
]
},
{
"id": "c3b8c6c.6b47c38",
"type": "function",
"z": "c30e715.8ba869",
"name": "oauth2Request",
"func": "msg.headers='Content-Type: application/json'\n\nmsg.payload= {\n \"grant_type\":\"password\",\n \"client_id\":\"Enter_client_id_here\",\n \"client_secret\":\"Enter_client_secret_here\",\n \"username\":\"Enter_account_username_here\",\n \"password\":\"Enter_account_password_here\"\n}\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 280,
"y": 220,
"wires": [
[
"63868470.6c669c"
]
]
},
{
"id": "fc96cf26.5b4b2",
"type": "inject",
"z": "c30e715.8ba869",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "43200",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 220,
"wires": [
[
"c3b8c6c.6b47c38"
]
]
},
{
"id": "abef5ab6.d8d3c8",
"type": "debug",
"z": "c30e715.8ba869",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 220,
"wires": []
},
{
"id": "b83c3058.70473",
"type": "http request",
"z": "c30e715.8ba869",
"name": "Get Location State",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.flumewater.com/users/YOUR_CLIENTID/locations/YOUR_LOCATION",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 490,
"y": 580,
"wires": [
[
"f0275e1b.3d8eb",
"dcb23dac.e2f2a"
]
]
},
{
"id": "77b4f79.8e3e808",
"type": "function",
"z": "c30e715.8ba869",
"name": "oauth2Request",
"func": "my_token = global.get(\"flume_access_token\");\n\n//node.warn(my_token);\n\nif (my_token) {\n msg.headers = {\n Authorization: \"Bearer \" + my_token\n }\n\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 280,
"y": 580,
"wires": [
[
"b83c3058.70473",
"f0275e1b.3d8eb"
]
]
},
{
"id": "facab48b.205d58",
"type": "inject",
"z": "c30e715.8ba869",
"name": "",
"props": [
{
"p": "payload",
"v": "",
"vt": "date"
},
{
"p": "topic",
"v": "",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 580,
"wires": [
[
"77b4f79.8e3e808"
]
]
},
{
"id": "f0275e1b.3d8eb",
"type": "debug",
"z": "c30e715.8ba869",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 540,
"wires": []
},
{
"id": "dcb23dac.e2f2a",
"type": "change",
"z": "c30e715.8ba869",
"name": "",
"rules": [
{
"t": "set",
"p": "flume_away_mode",
"pt": "global",
"to": "payload.data[0].away_mode",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 740,
"y": 580,
"wires": [
[]
]
},
{
"id": "ef818986.3a7708",
"type": "http request",
"z": "c30e715.8ba869",
"name": "Set Location State",
"method": "use",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.flumewater.com/users/YOUR_CLIENTID/locations/YOUR_LOCATION",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 490,
"y": 420,
"wires": [
[
"e93b7ba0.f2b8b8",
"201a4847.db7e08"
]
]
},
{
"id": "663350aa.9bc6f",
"type": "function",
"z": "c30e715.8ba869",
"name": "false",
"func": "my_token = global.get(\"flume_access_token\");\n\nif (my_token) {\n msg.method = \"PATCH\";\n\n msg.headers = {\n \"Authorization\": \"Bearer \" + my_token,\n \"Content-Type\": \"application/json\"\n }\n\n msg.payload = {\n \"away_mode\": false\n }\n\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 250,
"y": 420,
"wires": [
[
"ef818986.3a7708"
]
]
},
{
"id": "5f65cdae.4f3ab4",
"type": "inject",
"z": "c30e715.8ba869",
"name": "",
"props": [
{
"p": "payload",
"v": "",
"vt": "date"
},
{
"p": "topic",
"v": "",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 420,
"wires": [
[
"663350aa.9bc6f"
]
]
},
{
"id": "e93b7ba0.f2b8b8",
"type": "debug",
"z": "c30e715.8ba869",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 420,
"wires": []
},
{
"id": "a481ee26.19848",
"type": "function",
"z": "c30e715.8ba869",
"name": "true",
"func": "my_token = global.get(\"flume_access_token\");\n\nif (my_token) {\n msg.method = \"PATCH\";\n\n msg.headers = {\n \"Authorization\": \"Bearer \" + my_token,\n \"Content-Type\": \"application/json\"\n }\n\n msg.payload = {\"away_mode\": true}\n\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 250,
"y": 480,
"wires": [
[
"ef818986.3a7708"
]
]
},
{
"id": "a7e66bd5.11cad8",
"type": "inject",
"z": "c30e715.8ba869",
"name": "",
"props": [
{
"p": "payload",
"v": "",
"vt": "date"
},
{
"p": "topic",
"v": "",
"vt": "string"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 480,
"wires": [
[
"a481ee26.19848"
]
]
},
{
"id": "201a4847.db7e08",
"type": "delay",
"z": "c30e715.8ba869",
"name": "",
"pauseType": "delay",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 680,
"y": 460,
"wires": [
[
"77b4f79.8e3e808"
]
]
},
{
"id": "9725c581.21d138",
"type": "change",
"z": "c30e715.8ba869",
"name": "",
"rules": [
{
"t": "set",
"p": "flume_refresh_token",
"pt": "global",
"to": "payload.data[0].refresh_token",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 790,
"y": 120,
"wires": [
[]
]
},
{
"id": "30dfe80.8bf0118",
"type": "change",
"z": "c30e715.8ba869",
"name": "",
"rules": [
{
"t": "set",
"p": "flume_access_token",
"pt": "global",
"to": "payload.data[0].access_token",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 790,
"y": 180,
"wires": [
[]
]
}
]