How to have Tasker read the last line of a .csv (Excel) file. (Tasker/Torque integration)

1,399 views
Skip to first unread message

James Watkins

unread,
Jul 27, 2014, 12:36:48 PM7/27/14
to tas...@googlegroups.com
Hey all,
I have a Profile that activates when my phone connects to the Bluetooth in my car.

The tasks that follow are things that include disabling an ambient volume detection, maxing out my phone's volume, opening Torque, enabling a notification reader so my phone reads out texts and emails that I receive while driving, and plays music via a Poweramp playlist.

What I'm trying to add to this now is the ability to integrate Tasker and Torque.  Upon turning off and exiting my car I was hoping to use the exit task of the above mentioned profile to have Tasker close Torque which I've been able to accomplish, and read the logs from Torque to inform me of things like the total distance I drove since starting my car, average MPG of my trip, and any other bits of data that Torque wrote to the log.
  
I've tried various ways of having Tasker read the log but they have all failed.  I tried having Tasker read the log and split up the data into separate variables separated by a comma but Tasker created over 24,000 different variables and my phone didn't like that very much.

I've tried using a run shell command so Tasker reads only the last row in the log but every attempt I've tried with having Tasker read the .csv file have been unsuccessful.  I was hoping for someone with a bit more experience than me could inform me what I'm doing wrong with the shell command, or if they know of a better way to have Tasker read the file please inform me of how to do this better.

I've tried: tail -1 /storage/emulated/0/torqueLogs/trackLog.csv but this returns a variable %Error with sh: <stdin>[2]: tail: not found. I have no idea what this means.

Also, I found the following website which I've been using as a reference to get this to work right but unfortunately I've not gotten it working right.  I'm wondering if the latest updates to tasker since this website was updated no longer work as they designated?



I've gotten pretty experienced with Tasker but I'm pretty clueless with how the shell command feature works.  Any helpful information would be much appreciated.  I'm attaching the .csv file to this post so others can see the data that Torque created from my car.
trackLog.csv

Wietse van Buitenen

unread,
Jul 27, 2014, 1:05:33 PM7/27/14
to tas...@googlegroups.com


On Sunday, July 27, 2014 6:36:48 PM UTC+2, James Watkins wrote:

I've tried: tail -1 /storage/emulated/0/torqueLogs/trackLog.csv but this returns a variable %Error with sh: <stdin>[2]: tail: not found. I have no idea what this means.

this means that tails isn't present on your system.. a lost of common Linux tools are but tail isn't it seems..
There are probably other ways to get this done but I would also lean towards tails as this makes it easier :)

 If you don't mind messing around a bit you could use a full BusyBox binary in Tasker, this should have tail and a lot more.
I wrote a small how-to on how to get this done:
I use this in quite some projects now as it adds a lot of possibilities.

Bob Hansen

unread,
Jul 27, 2014, 2:41:41 PM7/27/14
to tas...@googlegroups.com
This seemed like an interesting challenge so I decided to create a task to read the last line of a file - even when there are 10s of thousands of lines!
This task uses Tasker's file read line action. It searches for the last line and then captures it. It isn't too fast but it works.

Since it is a pretty long task, here is a link to a task file that can be imported: csv.tsk.xml

I am sure there is a more efficient way to do this. 
Here is the task description.

csv (57)
        A1: [X] Variable Set [ Name:%offset To:100 Do Maths:Off Append:Off ]
        A2: Variable Set [ Name:%line To:10000 Do Maths:Off Append:Off ]
        <10000s>
        A3: Read Line [ File:Download/trackLog.csv Line:%line To Var:%temp Continue Task After Error:On ]
        A4: If [ %temp !~ EOF ]
        A5: Variable Set [ Name:%line To:%line + 10000 Do Maths:On Append:Off ]
        A6: Goto [ Type:Action Label Number:3 Label:10000s ]
        A7: Else
        A8: [X] Flash [ Text:%line Long:Off ]
        A9: End If
        A10: Variable Set [ Name:%line To:%line - 10000 Do Maths:On Append:Off ]
        <1000s>
        A11: Read Line [ File:Download/trackLog.csv Line:%line To Var:%temp Continue Task After Error:On ]
        A12: If [ %temp !~ EOF ]
        A13: Variable Set [ Name:%line To:%line + 1000 Do Maths:On Append:Off ]
        A14: Goto [ Type:Action Label Number:3 Label:1000s ]
        A15: Else
        A16: [X] Flash [ Text:%line Long:Off ]
        A17: End If
        A18: Variable Set [ Name:%line To:%line - 1000 Do Maths:On Append:Off ]
        <100s>
        A19: Read Line [ File:Download/trackLog.csv Line:%line To Var:%temp Continue Task After Error:On ]
        A20: If [ %temp !~ EOF ]
        A21: Variable Set [ Name:%line To:%line + 100 Do Maths:On Append:Off ]
        A22: Goto [ Type:Action Label Number:11 Label:100s ]
        A23: Else
        A24: [X] Flash [ Text:%line Long:Off ]
        A25: End If
        A26: Variable Set [ Name:%line To:%line - 100 Do Maths:On Append:Off ]
        <10s>
        A27: Read Line [ File:Download/trackLog.csv Line:%line To Var:%temp Continue Task After Error:On ]
        A28: If [ %temp !~ EOF ]
        A29: Variable Set [ Name:%line To:%line + 10 Do Maths:On Append:Off ]
        A30: Goto [ Type:Action Label Number:19 Label:10s ]
        A31: Else
        A32: [X] Flash [ Text:%line Long:Off ]
        A33: End If
        A34: Variable Set [ Name:%line To:%line - 10 Do Maths:On Append:Off ]
        <1s>
        A35: Read Line [ File:Download/trackLog.csv Line:%line To Var:%temp Continue Task After Error:On ]
        A36: If [ %temp !~ EOF ]
        A37: Variable Set [ Name:%line To:%line + 1 Do Maths:On Append:Off ]
        A38: Goto [ Type:Action Label Number:27 Label:1s ]
        A39: Else
        A40: [X] Flash [ Text:%line Long:Off ]
        A41: End If
        A42: Variable Set [ Name:%lastline To:%line - 1 Do Maths:On Append:Off ]
        A43: [X] Flash [ Text:%lastline Long:Off ]
        A44: Read Line [ File:Download/trackLog.csv Line:%lastline To Var:%data Continue Task After Error:On ]
        A45: Flash [ Text:%data Long:Off ]
        A46: Variable Split [ Name:%data Splitter:, Delete Base:On ]
        A47: Variable Set [ Name:%avg_mpg To:%data(17) Do Maths:Off Append:Off ]
        A48: Flash [ Text:Trip Avg. mpg

%avg_mpg Long:On ]

