Searching for some text in a variable

1,895 views
Skip to first unread message

tlamik

unread,
Feb 22, 2013, 3:10:54 PM2/22/13
to tas...@googlegroups.com

I am trying to make a task within Tasker, which will be count for some special data from incoming SMS. Every SMS could be write in different style. These are a few examples:

AUSDF001 Device is not working

ARFS97A Device is working now

TFDAAAA Home Device is off

HFGRTEUZTG1 Washington is ON

Every SMS contains one device and one state of that device.

I want to Tasker search for text the name of each device ("AUSDF001" or "ARFS97A" or "TFDAAAA Home" or "HFGRTEUZTG1 Washington", as You can see it may be one or two word)

I don't know all device's names. I want to save actual state of each device which send me SMS and show in Minimalistic Text or Tasker Sceen for example.

I need to save first word of every SMS and compare that against something, then try to save first and second word and compare too ? And then search for "not working", "is working" , "OFF" and "ON" ?

I know all incoming SMS body is in %SMSRB, but I don't know howto search for some text within a variable.

Any idea appreciated.


Regards,


Tlamik

bdanders

unread,
Feb 22, 2013, 3:26:00 PM2/22/13
to tas...@googlegroups.com
First thing I would do is set a local variable to %SMSRB so you don't have a bunch of empty useless globals clogging things up. Let's call it %sms.
Then, Split %sms with " is ". %sms2 will be the state. You can tackle separating %sms1 a couple different ways. One way is to separate by " " (space) and then loop through the results (%sms11, %sms12, %sms13, etc.) until you get to the end to account for any number of words in the device name. The other method would be to use a regular expression that grabs all text after the first space and saves that as a variable (Task: Variable search and replace of %sms1, Store Matches In %device). I'm not great with RegExs so you'll have to do a little searching to figure that one out.

bdanders

unread,
Feb 22, 2013, 3:47:43 PM2/22/13
to tas...@googlegroups.com
I think this does what you want:

Test
A1: Variable Set [ Name:%sms To:TFDAAAA Home Device is working now Do Maths:Off Append:Off ]
A2: Variable Split [ Name:%sms Splitter: is Delete Base:Off ]
A3: Variable Set [ Name:%status To:%sms2 Do Maths:Off Append:Off ]
A4: Variable Search Replace [ Variable:%sms1 Search:\s(.+)$ Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%device Replace Matches:On Replace With: ]
A5: Variable Set [ Name:%device_id To:%sms1 Do Maths:Off Append:Off ]
A6: Flash [ Text:%device_id
%device1
%status Long:On ]

On Friday, February 22, 2013 3:10:54 PM UTC-5, tlamik wrote:

tlamik

unread,
Feb 23, 2013, 10:23:31 AM2/23/13
to tas...@googlegroups.com
Nice work, thanks a lot.
Now I have device and its status. I want to create a list of not working devices (Minimalistic Text Widget or Tasker Scene).
Mine idea is the list will show not working devices and when I receive SMS with some working device, that device disappear from the list.
I can save all not working devices in file and visualise that file, but how can I delete one device from that file ?
I am thinking about one stuff. Can I create a new variables which will be hold the name of device and how ?
Like:
%AUSDF001 - Device
%ARFS97A Device
%TFDAAAA Home Device
%HFGRTEUZTG1 Washington

Or I have to use some kind of array ?







Dne pátek, 22. února 2013 21:47:43 UTC+1 bdanders napsal(a):

Matt R

unread,
Feb 23, 2013, 8:43:26 PM2/23/13
to tas...@googlegroups.com
Use an array. They're explained in the user guide at the bottom of the variables section. Then you can push and pop names to and from a list very easily.

Matt

tlamik

unread,
Feb 25, 2013, 1:54:45 AM2/25/13
to tas...@googlegroups.com
Thanks. I played with an arrays whole weekend. I have a new question in my case. I pickup a message body from %SMSRB and it's fine, but when I receive a lot of SMS in the same time, there is a problem, perhaps Tasker is unable to catch them all. Is it possible ? I received 6 SMS for example, but in the log file (which is written by Tasker, there are 5 only)

Matt R

unread,
Feb 25, 2013, 2:15:32 AM2/25/13
to tas...@googlegroups.com
I suppose it's possible. When you say log file do you mean the run log? Try raising the profile priority to see if that helps.

Matt

tlamik

unread,
Feb 25, 2013, 2:23:30 AM2/25/13
to tas...@googlegroups.com
No, log file I mean this i my task:
A1: Variable Set [ Name:%sms To:%SMSRB Do Maths:Off Append:Off ]
A2: Variable Split [ Name:%sms Splitter:: Delete Base:Off ]
A3: Variable Split [ Name:%sms2 Splitter: Delete Base:Off ]
A4: Write File [ File:/mnt/emmc/hotline/pocitadlo.txt Text:%DATE %TIME sms=%sms sms1=%sms1 sms2=%sms2 sms21=%sms21 sms22=%sms22 Append:On Add Newline:On ] 

maybe I should use internal memory instead of microSD ?

Matt R

unread,
Feb 25, 2013, 11:43:36 AM2/25/13
to tas...@googlegroups.com
Yes, writing to a file could certainly be slow enough that you could miss something. Get rid of the write to file if you can. Otherwise, you'll need to make an array that you can quickly push the data to (that runs at a high priority), and then have a lower priority task that works through the array to write all the data to file.

Matt

tlamik

unread,
Feb 25, 2013, 2:00:33 PM2/25/13
to tas...@googlegroups.com
Thanks, I'll be monitor if it will happend again then I'll try to get rid of write to file.

Dne pondělí, 25. února 2013 17:43:36 UTC+1 Matt R napsal(a):
Reply all
Reply to author
Forward
0 new messages