Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modified version of Henrik Bengtsson's speedtest-cli code which will dispatch the test results to the IFTTT Maker Channel.
#!/usr/bin/env bash
###########################################################################
# Originally written by: Henrik Bengtsson, 2014
# https://github.com/HenrikBengtsson/speedtest-cli-extras
# Modified to use IFTTT by: Alasdair Allan, 2015
# License: GPL (>= 2.1) [http://www.gnu.org/licenses/gpl.html]
###########################################################################
# Character for separating values
# (commas are not safe, because some servers return speeds with commas)
sep=";"
# Temporary file holding speedtest-cli output
user=$USER
if test -z $user; then
user=$USERNAME
fi
log=/tmp/$user/speedtest-csv.log
# Local functions
function str_extract() {
pattern=$1
# Extract
res=`grep "$pattern" $log | sed "s/$pattern//g"`
# Drop trailing ...
res=`echo $res | sed 's/[.][.][.]//g'`
# Trim
res=`echo $res | sed 's/^ *//g' | sed 's/ *$//g'`
echo $res
}
# Display header?
if test "$1" = "--header"; then
start="start"
stop="stop"
from="from"
from_ip="from_ip"
server="server"
server_dist="server_dist"
server_ping="server_ping"
download="download"
upload="upload"
share_url="share_url"
else
mkdir -p `dirname $log`
start=`date +"%Y-%m-%d %H:%M:%S"`
if test -n "$SPEEDTEST_CSV_SKIP" && test -f "$log"; then
# Reuse existing results (useful for debugging)
1>&2 echo "** Reusing existing results: $log"
else
# Query Speedtest
/usr/local/bin/speedtest-cli --share > $log
fi
stop=`date +"%Y-%m-%d %H:%M:%S"`
# Parse
from=`str_extract "Testing from "`
from_ip=`echo $from | sed 's/.*(//g' | sed 's/).*//g'`
from=`echo $from | sed 's/ (.*//g'`
server=`str_extract "Hosted by "`
server_ping=`echo $server | sed 's/.*: //g'`
server=`echo $server | sed 's/: .*//g'`
server_dist=`echo $server | sed 's/.*\\[//g' | sed 's/\\].*//g'`
server=`echo $server | sed 's/ \\[.*//g'`
download=`str_extract "Download: "`
upload=`str_extract "Upload: "`
share_url=`str_extract "Share results: "`
fi
# Standardize units?
if test "$1" = "--standardize"; then
download=`echo $download | sed 's/Mbits/Mbit/'`
upload=`echo $upload | sed 's/Mbits/Mbit/'`
fi
# Send to IFTTT
secret_key="SECRET_KEY"
value1=`echo $server_ping | cut -d" " -f1`
value2=`echo $download | cut -d" " -f1`
value3=`echo $upload | cut -d" " -f1`
json="{\"value1\":\"${value1}\",\"value2\":\"${value2}\",\"value3\":\"${value3}\"}"
curl -X POST -H "Content-Type: application/json" -d "${json}" https://maker.ifttt.com/trigger/speedtest/with/key/${secret_key}
@jscongdon

This comment has been minimized.

Copy link

@jscongdon jscongdon commented Feb 3, 2016

I'm not super familiar with Bash.... but when I try to run this script - I'm getting:
./speedtest-ifttt.sh: 21: ./speedtest-ifttt.sh: Syntax error: "(" unexpected

It shouldn't have any impact but I have substituted my secret key.

I figured out why it wasn't working... though the sheet is not being created in my gDrive... working on that issue now

Found the sheet, sync issue with my local machine 😒

@lubosm

This comment has been minimized.

Copy link

@lubosm lubosm commented Feb 25, 2016