James Watkins

unread,
Jul 27, 2014, 5:24:37 PM7/27/14
to tas...@googlegroups.com
Oh wow, this task you made is exactly what I was looking for. Thank you very much!  I should be able to modify this and make it suit my needs perfectly.  Thank you very much!

Mike Wilson

unread,
Aug 12, 2014, 3:17:17 PM8/12/14
to tas...@googlegroups.com
I'm doing something similar; trying to get Torque data into Tasker, but in my case I want to add some elements to my main screen to display some relatively slow-changing data (e.g. Distance to Empty, Coolant Temperature, etc.)  I also got hung on the "tail" command (getting the same error as the OP), but I finally found a way to make it work without root.

The trick is to install BusyBox (No Root) from the Play Store (which also requires you to install Terminal Emulator).  Go through all the steps needed to set up the system and after you have pasted in the new path variable into the terminal screen, it will come back and display a path.  Mine looks like this: /data/data/burrows.apps.busybox/app_busybox  

Use that as an explicit prefix to call the tail command:
/data/data/burrows.apps.busybox/app_busybox/tail -1 /storage/emulated/0/torqueLogs/trackLog.csv

Tail doesn't require root unless you want to use it on protected files, so just having an Android-compiled version that you can call works fine for this application.

Once you've set up to Torque properly to log what you want, you can use that that sequence in a Tasker Shell command  to get the last line and use a Variable Split to extract whatever you want.

I've got a profile set up that monitors the Torque log file for any changes and runs the get-and-split task as a result.  By default, Torque writes to the log once per second, which is plenty fast for what I want. (You can decrease the time as well, but I haven't tried it because I don't need that kind of granularity.)


I'm still playing with this to see if it takes too many cycles and slows down the rest of my UI, but so far, it looks promising.

Getting Torque data into Tasker is something I've wanted to do for a long time.

James Watkins

unread,
Aug 14, 2014, 10:00:35 AM8/14/14
to tas...@googlegroups.com
Wow, yeah this method is a lot quicker and far more efficient.  The output only goes to one variable but splitting it into separate variables should be really simple.  Thanks for the suggestion!

James Watkins

unread,
Aug 22, 2016, 7:42:33 PM8/22/16
to Tasker
Well, I'm glad this old thread is still here.

I've upgraded my phone from my Note 3 to the Note 7 and have been bringing all of my tasks over.  Everything is going great with an exception for my Torque integration.  My Run Shell command errors out with the following error:

19.27.32/E Run Shell: %CarData -> %CarData
19.27.32/E Run Shell:  -> 
19.27.32/E Run Shell:  -> 
19.27.32/Shell runBackground /data/data/burrows.apps.busybox/app_busybox/tail -1 /storage/emulated/0/torqueLogs/trackLog.csv root: false timeout: -1
19.27.32/Shell start process-thread ID 24264
19.27.32/E add wait type Shell1 time 2147483647
19.27.32/E add wait type Shell1 done

I've noticed that BusyBox now shows a different path of: /data/user/0/burrows.apps.busybox/app_busybox  which I have tried but I get the same error.  Suggestions?  As far as I've seen the directory of the .csv file hasn't changed on the new phone.  Thanks ahead of time.

Mike Wilson

unread,
Aug 23, 2016, 8:45:27 AM8/23/16
to Tasker
Mine is still working correctly; I haven't changed anything since I wrote that about two years ago.

If you try running the tail command from the BusyBox terminal emulator, does it still error out?

James Watkins

unread,
Aug 23, 2016, 10:05:27 AM8/23/16
to tas...@googlegroups.com
No, I can run it from the terminal emulator and it pulls the last line from the .csv file without issue.  Maybe this is an issue with Tasker then?

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/Cb0-gz-pcAM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Mike Wilson

unread,
Aug 24, 2016, 7:48:01 AM8/24/16
to tas...@googlegroups.com

Either Tasker or the OS.  I'm still running my system on Lollipop...

James Watkins

unread,
Aug 24, 2016, 6:00:22 PM8/24/16
to Tasker
My Note 3 is on Lollipop too and terminal emulator runs fine, Note 7 came with Marshmallow and doesn't seem to want to play nicely.  I'll continue tinkering to see if I can figure this one out.  I'll make another post if I can figure anything out in regards to this.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.

Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/Cb0-gz-pcAM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.

Rolof Tilanus

unread,
Sep 1, 2017, 3:05:35 PM9/1/17
to Tasker
Hi James, I'm having the same problemen. After soms searching on the system, I found tail was installed at /system/bin. So I put this path in the Shell command and it was reading the CSV file. Only if red the shops file instead of the last Line. But no errors. Only have to find a way to have it reading only the last Line.
Reply all
Reply to author
Forward
0 new messages