Gå til innhold
  • Bli medlem
Støtt hjemmeautomasjon.no!

Anbefalte innlegg

Skrevet

Har lett litt etter en ferdig løsning for å få litt status fra "Robert" inn i NodeRed og endte opp med å ta en Gardena-løsning og modifisere litt.

 

Legger bare ut det mest grunleggende her så kan en selv bygge videre om en vil...

image.png.29556bee8673020fb5c63c3cef8cc2e1.png

Du trenger brukernavn/passord (samme som i appen) og api_key og api_secret (som en finner på https://developer.husqvarnagroup.cloud/applications/)

 

Resultatet ser slik ut:

1248406518_Skjermbildefra2023-04-1610-06-01.png.552bfeb7daeed88342a61cf25cbb83b5.png

 

[{"id":"ec4f37957f88a213","type":"inject","z":"8603c38cd8dca9a1","name":"InitialToken","props":[],"repeat":"300","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":220,"y":100,"wires":[["5a76f5f24753307f"]]},{"id":"ef52311e418fa6cd","type":"http request","z":"8603c38cd8dca9a1","name":"http request","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":610,"y":160,"wires":[["1c85b2910f1c6f49","d89c283dd29ecf4e","1c19f3206acd6d3f","9a8a81a102fe4394"]]},{"id":"6b818ceca37c4778","type":"function","z":"8603c38cd8dca9a1","name":"Get Mowers","func":"flow.set(\"access_token\", msg.oauth2Response.access_token);\nflow.set(\"refresh_token\", msg.oauth2Response.refresh_token);\nflow.set(\"user_id\", msg.oauth2Response.user_id)\n\nvar mytoken = flow.get(\"access_token\"); \nvar myapi = flow.get(\"api_key\"); \nvar url = \"https://api.amc.husqvarna.dev/v1/mowers\";\n\nmsg.headers = {\n\t'Authorization': 'Bearer '+mytoken,\n\t'Authorization-Provider': 'husqvarna',\n\t'X-Api-Key': myapi,\n\t'Content-Type': 'application/vnd.api+json',\n};\n\nmsg.url = url;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":160,"wires":[["ef52311e418fa6cd"]]},{"id":"1c85b2910f1c6f49","type":"debug","z":"8603c38cd8dca9a1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":160,"wires":[]},{"id":"5a76f5f24753307f","type":"function","z":"8603c38cd8dca9a1","name":"Credentials","func":"flow.set(\"gard_login\", \"[email protected]\");\nflow.set(\"gard_pass\", \"xxxxxx\");\nflow.set(\"api_key\", \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\");\nflow.set(\"api_secret\", \"zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz\");\n\n\nvar mylogin = flow.get(\"gard_login\");\nvar mypass = flow.get(\"gard_pass\"); \nvar myrefresh = flow.get(\"refresh_token\"); \nvar myapi = flow.get(\"api_key\"); \nvar mysecret = flow.get(\"api_secret\"); \n\nmsg.oauth2Request = { \n\"access_token_url\": \"https://api.authentication.husqvarnagroup.dev/v1/oauth2/token\", \n\"credentials\": {\n    \"grant_type\": \"password\",\n    \"username\": mylogin,\n    \"password\": mypass,\n    \"client_id\": myapi,\n    \"client_secret\": mysecret,\n    \"scope\": \"openid\"\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":100,"wires":[["88e8d4ddd3a7e099"]]},{"id":"498b21e243819b76","type":"debug","z":"8603c38cd8dca9a1","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"oauth2Response","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":100,"wires":[]},{"id":"88e8d4ddd3a7e099","type":"oauth2","z":"8603c38cd8dca9a1","name":"","container":"oauth2Response","grant_type":"set_by_credentials","access_token_url":"","authorization_endpoint":"","open_authentication":"","username":"","password":"","client_id":"","client_secret":"","scope":"","proxy":"","senderr":false,"client_credentials_in_body":true,"rejectUnauthorized":true,"headers":{},"x":660,"y":100,"wires":[["6b818ceca37c4778","498b21e243819b76"]]},{"id":"d89c283dd29ecf4e","type":"change","z":"8603c38cd8dca9a1","name":"Extract Mower activity","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[\"data\"][0][\"attributes\"][\"mower\"].activity","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":240,"wires":[["55ea77bc8dc2844a"]]},{"id":"0d70166c691efcee","type":"ui_text","z":"8603c38cd8dca9a1","group":"a7f439d7b1e0bbd4","order":1,"width":0,"height":0,"name":"","label":"Act:","format":"{{msg.payload}}","layout":"row-left","className":"","x":1010,"y":240,"wires":[]},{"id":"55ea77bc8dc2844a","type":"show-value","z":"8603c38cd8dca9a1","name":"","path":"","x":820,"y":240,"wires":[["0d70166c691efcee"]]},{"id":"1c19f3206acd6d3f","type":"change","z":"8603c38cd8dca9a1","name":"Extract Mower state","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[\"data\"][0][\"attributes\"][\"mower\"].state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":280,"wires":[["12a6948a8805bccf"]]},{"id":"0ec1d3574e80d05f","type":"ui_text","z":"8603c38cd8dca9a1","group":"a7f439d7b1e0bbd4","order":1,"width":0,"height":0,"name":"","label":"State:","format":"{{msg.payload}}","layout":"row-left","className":"","x":1010,"y":280,"wires":[]},{"id":"12a6948a8805bccf","type":"show-value","z":"8603c38cd8dca9a1","name":"","path":"","x":820,"y":280,"wires":[["0ec1d3574e80d05f"]]},{"id":"80c2164fda5b93c9","type":"ui_table","z":"8603c38cd8dca9a1","group":"a7f439d7b1e0bbd4","name":"","order":2,"width":"8","height":"11","columns":[],"outputs":0,"cts":false,"x":1010,"y":200,"wires":[]},{"id":"9a8a81a102fe4394","type":"function","z":"8603c38cd8dca9a1","name":"2array.of.obj","func":"var newObj = {}\nlet arr = []\nvar lastDate = 0;\nvar options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' };\nvar lastDateFormatted = 0;\nvar system = [msg.payload.data[0].attributes.system]\nvar mower = [msg.payload.data[0].attributes.mower]\nvar battery = [msg.payload.data[0].attributes.battery]\nvar metadata = [msg.payload.data[0].attributes.metadata]\nvar planner = [msg.payload.data[0].attributes.planner]\nvar calendar = [msg.payload.data[0].attributes.calendar.tasks[0]]\n\nnewObj = { Status: \"Name: \" + system[0].name }\narr.push(newObj)\nnewObj = { Status: \"Model: \" + system[0].model }\narr.push(newObj)\nnewObj = { Status: \"Serial: \" + system[0].serialNumber }\narr.push(newObj)\n\nnewObj = { Status: \"Override: \" + planner[0].override.action }\narr.push(newObj)\n\n//Calendar\nvar cald = \"\";\nif (calendar[0].monday == true) cald = \"M\"; else cald = \"_\";\nif (calendar[0].tuesday == true) cald += \"T\"; else cald += \"_\";\nif (calendar[0].wednesday == true) cald += \"W\"; else cald += \"_\";\nif (calendar[0].thursday == true) cald += \"T\"; else cald += \"_\";\nif (calendar[0].friday == true) cald += \"F\"; else cald += \"_\";\nif (calendar[0].saturday == true) cald += \"S\"; else cald += \"_\";\nif (calendar[0].sunday == true) cald += \"S\"; else cald += \"_\";\nnewObj = { Status: \"Calendar: \" + cald }\narr.push(newObj)\n\nnewObj = { Status: \"Connected: \" + metadata[0].connected }\narr.push(newObj)\n\nlastDate = new Date(metadata[0].statusTimestamp);\nlastDateFormatted = lastDate.toLocaleDateString('nb-NO', options);\nnewObj = { Status: \"StatusTS: \" +  lastDateFormatted}\narr.push(newObj)\n\nnewObj = {Status: \"Mode: \" + mower[0].mode}\narr.push(newObj)\nnewObj = { Status: \"Activity: \" + mower[0].activity}\narr.push(newObj)\nnewObj = { Status: \"State: \" + mower[0].state }\narr.push(newObj)\nnewObj = { Status: \"ErrorCode: \" + mower[0].errorCode }\narr.push(newObj)\nlastDate = new Date(mower[0].errorCodeTimestamp);\nlastDateFormatted = lastDate.toLocaleDateString('nb-NO', options);\nnewObj = { Status: \"ErrorCodeTS: \" +  lastDateFormatted}\narr.push(newObj)\nnewObj = { Status: \"Battery: \" + battery[0].batteryPercent }\narr.push(newObj)\n\nnode.warn(arr)\nmsg.payload = arr\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":200,"wires":[["80c2164fda5b93c9","1c85b2910f1c6f49"]]},{"id":"afa6c1e45f377316","type":"comment","z":"8603c38cd8dca9a1","name":"Input your credentials","info":"","x":470,"y":70,"wires":[]},{"id":"a7f439d7b1e0bbd4","type":"ui_group","name":"Status","tab":"55b4bf40cf1e815d","order":1,"disp":true,"width":"8","collapse":false,"className":""},{"id":"55b4bf40cf1e815d","type":"ui_tab","name":"Robert","icon":"android","order":21,"disabled":false,"hidden":false}]

 

  • Like 2

Bli med i samtalen

Du kan publisere innhold nå og registrere deg senere. Hvis du har en konto, logg inn nå for å poste med kontoen din.

Gjest
Skriv svar til emnet...

×   Du har limt inn tekst med formatering.   Lim inn uten formatering i stedet

  Du kan kun bruke opp til 75 smilefjes.

×   Lenken din har blitt bygget inn på siden automatisk.   Vis som en ordinær lenke i stedet

×   Tidligere tekst har blitt gjenopprettet.   Tøm tekstverktøy

×   Du kan ikke lime inn bilder direkte. Last opp eller legg inn bilder fra URL.

×
×
  • Opprett ny...

Viktig informasjon

Vi har plassert informasjonskapsler/cookies på din enhet for å gjøre denne siden bedre. Du kan justere dine innstillinger for informasjonskapsler, ellers vil vi anta at dette er ok for deg.