My ZE Online abfragen

Renault hat im Januar 2016 die Seite: www.services.renault-ze.com überarbeitet. Nun gibt es eine json API um auf die Daten vom Renault Elektroauto zuzugreifen.

Das Vorgehen ist folgendermasen:

Zuerst muss die login Seite mit username und passwort in einem json request aufgerufen werden.

URL: www.services.renault-ze.com/api/user/login

http Header: “Content-Type: application/json;charset=utf-8”
http Post: {“username”:”[e-mail adresse]”,”password”:”[das passwort]”}

In der Antwort kriegt man ein json mit einem token der vin und weiteren angaben zurück, mit diesem token kann man nun authentifiziert weitere daten anfordern:

URL: www.services.renault-ze.com/api/vehicle/%5Bvin einfügen]/battery

http Header: “Authorization: Bearer [token einfügen]”
http Get

mit diesem aufruf kommt ein json zurück mit den Angaben zum Ladestatus.

 

Hier ein Beispiel in NodeRED mit NodeRED-UI plugin:

[{"id":"88f5ae81.3d8df8","type":"ui_tab","name":"Home","icon":"dashboard","order":"1"},{"id":"a7141545.36353","type":"inject","z":"fecf0569.4adad8","name":"every hour","topic":"","payload":"","payloadType":"none","repeat":"3600","crontab":"","once":true,"x":138,"y":55,"wires":[["f9bbdd37.1052b"]]},{"id":"81d077e8.d4993","type":"http request","z":"fecf0569.4adad8","name":"","method":"POST","ret":"obj","url":"https://www.services.renault-ze.com/api/user/login","x":517,"y":55,"wires":[["865fb89.8f11bc8","c200c526.960ea"]]},{"id":"865fb89.8f11bc8","type":"debug","z":"fecf0569.4adad8","name":"","active":false,"console":"false","complete":"false","x":766,"y":51,"wires":[]},{"id":"f9bbdd37.1052b","type":"function","z":"fecf0569.4adad8","name":"login request","func":"msg.headers = {\"Content-Type\":\"application/json;charset=utf-8\"}\nmsg.payload = {\"username\":\"a@b.ch\",\"password\":\"hier das passwort eingeben\"}\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":56,"wires":[["81d077e8.d4993"]]},{"id":"c200c526.960ea","type":"function","z":"fecf0569.4adad8","name":"battery stats","func":"token = msg.payload.token;\nrefresh_token = msg.payload.refresh_token;\n\nvin = msg.payload.user.vehicle_details.VIN;\n\nmsg.url = \"https://www.services.renault-ze.com/api/vehicle/\" + vin + \"/battery\";\nmsg.headers = {\"Authorization\": \"Bearer \" + token};\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"x":301,"y":157,"wires":[["5484869b.b54ab","ad288d6e.e11808","14be5617.56cc52"]]},{"id":"14be5617.56cc52","type":"http request","z":"fecf0569.4adad8","name":"","method":"GET","ret":"obj","url":"","x":516,"y":161,"wires":[["da844948.1e4af","7923c02f.9f6f28","bbd04d3.7b55eb","4d58211c.31efb8","e759c4be.d560a8","d3fcff23.66184"]]},{"id":"ad288d6e.e11808","type":"debug","z":"fecf0569.4adad8","name":"","active":false,"console":"false","complete":"headers","x":515,"y":260,"wires":[]},{"id":"5484869b.b54ab","type":"debug","z":"fecf0569.4adad8","name":"","active":false,"console":"false","complete":"url","x":498,"y":213,"wires":[]},{"id":"da844948.1e4af","type":"debug","z":"fecf0569.4adad8","name":"","active":false,"console":"false","complete":"false","x":760,"y":167,"wires":[]},{"id":"81d714de.0e7208","type":"ui_text","z":"fecf0569.4adad8","tab":"88f5ae81.3d8df8","name":"Lädt: ","group":"ZOE Status","order":1,"format":"{{msg.payload.charging}}","x":981,"y":212,"wires":[]},{"id":"e8d50ee.92e27f","type":"ui_text","z":"fecf0569.4adad8","tab":"88f5ae81.3d8df8","name":"Kabel: ","group":"ZOE Status","order":1,"format":"{{msg.payload.plugged}}","x":983,"y":257,"wires":[]},{"id":"7923c02f.9f6f28","type":"ui_text","z":"fecf0569.4adad8","tab":"88f5ae81.3d8df8","name":"Ladestand: ","group":"ZOE Status","order":1,"format":"{{msg.payload.charge_level}} %","x":757,"y":296,"wires":[]},{"id":"bbd04d3.7b55eb","type":"ui_text","z":"fecf0569.4adad8","tab":"88f5ae81.3d8df8","name":"Reichweite: ","group":"ZOE Status","order":1,"format":"{{msg.payload.remaining_range}} km","x":759,"y":338,"wires":[]},{"id":"4d58211c.31efb8","type":"function","z":"fecf0569.4adad8","name":"translate","func":"if (msg.payload.plugged == true) {\n    msg.payload.plugged = \"Angeschlossen\";\n} else {\n    msg.payload.plugged = \"Entfernt\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":746,"y":256,"wires":[["e8d50ee.92e27f"]]},{"id":"e759c4be.d560a8","type":"function","z":"fecf0569.4adad8","name":"translate","func":"if (msg.payload.charging == true) {\n    msg.payload.charging = \"Ja\";\n} else {\n    msg.payload.charging = \"Nein\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":745,"y":212,"wires":[["81d714de.0e7208"]]},{"id":"5845a75d.1283c","type":"moment","z":"fecf0569.4adad8","name":"","topic":"","input":"payload","format":"fromNow","output":"payload","x":918,"y":385,"wires":[["96377cb0.9305"]]},{"id":"96377cb0.9305","type":"ui_text","z":"fecf0569.4adad8","tab":"88f5ae81.3d8df8","name":"Aktuallisiert:","group":"ZOE Status","order":1,"format":"{{msg.payload}}","x":1102,"y":385,"wires":[]},{"id":"d3fcff23.66184","type":"function","z":"fecf0569.4adad8","name":"translate","func":"msg.payload = msg.payload.last_update\nreturn msg;","outputs":1,"noerr":0,"x":743,"y":385,"wires":[["5845a75d.1283c"]]}]