:( hmm, still Syntax error: "(" unexpected

@salt-lick

This comment has been minimized.

Copy link

@salt-lick salt-lick commented Mar 9, 2016

speedtest-ifttt.sh: 21: speedtest-ifttt.sh: Syntax error: "(" unexpected

@Landei

This comment has been minimized.

Copy link

@Landei Landei commented Mar 9, 2016

If you see "speedtest-ifttt.sh: 21: speedtest-ifttt.sh: Syntax error: "(" unexpected" you have to remove the "function" in line 21.

@salt-lick

This comment has been minimized.

Copy link

@salt-lick salt-lick commented Mar 9, 2016

or run it with ... /bin/bash /speedtest-ifttt.sh

@meaverick

This comment has been minimized.

Copy link

@meaverick meaverick commented Oct 13, 2016

sudo ./speedtest-ifttt.sh
./speedtest-ifttt.sh: line 54: /usr/local/bin/speedtest-cli: No such file or directory
Congratulations! You've fired the speedtest event

@drijd

This comment has been minimized.

Copy link

@drijd drijd commented Nov 25, 2016

Hi,

Thanks so much for your efforts in producing this. I got this working in an evening, which given my skill level, I'm delighted with. If I get chance, I'll write something on the IFTTT setup too, unless you have already blogged that somewhere?

Thanks once again,

Ian

@Stybyk

This comment has been minimized.

Copy link

@Stybyk Stybyk commented Feb 13, 2017

Hello,
i have same problem. I try to create exact folder with exact empty spreadsheet.
In addon activity log i have "Applet updated" messages witch "log speedtest results to spreadsheet" but google table is still empty.
Where will be problem ?

@babca

This comment has been minimized.

Copy link

@babca babca commented Feb 14, 2017

@Stybyk @vacano tested, it works for me. Current IFFFT web interface is a bit confusing, maybe you have a mistake in your configuration.

Make sure you have "Log Speedtest results to Spreadsheet" applet in https://ifttt.com/my_applets
Click on the applet and then click on "Check now". Is the check working? It should say "Applet checked".
If not, check the applet settings:

event name speedtest
spreadsheet name MyAutoSpeedtest
formatted row {{OccurredAt}}
Drive folder path speedtests/{{EventName}}

Then open Maker service setting page: https://ifttt.com/services/maker/settings
You will see an account info:

Account Info
Connected as your nickname
URL https://maker.ifttt.com/use/__________YOUR_KEY__________
Status active

Select and open your URL in your browser to test your applet manually.
Fill the inputs with test data: {event} = speedtest, value1 = 1, value2 = 1, value3 = 1 and submit with Test it button.
You will see a new spreadsheet in sheets.google.com with 1, 1, 1 data row.

Finally, copy/paste YOUR_KEY into the speedtest-ifttt.sh script (line 82) and run your script. It should work OOB.

@epifano83

This comment has been minimized.

Copy link

@epifano83 epifano83 commented Mar 19, 2017

I keep running into an issue with my key do I enter it in both fields listed secret key?

Send to IFTTT

secret_key="SECRET_KEY"
value1=echo $server_ping | cut -d" " -f1
value2=echo $download | cut -d" " -f1
value3=echo $upload | cut -d" " -f1
json="{"value1":"${value1}","value2":"${value2}","value3":"${value3}"}"
curl -X POST -H "Content-Type: application/json" -d "${json}" https://maker.ifttt.com/trigger/speedtest/with/key/${secret_key}

@epifano83

This comment has been minimized.

Copy link

@epifano83 epifano83 commented Mar 19, 2017

I answered my own question updated both fields with my key however my main issue was I never name my applet on Maker Web Hooks..

@esharksolutions

This comment has been minimized.

Copy link

@esharksolutions esharksolutions commented May 20, 2017

Fantastic mod of speedtest-extras - question regarding output to Google Sheet:
The date/time appears in my Google Sheet as May 1, 2017 at 12:00am
Can the script be modified to add a leading zero to single digit dates so it inserts into Google Sheet as May 01, 2017 at 12:00am?

@garycrj

This comment has been minimized.

Copy link

@garycrj garycrj commented Jun 29, 2017

sudo ./speedtest-ifttt.sh
./speedtest-ifttt.sh: line 54: /usr/local/bin/speedtest-cli: No such file or directory
Congratulations! You've fired the speedtest event

@walkingman63

This comment has been minimized.

Copy link

@walkingman63 walkingman63 commented Sep 27, 2017

Hi
Just set this up and it works as it should (top Job from you).
Is there away to change the date time format to 27/09/2017 09:44:29
Thanks in advance

@wesleycombs

This comment has been minimized.

Copy link

@wesleycombs wesleycombs commented Oct 10, 2017

@garycrj perhaps you dont have speedtest-cli installed? sudo pip install speedtest-cli

@wesleycombs

This comment has been minimized.

Copy link

@wesleycombs wesleycombs commented Oct 10, 2017

I got it working, but I am getting a random decimal in front of some of my download readings. I havent been able to track it down to a particular pattern. Maybe its a certain server that is returning the data in a strange format?
image

@hornjt75862

This comment has been minimized.

Copy link

@hornjt75862 hornjt75862 commented Nov 11, 2017

I am trying to figure out how to find out what the "SECRET_KEY" value needs to be

@OhioJoe

This comment has been minimized.

Copy link

@OhioJoe OhioJoe commented Nov 12, 2017

@hornjt75862, Secret_Key ->
log in to your IFTTT account: https://ifttt.com/
Click on your name (upper right hand corner of web page)
Click on Services
Click on Webhooks
Click on Settings (upper right hand corner of web page, under your name)
You should see : URL https://maker.ifttt.com/use/#####
The ##### part is your Secret Key!

Edit line #82(above -in the code)secret_key="SECRET_KEY"
Replace "SECRET_KEY" with "#####" what every was that part of the URL above.
DO NOT edit the last line #87.

Hope this helps

@OhioJoe

This comment has been minimized.

Copy link

@OhioJoe OhioJoe commented Nov 13, 2017

Your secret key is generated when you connect the IFTTT maker channel, and is shown here, https://ifttt.com/maker

@AndrewLindsay

This comment has been minimized.

Copy link

@AndrewLindsay AndrewLindsay commented Nov 17, 2017

I’ve got everything running (apparently) I get the message ‘Congratulations! You’ve fired the speedtest event’ but I don’t get a spreadsheet created in my google sheets.

Any pointers on what I have to do to get this link working?

@teshiburu

This comment has been minimized.

Copy link

@teshiburu teshiburu commented Nov 30, 2017

Hi - i was wondering if there was a way to get this to pass a 4th value to the IFTTT channel.

I added the relevant values here (value4)

value1=echo $server_ping | cut -d" " -f1
value2=echo $download | cut -d" " -f1
value3=echo $upload | cut -d" " -f1
value4=echo $server | cut -d" " -f1
json="{"value1":"${value1}","value2":"${value2}","value3":"${value3}","value4":"${value4}"}"
curl -X POST -H "Content-Type: application/json" -d "${json}" https://maker.ifttt.com/trigger/speedtest/with/key/${secret_key}

But when i go to the IFTTT applet and att |||{{value4}} to the applet it says there is an error and wont let me save :(

@kokest

This comment has been minimized.

Copy link

@kokest kokest commented Dec 14, 2017

i keep getting the following error : speedtest-ifttt.sh: line 87: curl: command not found
i havent changed anything on line 87. any ideas?

@mrminus

This comment has been minimized.

Copy link

@mrminus mrminus commented Dec 30, 2017

I have this working and posting to Google Sheets via IFTTT without any issues. I do have a few questions that maybe the author or another user can opine on:

  1. The standard ingredient for date/time is in UCT and has that annoying "at" in it. I can convert it in my sheet to my local time (because, if I want to know when something went below my threshold I really do need it in my local time...). How can I just have the IFTTT ingredient give me US/PST?
  2. I added my own field for tracking the ongoing percentage delta test to test. I do that via the calculation of : (currentDL - previousDL) / previousDL, and formatting the cell as a percent. I included a screen shot. Since the script appends to the google sheet in the next row, is there any way, and this is a Sheets question mostly, to pre-populate the formula to the cell so that when the applet does the append the calculation is already there? right now i have to do a drag/copy every few hours.
    internet-tracking

by the way, this is how i'm calculating the local time from UCT.

=(datevalue(regexextract(A2, "^(.+) at ")) + time(regexextract(A2, "(?i) at (\d+):") + 12 * (right(A2, 2) = "PM") * (regexextract(A2, "(?i) at (\d+):") <> "12") - 12 * (right(A2, 2) = "AM") * (regexextract(A2, "(?i) at (\d+):") = "12"), regexextract(A2, "(?i) at .+:(\d*)[ap]m$"), 0))-time(8,0,0)

@pbouianov

This comment has been minimized.

Copy link

@pbouianov pbouianov commented Jan 1, 2018

Not sure about #1 as for me that ingredient comes w/ local time (though I do have that annoying string format), but your #2 custom field can be done w/ something like

=(INDIRECT(CONCAT("E", ROW()))-INDIRECT(CONCAT("E", ROW()-1)))/INDIRECT(CONCAT("E", ROW()-1))

Just change the colname to your download speed col.

@shanep2300

This comment has been minimized.

Copy link

@shanep2300 shanep2300 commented Feb 27, 2018

Is there any update to the script or where it pulls the speeds from? At my old apartment I was paying for 60Mb/s down and my sheets were correctly averaging around 60. Now that I'm at a new location and new house, I'm paying for 100Mb/s down and it's averaging at 70. When I use speedtest.net, it shows 70Mb/s. When I use speedof.me it shows 100Mb/s+. Bandwidthplace.com shows around 70. And testmy.net shows 100Mb/s+. So, which is it!?

@HughP

This comment has been minimized.

Copy link

@HughP HughP commented Mar 17, 2018

Is there a way to record the mac address of the triggering machine?

@davedavis

This comment has been minimized.

Copy link

@davedavis davedavis commented Apr 9, 2018

@mrminus Did you ever figure that out? Could you share?

@GenerlAce

This comment has been minimized.

Copy link

@GenerlAce GenerlAce commented Aug 28, 2018

is this still working? i cannot for the life of me get this to create a spreadsheet on google.

@gitricko

This comment has been minimized.

Copy link

@gitricko gitricko commented Sep 22, 2018

me too !

@dantgal

This comment has been minimized.

Copy link

@dantgal dantgal commented Oct 18, 2018

Doesn't work anymore, probably cause of changes with API Google:
Applet failed
Oct 18 - 10:44 PM
Webhooks
Log Speedtest results to Spreadsheet
There was a problem with the Google Sheets service.

@RealDyllon

This comment has been minimized.

Copy link

@RealDyllon RealDyllon commented Mar 10, 2019

@dantgal

The script does work if you follow the instructions here: http://grantglazer.com/automatically-log-your-internet-speeds-with-a-raspberry-pi/

If you still experience the Google Sheets error, the disconnect the Google Drive service in IFTTT, and reconnect it. That should fix your issue.

@mistergrumpy

This comment has been minimized.

Copy link

@mistergrumpy mistergrumpy commented Apr 6, 2019

The script doesn't work. I think it's something to do with IFTT and Google and the triggers.

@paperjam2032

This comment has been minimized.

Copy link

@paperjam2032 paperjam2032 commented Aug 16, 2019

i got it working previously, but now, im trying to look for the secretkey in ifttt.com. its just not there anymore.
i know thati need the secretkey to get it working tho.

@jackdanpr

This comment has been minimized.

Copy link

@jackdanpr jackdanpr commented Mar 4, 2020

Hi - i was wondering if there was a way to get this to pass a 4th value to the IFTTT channel.

I added the relevant values here (value4)

value1=echo $server_ping | cut -d" " -f1
value2=echo $download | cut -d" " -f1
value3=echo $upload | cut -d" " -f1
value4=echo $server | cut -d" " -f1
json="{"value1":"${value1}","value2":"${value2}","value3":"${value3}","value4":"${value4}"}"
curl -X POST -H "Content-Type: application/json" -d "${json}" https://maker.ifttt.com/trigger/speedtest/with/key/${secret_key}

But when i go to the IFTTT applet and att |||{{value4}} to the applet it says there is an error and wont let me save :(

I know it's an old post, but, did you ever figure it out? It's suppose to parse the new value but doesn't work...
Thanks,

@aallan

This comment has been minimized.

Copy link
Owner Author

@aallan aallan commented Mar 4, 2020

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented May 29, 2020

I am getting leading decimals in my output.

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented Jun 1, 2020

I am getting leading decimals in my output.

I was able to resolve this using sed to replace leading decimal points with nothing.

github

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 17, 2020

I am not getting anything in google drive. When clicking the check now in the IFTTT recipe I get a 'There was an error during check process' message. Any ideas??

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented Jun 17, 2020

I am not getting anything in google drive. When clicking the check now in the IFTTT recipe I get a 'There was an error during check process' message. Any ideas??

Did you set the trigger in ifttt to "speedtest"

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 17, 2020

@kkasberg sorry I am new to IFTTT but if you mean the title of the applet then yes.

Screenshot 2020-06-17 at 18 18 33

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented Jun 17, 2020

@kkasberg sorry I am new to IFTTT but if you mean the title of the applet then yes.

Screenshot 2020-06-17 at 18 18 33

I mean where it says "Event Name" (blank above) use "Speedtest".

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 17, 2020

https://maker.ifttt.com/trigger/speedteest/with/key/ gives me:
Congratulations! You've fired the speedtest event

But still nothing in google drive

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented Jun 17, 2020

https://maker.ifttt.com/trigger/speedteest/with/key/ gives me:
Congratulations! You've fired the speedtest event

But still nothing in google drive

It will give that result because the event fired is "speedtest". I in ifttt you don't enter that as the event name it won't post to google sheets.

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 17, 2020

I see this in the activity:
Screenshot 2020-06-17 at 18 26 44

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented Jun 17, 2020

I see this in the activity:
Screenshot 2020-06-17 at 18 26 44

It is saying that your trigger field is still empty. It needs to be "speedtest" under "Event Name".

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 18, 2020

Ok I have added that and getting somewhere now however nothing appears in Google Sheets unless I hit the Check Now button in IFTTT. Doing this seems to then send all the 'queued' entries.
What could be causing this?

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 18, 2020

It actually seems to do nothing for a while then several readings all come through together. I have it set to every 15mins in the cronjob but it takes a few hours to get written to google sheets.

@kkasberg

This comment has been minimized.

Copy link

@kkasberg kkasberg commented Jun 18, 2020

It actually seems to do nothing for a while then several readings all come through together. I have it set to every 15mins in the cronjob but it takes a few hours to get written to google sheets.

This happened to me also, and I resolved it by deleting my webhook secret key and having a new one created (then adding the new one back into the scripts).

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 18, 2020

Thanks @kkasberg I will try that.

@jonmoore-pulse

This comment has been minimized.

Copy link

@jonmoore-pulse jonmoore-pulse commented Jun 19, 2020

Working!

@johenkel

This comment has been minimized.

Copy link

@johenkel johenkel commented Nov 19, 2020

Everything was working great. On the sudden the script started filling it into a new spreadsheet speedtest(1) .... not sure where the copy came from and why its just posting it in there.

@aallan

This comment has been minimized.

Copy link
Owner Author

@aallan aallan commented Nov 19, 2020

Everything was working great. On the sudden the script started filling it into a new spreadsheet speedtest(1) .... not sure where the copy came from and why its just posting it in there.

Google Sheets have a maximum number of rows. Once you exceed that number it will auto-magically generate a new sheet.

@JeremyDurnell

This comment has been minimized.

Copy link

@JeremyDurnell JeremyDurnell commented Mar 20, 2021

This has been working great since I started using it over a year ago, but it looks like something has changed on the IFTTT platform. The recipe, and my applet, both 404 now. It looks like it stopped working on March 8, 2021 around 2 PM CST. I'm wondering if anyone has found a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment