Skip to main content
  1. Posts/

Collect Ather Logs in Google Sheets via Telegram Bot

I have been using the Ather 450X for over 8 months now. I prefer driving this vehicle more compared to my previous ones.

The Ather app provides statistics such as the last 20 rides, monthly ride logs, charging statistics, etc. However, they recently stopped sending monthly logs. To continue analyzing the data, I decided to collect the logs myself.

Follow this post, if you wish to setup API based automatic bot.

Purpose #

My aim was to track trends in my monthly driving distance, monitor expected range variations, and evaluate whether these metrics are increasing or decreasing over time. The monthly ride logs were helpful, but since Ather discontinued them, there’s no single place to view all the monthly data. I used to rely on my previous emails to access them.

I wanted to take charge of collecting the logs, incorporate additional metrics not provided by Ather, such as Battery Usage for each ride, Daily and Monthly Battery Usage, and Battery Consumption per Kilometer. By managing my data, I can access it at my convenience.

Thought Process #

Initially, I considered manually collecting statistics using a webpage. However, I realized this could become cumbersome and might discourage me from maintaining the logs over time. I opted for the option in the Ather app to share ride statistics as images for their marketing purposes.

I planned to run Optical Character Recognition (OCR) on these images to extract relevant text values and then organize them systematically. This way, I wouldn’t lose interest in maintaining the logs, as it require less work.

Tools #

I needed tools for the following steps:

  1. Collect input from the Ather app.
  2. Process OCR and convert to data points.
  3. Store organized data.
  4. Set up reports for trend analysis.
  5. Automate the process.
  6. Keep costs low or free.

After consideration, I settled on the following tools:

  1. Collect input from Ather app: Telegram / Telegram bot.
  2. Process OCR and convert to data points: Google Docs.
  3. Store organized data: Google Sheets.
  4. Set up trend analysis reports: Google Sheets.
  5. Automate the process: Google Scripts.
  6. Keep costs low or free: All tools above are free within certain limits.

How It Works #

  1. Open the Ather app and access ride statistics, which includes details like Date, Distance Traveled, Time Spent, Efficiency, Projected Range, and Top Speed for the last 20 rides.
  2. Share the ride statistics image with my Telegram bot.
  3. The bot sends the image to Google Drive.
  4. A script retrieves the image, converts it to text and data points.
  5. The script organizes the data and places it in the correct columns.
  6. Google Sheets summarizes the data and generates update charts.
  7. The Telegram bot sends a summary of the extracted image information.
  8. The Telegram bot provides options to view ride statistics as graphs.

Setup #

Requirements #

To set up a similar system for personal use, you’ll need:

  • A Google account.
  • A Telegram account.
  • A computer (setting up on a mobile device is challenging).
  • Some time and patience.

Setting up Telegram Bot #

  1. Search for BotFather on Telegram or use this link: https://t.me/BotFather.
  2. Start a chat and choose /newbot from the menu.
  3. Provide basic information such as Bot’s name and username (naming rules apply).

Botfather

Refer this API Token as BOT TOKEN.

Setting up Google Sheets #

Make a copy of this Google Sheet: Google Sheets Template.

google-sheet-make-a-copy

It will ask you to name the file and also highlight that the scripts also will be saved.

google-sheet-make-copy-name

You can rename the sheet the way you want and click ‘Make a copy’. Once the file is saved, you will be able to make edits to the sheet.

Setting up Google Drive #

Visit https://drive.google.com/ and create a new folder.

google-drive-new-folder

Choose a name, such as ‘Ride Logs’, and securely save the content from the address bar, as highlighted below. This information will be utilized in the subsequent step.

google-drive-url

We’ll refer to this section as the DRIVE ID

Setting up Script #

Access Google Apps Script via the “Extensions” menu in Google Sheets.

google-app-script-start
Rename the project to match your sheet’s name (optional). Deploy the script, authorizing necessary permissions.
script-deploy-button

You will get a pop-up like below. Make sure you select the highlighted poritions. If you make mistakes here, your bot will not work.

script-deploy-1st

Then you need to follow the steps as highlighted in the screenshots. These steps are required to access your google drive, google sheets, google docs and slides, to process further.

script-authorize-access

Choose your gmail ID, if you don’t want to use your primary gmail you can create a new one.

script-authorize-gmail

You will get a warning that the app is unverified. Click advanced

script-authorized-advanced

Click go to ‘your google sheet file name’

script-authorize-unsafe

Click Allow

script-authorize-allow

You will get a deployment URL. Keep it safe and do not share it with anyone.

script-deploy-copy-url

lets call this URL as WEBHOOK for time being.
WARNING Do not try to deploying multiple times, if the URL changes then you need to modify few things later.

Now click the gear icon on the left pane, which will open up the project settings.

script-project-settings

Scroll to the bottom where you can see the Script Properties, then click on ‘Add Script Property’ button

script-property-button

Update Script Properties #

IMPORTANT This portion is very important. If anything missed out, the whole process might fail.

Create the following Script Properties. To avoid spell error, copy and paste.

ADMIN
ALLOWED_USER_IDS
DRIVE_FOLDER_ID
DOC_ID
SLIDE_ID
WEBHOOK_URL
bot_token

The suggested values to be set on the Script Properties.

Variable / PropertyValueRemarks
ADMINYour Telegram IDA numeric Value. Explained in later part how to get this.
ALLOWED_USER_IDSYour Telegram ID, If you want someone else to access your botA numeric Value. Explained in later part how to get this.
DRIVE_FOLDER_IDCreate a folder in Google Drive and update the ID hereGet it from Address bar. Only the ID not the URL
DOC_IDCreate a Doc file in Google Drive and update the ID hereGet it from Address bar. Only the ID not the URL
SLIDE_IDCreate a slide from Google Drive and update the ID hereGet it from Address bar. Only the ID not the URL
WEBHOOK_URLRead the instructions from blog postKeep it safe, do not share it with anyone.
bot_tokenYour telegram bot token form BotFatherKeep it safe, don’t share it withanyone.

It should look like the below picture.

script-properties-list

Then click ‘Save Script Properties’ Button.

Deploy it Again #

The changes that we made in the script properties should be deployed again. But this time, we need to deploy a new version.

Click the ‘Deploy’ Button, then click ‘Manage Deployments’.

script-deploy-manage-deployments

WARNING Do not click the new deployment. If you do, the webhook URL will change and it has to be reset.

Click on the pencil icon,on the version drop down choose ‘New Version’, then deploy.

IMPORTANT This step has to be done whenever we change something on the code or script properties.

script-deploy-new-version

Setup Webhook and Get Telegram User Info #

Now we need to set up the ADMIN and ALLOWED_USER_IDS, so that the bot can be accessible only to the intendented users. For that, go to Script editor from the left pane.

script-editor

Then go to bot.gs file. You will see many functions like getMe(), setWebhook(), etc.,

from the top select getMe then click Run. You will get a success message in the execution log on the bottom.

script-run-get-me

Now do the same for setWebhook.

script-run-set-webhook

Once it is done Deploy It Again.

SUCCESS: if you are getting a result as ‘ok: true’ then, you have followed the steps without any mistakes.

Once the webhook is setup the telegram bot that we created above will start working.

Open the telegram app and open the bot that you have created. If you don’t know the bot, the link would be available in BotFather.

Hit ‘Start’ button. You need to get a message like

Hey firstName Thank you for the interest in using this bot…….. for more information about this project. Your ID is chatId.

Note the chatID and this is going to be our ADMIN and ALLOWED_USER_IDS.

telegram-user-not-authorized

Follow the steps explained in the Update Script Properties and fill in ADMIN and ALLOWED_USER_IDS.

So your script proprties should have the telegram numeric IDs something like this.

script-properties-id

Now go back to telegram and send a message /start. You should be getting a welcome message.

SUCCESS: You have setup this properly if you have set it up properly. If it is not working follow step Deploy It Again.

Usage #

  1. You can clear the contents from ‘Data’ sheet from row no.2 onwards.
  2. Do not delete the titles.
  3. Do not make any changes on the other sheets, unless you know what you are doing.
  4. Share the ride log image with the Telegram bot.
  5. The script extracts and populates data in the ‘Data’ sheet.
    ride-log-sample

Telegram bot menu #

We don’t get menus by default on the bot. The bottom text input box would look like this at this stage.

To enable menu and commands, touch the name of the bot.

telegram-bottom-wo-menu

Touch the pencil icon.

telegram-bot-edit

Touch ‘Edit commands’ option

telegram-bot-edit-commands

The Botfather window would open and ask for commands. Copy and paste the following.

telegram-botfather-commands

start - Initiate the bot
daily_charts - Day level stats
weekly_charts - Week level stats
monthly_charts - Month level stats
IMPORTANT Do not make spell error, also the commands are case sensitive.

Once it is pasted the menu will be activated for the bot you have creaged and it will look like this.

telegram-bottom-with-menu

Choosing menu and relevant buttons will bring charts for analysis.

telegram-charts

Sample Charts #

Here are some sample charts:

  • Distance vs. Range:
    Sample Chart 1
  • Distance vs. Efficiency:
    Sample Chart 2
  • Distance vs. Battery % per Km:
    Sample Chart 3
  • Daily battery usage in %:
    Sample Chart 4

Important Notes #

  1. The script will process data extracted from the ride log image; if the source is incorrect the result also will be incorrect.
  2. Ather’s average speed calculation differs from the script due to how stop time is handled. I feel the calculation on Ather’s side also incorrect.
  3. This data is intended for educational use only.
  4. The script’s security vulnerabilities were checked, but use at your own risk.
  5. This data shouldn’t be used for legal or official purposes.
  6. The code can be modified, enhanced, redistributed, or sold.
  7. The project is provided to support the community, without expectations of monetary gain.

For questions, contact me on this Telegram channel. I’ll respond when available, but immediate support isn’t guaranteed.