Hi
Does anyone know if it would be possible to send eg. charging data from an EV to google sheets.
I would like to analyse the charging cycle of my Hyundai Ioniq, to understand the planned charging better.
Thx.
Hi
Does anyone know if it would be possible to send eg. charging data from an EV to google sheets.
I would like to analyse the charging cycle of my Hyundai Ioniq, to understand the planned charging better.
Thx.
Mikael,
Not an easy answer however I can send you a sample google script that calls a rest end point and populates a google sheet . You will need change it quite a bit to add support for initial key request etc,
I am doing it a. Bit of a round trip. I extract to Mongo DB by using Mongos great stitch sererless function and then have it provide a rest end point onto google sheets
Let me know
Hi,
I did the job with MS Excel. The macro can read logged data via Autopi-API.
Have fun with it and feel free to improve code.
GetDataFromWebAPI.xlsm
Manfred
Great, thanks much appreciated
Thx. Chris and Manfred. I would though still like to see if I can push data to google sheets, with a job and some custom code.
I would like to build up some historical data, so that I can draw a graph of eg. a charging session.
Mikael,
I have a simple script which should work to get you started. Go into google sheets and
once you have done that from the run menu run the retrieveAutoPI. This should get you started
function retrieveAutoPI() {
let authData = retrieveToken();
if (authData){
let bbmData = retrieveData(authData.token,authData.user.devices[0].id,âobd.rpm.valueâ)
insertData(bbmData);
}
}
function retrieveToken()
{
let data = {âemailâ:âredacted_emailâ,âpasswordâ:âredacted_passwordâ}
let url = âhttps://api.autopi.io/auth/login/â
let options = {
âmethodâ: âpostâ,
âpayloadâ: data
};
let response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() == 200){
return JSON.parse(response.getContentText());
} else
{
return null;
}
}
function retrieveData(token, device_id, field){
var now = new Date().toISOString();
var yesterday = new Date()
//yesterday.setHours(yesterday.getHours()-5)
yesterday.setDate(yesterday.getDate()-1)
yesterday = yesterday.toISOString()
var options = {
âmethodâ: âgetâ,
âheadersâ: {
âAuthorizationâ: "bearer " + token
},
};
var url = âhttps://api.autopi.io/logbook/storage/read/â+
â?from_utc=â+yesterday+
â&device_id=â+device_id+
â&field_type=primitiveâ+
â&interval=5mâ+
â&field=â+field+
â&page_num=0â
var response = UrlFetchApp.fetch(url, options);
var data = JSON.parse(response.getContentText())
return(data)
}
function insertData(data){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(âtestâ);
sheet.getLast
sheet.clear();
var sheetRows = []
for(i = 0; i < data.length; i++){
row = []
row[0] = data[i].ts;
row[1] = data[i].value
sheetRows.push(row)
}
range = sheet.getRange(1, 1, sheetRows.length, sheetRows[0].length).setValues(sheetRows);
range.activate();
range.sort({column: 1, ascending: false});
}
I will add it to my GitHub repository tomorrow -
Did this ever get put on github? The formatting on here isnât translating correctly into google sheets.
Hi,
JVTeam, no I had not but have now. apologies, I donât have time to test this over the next 48 hours however will do over
Hello.
Don´t understand the the readme file. Can you explain in other way? How can i install?
Thanks for the help.
Hi,
I will update the readme file however the essential steps
Let me know how you go and where it does not work for you
Hello.
For me does not work. Give me the error TypeError: Cannot read property âlengthâ of undefined (linha 68, arquivo âCĂłdigoâ)
Line 68
range = sheet.getRange(1, 1, sheetRows.length, sheetRows[0].length).setValues(sheetRows);
Cant see what is worgâŚ
Hi,
The issue is that there is no data being returned from the call.
The good news is that the authentication is working however there are probably two reasons
You donât have rpm data ? Can you confirm you have a PID names rpm. I am pretty sure you will.
The other potential problem is that the time frame is to short. Currently it is retrieving data of the last 24 hours. If you have not logged any data in 24 hours then this is probably the problem. You can test that by changing the 1 on line 32 (1 day ) to how many days you want 1 - 700 ?
Let me know how it goes
Hello.
Iâm sorry, my mistake. I was using it on my electric vehicle so I didnât change the RMP field to another one. Using one that I already have data works with. Any way to complete the code in order to gather more obd data?
Thank you for your help.
Hi,
Warning - I suggest you create a new sheet to test this
great to see you have been successful - I had only really intended this to be a proof of capability but happy to extend its capability over the next bit to include over PIDs. I have made a quick change which should allow you to have as many PIDs as you want (you will need to add them like const RPM = ârpmâ and add them to the array (as per the code)
Over the next while I might see if I can make it more extensible, particularly so it will add to data rather than overwriting but at the moment it should bring back data (where it exists for the last 24 hours). You can make that window wider by changing the 1 (day) to more.
Let me know how you go
Hello.
Just to say that the code work very good. No problem at all.
Thanks for the help.
Hi,
Great to see that it worked. Hopefully over the next few days, I will add the capability to retrieve from the last record and cap the number of rows at a defined limit, this will make it easier to manage over the medium term. Let me know if there is any other functionality that you are keen to see
Chris