Saturday, May 25, 2013

[Tasker] How to sync data between devices with Tasker

Sometimes it's handy to have the same data on both devices, or to inform a device about some status of an other device. I want to show you an easy way to send information from one device to another with Tasker and a small PHP file on a web server.

What is possible with this?
  • Display the position of another device directly on the home screen within a widget (I use it for this)
  • React to certain states of another device (like low battery)
  • Send information from android to computer
 What do we need?
  • Tasker
  • Webserver with PHP support
On the server side we need a PHP file named "receive.php" with the following content:
<?php
$file = 'received_data.log';
$handle = fopen($file, 'w') or die('Cannot open file: '.$file);
$data = "";

foreach ($_POST as $key => $value)
{
  $data = $data.$value."\n";
}
fwrite($handle, $data);

fclose($handle);
print("0");
?>
  

Make sure the file has the permission "rw-rw-r--". This script receives data send through a PHP_POST and writes the passed values into a file called "received_data.log". Values of different POST variables are seperated by a newline.

Now Tasker needs to send the desired variables to this php file. The important actions are:
Senddata
A1: HTTP Post [ 
    Server:Port:http://myserver.com/mysite/receive.php
    Path:
    Data / File:data1=hello data2=test data3=%taskervar1 data4=%taskervar2
                data5=%taskervar3 data6=%taskervar4 data7=%taskervar5
    Cookies:
    Timeout:20
    Content Type:application/x-www-form-urlencoded
    Output File:Tasker/data/senddata.log ]
A2: Read File [ File:Tasker/data/senddata.log To Var:%error ]
A3: Popup [ Title: Text:%error
            Background Image:
            Layout:
            Popup Timeout (Seconds):1
            Show Over Keyguard:On ]
In A1 we send the words "hello", "test" and some values stored in the Tasker variables %taskervar1 to %taskervar5 to the PHP script. The PHP script will write the passed values into a new file, each value seperated by a new line. It will return "0" if no errors occurred. So we can check the success of the operation by comparing the local Tasker variable "%error" to "0".

Of course the sending doesn't succeed always, the phone could have no connection at the moment or the server could be down. I came up with the following solution: Try to send the data five times in a row until one sending succeeds, if none got through - Tasker waits a few minutes and tries again five times to send the data. This procedure is repeated until it succeeds. I created two Tasks for this. One for preparing the data and one to send it.
I will show you an example how to send the last seven lines of a file with this method. The task "Data write" is called with a variable passed to it (stored afterwards in %par1). It appends this value to a file if the value isn't already the last value stored there and sends the last seven lines of the file to the server:
Data write
Run Both Together
A1: If [ %par1 !~ %LASTLOG ]
  A2: Variable Set [ Name:%LASTLOG To:%par1 Do Maths:Off Append:Off ]
  A3: Run Shell [ Command:tail -n7 /mnt/sdcard/Tasker/log/Blackbox.log Timeout (Seconds):0 Use Root:Off Store Result In:%log ]
  A4: Write File [ File:Tasker/log/Blackbox.log Text:%log %TIME %par1 Append:Off Add Newline:On ]
  A5: Write File [ File:Tasker/log/BlackboxFull.log Text:%TIME %par1 Append:On Add Newline:Off ]
  A6: Zoom Element Visibility [ Element:Protokoll11.w / logs Set:On ]
  A7: If [ %AIR !~ on ]
    A8: Variable Set [ Name:%num To:1 Do Maths:Off Append:Off ]
    <Post>
    A9: Perform Task [ Name:Data send Stop:Off Priority:7 Parameter 1 (%par1):%num Parameter 2 (%par2): Return Value Variable:%post_success ]
    A10: Wait [ MS:0 Seconds:0 Minutes:3 Hours:0 Days:0 ]
    A11: If [ %post_success !~ 1 ]
      A12: Wait [ MS:0 Seconds:0 Minutes:8 Hours:0 Days:0 ]
      A13: Variable Add [ Name:%num Value:1 Wrap Around:0 ]
      A14: Goto [ Type:Action Label Number:1 Label:Post ]
    A15: End If
    A16: Notify Cancel [ Title:send log Warn Not Exist:Off ]
  A17: End If
A18: End If
A19: Return [ Value:1 Stop:On ]
As you can see, it calls a second task which actually sends the information:
Data Send
Abort Existing Task
A1: Delete File [ File:Tasker/log/Blackboxout.log Shred Level:0 Use Root:Off Continue Task After Error:On ]
A2: Run Shell [ Command:tail -n7 /mnt/sdcard/Tasker/log/Blackbox.log Timeout (Seconds):10 Use Root:Off Store Result In:%log ]
A3: Variable Split [ Name:%log Splitter:%NEWLINE Delete Base:Off ]
A4: Variable Set [ Name:%log4 To:  Do Maths:Off Append:Off ] If [ %log4 ! Set ]
A5: Variable Set [ Name:%log5 To:  Do Maths:Off Append:Off ] If [ %log5 ! Set ]
A6: Variable Set [ Name:%log6 To:  Do Maths:Off Append:Off ] If [ %log6 ! Set ]
A7: Variable Set [ Name:%log7 To:  Do Maths:Off Append:Off ] If [ %log7 ! Set ]
A8: Variable Set [ Name:%post_ok To:0 Do Maths:Off Append:Off ]
A9: For [ Variable:%num Items:1:5 ]
  A10: Variable Set [ Name:%counter To:%par1*10+%num Do Maths:On Append:Off ]
  A11: Notify [ Title:sendlog Text:%LASTLOG Icon:ipack:crystalhd:easymoblog Number:%counter Permanent:On Priority:3 ]
  A12: HTTP Post [ Server:Port:http://myserver.com/mysite/receive.php
       Path:
       Data / File:log1=%log1 log2=%log2 log3=%log3
                   log4=%log4 log5=%log5 log6=%log6 log7=%log7
       Cookies:
       Timeout:20
       Content Type:application/x-www-form-urlencoded
       Output File:Tasker/log/Blackboxout.log
       Continue Task After Error:On ]
  A13: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
  A14: Read File [ File:Tasker/log/Blackboxout.log To Var:%post_ok ]
  A15: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ]
  A16: If [ %post_ok ~ 1 ]
    A17: Notify Cancel [ Title:send log Warn Not Exist:Off ]
    A18: Return [ Value:1 Stop:On ]
  A19: End If
  A20: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A21: End For
A22: Return [ Value:2 Stop:On ]
The global variable %NEWLINE has a newline, a return character stored in it. Please create this one, we need it to separate each new line in the file.

If you are looking for an easier solution to send information directly from one android device to another android device, you should have a look at AutoRemote. Unfortunately this feature isn't free.

Friday, May 17, 2013

[Tasker] How to read out WhatsApp messages with Tasker and react on their content in real time

Update2:

They changed something since Android 5.
First, one needs a new sqlite3 binary. I found a working one at xda-developers.
Secondary, one has to change the database access terminal command in Tasker from

sqlite3 /data/data/com.whatsapp/databases/msgstore.db "SELECT timestamp,data,key_remote_jid FROM messages WHERE key_from_me='0' ORDER BY timestamp DESC LIMIT 1;"

to

cd /data/data/com.whatsapp/databases/;
sqlite3 msgstore.db "SELECT timestamp,data,key_remote_jid FROM messages WHERE key_from_me='0' ORDER BY timestamp DESC LIMIT 1;"

Now it works again. 
I will update the post soon and explain the changes in more detail. 

Update:

If you like this article, you should take a look at this one:
Make Tasker read aloud all incoming notifications and messages


Tasker can read out incoming or stored WhatsApp Messages, I used Tasker to do the following things on WhatsApp:
  • Display the incoming messages in iOS style, no need to pull down the notification menu to read the messages. The whole message is displayed in the menu bar. See screenshot for details
  • Play different notification sounds for different contacts or different message content, this way you can for example get a special notification if your name is mentioned.
  • Mute WhatsApp at specific times or at specific locations, without muting other notifications. 
  • Update: Read aloud WhatsApp messages
 What we need:
  • Tasker
  • WhatsApp
  • root. I want you to root your phone now! You need root for SQLite, we need it to read out the database of WhatsApp.
  • SQLite for Android
  • Kyo-Tux Aeon HD icon pack, provides useful icons for Tasker, its free and lightweight, so grab it

Here is the complete profile:
Profile: WhatsApp Statusbar
  Priority: 9 CoolDown: 0
  Event: Notification [ Owner Application:WhatsApp Title:* ]

Enter: WhatsApp Notification
  Run Both Together
  A1: Run Shell [ Command:sqlite3 /data/data/com.whatsapp/databases/msgstore.db "SELECT timestamp,data,key_remote_jid FROM messages WHERE key_from_me='0' ORDER BY timestamp DESC LIMIT 1;" Timeout (Seconds):15 Use Root:On Store Result In:%sql_result Continue Task After Error:On ]
  A2: If [ %sql_result !~ %SQL_RESULT_OLD ]
    A3: Variable Set [ Name:%SQL_RESULT_OLD To:%sql_result Do Maths:Off Append:Off ]
    A4: Variable Split [ Name:%sql_result Splitter:| Delete Base:On ]
    A5: Variable Set [ Name:%sql_result1 To:%sql_result1/1000 Do Maths:On Append:Off ]
    A6: Variable Convert [ Name:%sql_result1 Function:Seconds to Date Time Store Result In: ]
    A7: Variable Split [ Name:%sql_result1 Splitter: Delete Base:Off ]
    A8: Variable Search Replace [ Variable:%sql_result12 Search:\. Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With:: ]
    A9: Perform Task [ Name:Number->Name WhatsApp Stop:Off Priority:6 Parameter 1 (%par1):%sql_result3 Parameter 2 (%par2): Return Value Variable:%sql_result3 ]
    A10: Wait Until [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] If [ %sql_result3 !~R @s.whatsapp.net ]
    A11: Array Push [ Name:%WHATSAPP_NOTIFY Position:1 Value:%sql_result3: %sql_result2 Fill Spaces:Off ]
    A12: Notify Cancel [ Title:%WHATSAPP_NOTIFY4 Warn Not Exist:Off ]
    A13: Variable Clear [ Name:%WHATSAPP_NOTIFY4 Pattern Matching:Off ]
    A14: Notify [ Title:%sql_result3: %sql_result2 Text:%sql_result2 Icon:ipack:kyotuxaeonhd:buddy_green Number:0 Permanent:Off Priority:3 ]
    A15: Perform Task [ Name:Play Sound Stop:Off Priority:6 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: ]
  A16: End If
Click here to see the WhatsAppStatusbar.prf.xml you can import directly into Tasker.
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
 <Profile sr="prof59" ve="2">
  <cdate>1353556343390</cdate>
  <edate>1368831772583</edate>
  <flags>1</flags>
  <id>59</id>
  <mid0>175</mid0>
  <nme>WhatsApp Statusbar</nme>
  <pri>9</pri>
  <Event sr="con0" ve="2">
   <code>461</code>
   <pri>1</pri>
   <App sr="arg0">
    <appClass>com.whatsapp.Main</appClass>
    <appPkg>com.whatsapp</appPkg>
    <label>WhatsApp</label>
   </App>
   <Str sr="arg1" ve="3"/>
  </Event>
 </Profile>
 <Task sr="task175">
  <cdate>1353556370005</cdate>
  <edate>1368831772583</edate>
  <id>175</id>
  <nme>WhatsApp Message</nme>
  <pri>10</pri>
  <rty>2</rty>
  <Action sr="act0" ve="3">
   <code>123</code>
   <se>false</se>
   <Str sr="arg0" ve="3">sqlite3 /data/data/com.whatsapp/databases/msgstore.db "SELECT timestamp,data,key_remote_jid FROM messages WHERE key_from_me='0' ORDER BY timestamp DESC LIMIT 1;"</Str>
   <Int sr="arg1" val="15"/>
   <Int sr="arg2" val="1"/>
   <Str sr="arg3" ve="3">%sql_result</Str>
  </Action>
  <Action sr="act1" ve="3">
   <code>37</code>
   <lhs>%sql_result</lhs>
   <op>2</op>
   <rhs>%SQL_RESULT_OLD</rhs>
  </Action>
  <Action sr="act10" ve="3">
   <code>355</code>
   <Str sr="arg0" ve="3">%WHATSAPP_NOTIFY</Str>
   <Int sr="arg1" val="1"/>
   <Str sr="arg2" ve="3">%sql_result3: %sql_result2</Str>
   <Int sr="arg3" val="0"/>
  </Action>
  <Action sr="act11" ve="3">
   <code>779</code>
   <Str sr="arg0" ve="3">%WHATSAPP_NOTIFY4</Str>
   <Int sr="arg1" val="0"/>
  </Action>
  <Action sr="act12" ve="3">
   <code>549</code>
   <Str sr="arg0" ve="3">%WHATSAPP_NOTIFY4</Str>
   <Int sr="arg1" val="0"/>
  </Action>
  <Action sr="act13" ve="3">
   <code>523</code>
   <Str sr="arg0" ve="3">%sql_result3: %sql_result2</Str>
   <Str sr="arg1" ve="3">%sql_result2</Str>
   <Img sr="arg2" ve="2">
    <nme>buddy_green</nme>
    <pkg>net.dinglisch.android.ipack.kyotuxaeonhd</pkg>
   </Img>
   <Int sr="arg3" val="0"/>
   <Int sr="arg4" val="0"/>
   <Int sr="arg5" val="3"/>
  </Action>
  <Action sr="act14" ve="3">
   <code>130</code>
   <Str sr="arg0" ve="3">Play Sound</Str>
   <Int sr="arg1" val="0"/>
   <Int sr="arg2" val="6"/>
   <Str sr="arg3" ve="3"/>
   <Str sr="arg4" ve="3"/>
   <Str sr="arg5" ve="3"/>
  </Action>
  <Action sr="act15" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act2" ve="3">
   <code>547</code>
   <Str sr="arg0" ve="3">%SQL_RESULT_OLD</Str>
   <Str sr="arg1" ve="3">%sql_result</Str>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
  </Action>
  <Action sr="act3" ve="3">
   <code>590</code>
   <Str sr="arg0" ve="3">%sql_result</Str>
   <Str sr="arg1" ve="3">|</Str>
   <Int sr="arg2" val="1"/>
  </Action>
  <Action sr="act4" ve="3">
   <code>547</code>
   <Str sr="arg0" ve="3">%sql_result1</Str>
   <Str sr="arg1" ve="3">%sql_result1/1000</Str>
   <Int sr="arg2" val="1"/>
   <Int sr="arg3" val="0"/>
  </Action>
  <Action sr="act5" ve="3">
   <code>596</code>
   <Str sr="arg0" ve="3">%sql_result1</Str>
   <Int sr="arg1" val="4"/>
   <Str sr="arg2" ve="3"/>
  </Action>
  <Action sr="act6" ve="3">
   <code>590</code>
   <Str sr="arg0" ve="3">%sql_result1</Str>
   <Str sr="arg1" ve="3"/>
   <Int sr="arg2" val="0"/>
  </Action>
  <Action sr="act7" ve="3">
   <code>598</code>
   <Str sr="arg0" ve="3">%sql_result12</Str>
   <Str sr="arg1" ve="3">\.</Str>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
   <Int sr="arg4" val="0"/>
   <Str sr="arg5" ve="3"/>
   <Int sr="arg6" val="1"/>
   <Str sr="arg7" ve="3">:</Str>
  </Action>
  <Action sr="act8" ve="3">
   <code>130</code>
   <Str sr="arg0" ve="3">Number-&gt;Name
WhatsApp</Str>
   <Int sr="arg1" val="0"/>
   <Int sr="arg2" val="6"/>
   <Str sr="arg3" ve="3">%sql_result3</Str>
   <Str sr="arg4" ve="3"/>
   <Str sr="arg5" ve="3">%sql_result3</Str>
  </Action>
  <Action sr="act9" ve="3">
   <code>35</code>
   <lhs>%sql_result3</lhs>
   <op>12</op>
   <rhs>@s.whatsapp.net</rhs>
   <Int sr="arg0" val="0"/>
   <Int sr="arg1" val="5"/>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
   <Int sr="arg4" val="0"/>
  </Action>
  <Img sr="icn" ve="2">
   <cls>com.whatsapp.Main</cls>
   <pkg>com.whatsapp</pkg>
  </Img>
 </Task>
</TaskerData>


The most important line is A1. Here we use the installed sqlite to save the time, the sender and the content of the last message stored in the WhatsApp database into a Tasker variable. The values are separated by a "|", the time is in ms and the sender is stored as a phone numer. So there are some conversions needed afterwards.
You may have noticed that there is a call to another task at line A9. WhatsApp saves only the number of the contact who send you the message in its database, so we need to convert the number to a real contact name as saved in your phone book. The task "Number->Name WhatsApp" does it. It searches the address book for contacts associated with a WhatsApp account and returns their name. So after line A10 you should know who texted you by name, you can put in if clauses to react different to different names. Here the description of the "Number->Name WhatsApp" task:
Number->Name WhatsApp
  A1: Run Shell [ Command:sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db "SELECT display_name FROM raw_contacts WHERE sync1 like '%par1';" Timeout (Seconds):5 Use Root:On Store Result In:%sql_result_name Continue Task After Error:On ]
  A2: If [ %sql_result_name !~R sql_result_name ]
    A3: Return [ Value:%sql_result_name Stop:On ]
  A4: Else
    A5: Return [ Value:%par1 Stop:On ]
  A6: End If
Click here to see the NumberNameWhatsApp.tsk.xml you can import directly into Tasker.
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
 <Task sr="task60">
  <cdate>1355153077534</cdate>
  <edate>1357807836858</edate>
  <id>60</id>
  <nme>Number-&gt;Name WhatsApp</nme>
  <pri>10</pri>
  <Action sr="act0" ve="3">
   <code>123</code>
   <se>false</se>
   <Str sr="arg0" ve="3">sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db "SELECT display_name FROM raw_contacts WHERE sync1 like '%par1';"</Str>
   <Int sr="arg1" val="5"/>
   <Int sr="arg2" val="1"/>
   <Str sr="arg3" ve="3">%sql_result_name</Str>
  </Action>
  <Action sr="act1" ve="3">
   <code>37</code>
   <lhs>%sql_result_name</lhs>
   <op>12</op>
   <rhs>sql_result_name</rhs>
  </Action>
  <Action sr="act2" ve="3">
   <code>126</code>
   <Str sr="arg0" ve="3">%sql_result_name</Str>
   <Int sr="arg1" val="1"/>
  </Action>
  <Action sr="act3" ve="3">
   <code>43</code>
  </Action>
  <Action sr="act4" ve="3">
   <code>126</code>
   <Str sr="arg0" ve="3">%par1</Str>
   <Int sr="arg1" val="1"/>
  </Action>
  <Action sr="act5" ve="3">
   <code>38</code>
  </Action>
 </Task>
</TaskerData>

At line A15 of the task "WhatsApp Notification" task I call a Tasker task called "Play Sound". That's because I disabled notification sounds in WhatsApp to handle them myself (They are time and WhatsApp message content depandant). Here an example of how a simple "Play Sound" task could look like:
Play Sound
  Run Both Together
  A1: If [ %par1 ~R .*[Rr]+[Uu]+[Aa]+[Rr]+.* ]
    A2: Variable Set [ Name:%tmp To:%VOLS Do Maths:Off Append:Off ]
    A3: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]
    A4: System Volume [ Level:7 Display:Off Sound:Off ]
    A5: If [ %SILENT ~ off ]
      A6: Play Ringtone [ Type:Notification Sound:Dinosaur Roar Stream:1 ]
    A7: Else If [ %HEADSET ~ 1 ]
      A8: Play Ringtone [ Type:Notification Sound:Dinosaur Roar Stream:1 ]
    A9: End If
    A10: Vibrate [ Time:1000 ]
    A11: Vibrate [ Time:1000 ]
    A12: Vibrate [ Time:1000 ]
    A13: Vibrate [ Time:1000 ]
    A14: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
    A15: System Volume [ Level:%tmp Display:Off Sound:Off ]
  A16: Else If [ %par1 ~R [Mm][Ii][Aa][Uu]+\b ]
    A17: If [ %SILENT ~ off ]
      A18: Play Ringtone [ Type:Notification Sound:Miau Stream:1 ]
    A19: Else If [ %HEADSET ~ 1 ]
      A20: Play Ringtone [ Type:Notification Sound:Miau Stream:1 ]
    A21: End If
  A22: Else
    A23: If [ %par2 !~ 1 ]
      A24: If [ %HEADSET !~ 1 ]
        A25: If [ %SILENT ~ off ]
          A26: Vibrate [ Time:100 ]
          A27: Play Ringtone [ Type:Notification Sound:Good news Stream:5 ]
        A28: End If
      A29: End If
    A30: End If
  A31: End If
Save me as "PlaySound.tsk.xml" and import me in Tasker.
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
 <Task sr="task176">
  <cdate>1353531946878</cdate>
  <edate>1368836670797</edate>
  <id>176</id>
  <nme>Play Sound</nme>
  <pri>10</pri>
  <rty>2</rty>
  <Action sr="act0" ve="3">
   <code>37</code>
   <lhs>%par1</lhs>
   <op>11</op>
   <rhs>.*[Rr]+[Uu]+[Aa]+[Rr]+.*</rhs>
  </Action>
  <Action sr="act1" ve="3">
   <code>547</code>
   <Str sr="arg0" ve="3">%tmp</Str>
   <Str sr="arg1" ve="3">%VOLS</Str>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
  </Action>
  <Action sr="act10" ve="3">
   <code>61</code>
   <Int sr="arg0" val="1000"/>
  </Action>
  <Action sr="act11" ve="3">
   <code>61</code>
   <Int sr="arg0" val="1000"/>
  </Action>
  <Action sr="act12" ve="3">
   <code>61</code>
   <Int sr="arg0" val="1000"/>
  </Action>
  <Action sr="act13" ve="3">
   <code>30</code>
   <Int sr="arg0" val="0"/>
   <Int sr="arg1" val="5"/>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
   <Int sr="arg4" val="0"/>
  </Action>
  <Action sr="act14" ve="3">
   <code>308</code>
   <Int sr="arg0">
    <var>%tmp</var>
   </Int>
   <Int sr="arg1" val="0"/>
   <Int sr="arg2" val="0"/>
  </Action>
  <Action sr="act15" ve="3">
   <code>43</code>
   <lhs>%par1</lhs>
   <op>11</op>
   <rhs>[Mm][Ii][Aa][Uu]+\b</rhs>
  </Action>
  <Action sr="act16" ve="3">
   <code>37</code>
   <lhs>%SILENT</lhs>
   <op>1</op>
   <rhs>off</rhs>
  </Action>
  <Action sr="act17" ve="3">
   <code>192</code>
   <Int sr="arg0" val="1"/>
   <Str sr="arg1" ve="3">Join Hangout</Str>
   <Int sr="arg2" val="1"/>
  </Action>
  <Action sr="act18" ve="3">
   <code>43</code>
   <lhs>%HEADSET</lhs>
   <op>1</op>
   <rhs>1</rhs>
  </Action>
  <Action sr="act19" ve="3">
   <code>192</code>
   <Int sr="arg0" val="1"/>
   <Str sr="arg1" ve="3">Join Hangout</Str>
   <Int sr="arg2" val="1"/>
  </Action>
  <Action sr="act2" ve="3">
   <code>30</code>
   <Int sr="arg0" val="50"/>
   <Int sr="arg1" val="0"/>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
   <Int sr="arg4" val="0"/>
  </Action>
  <Action sr="act20" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act21" ve="3">
   <code>43</code>
  </Action>
  <Action sr="act22" ve="3">
   <code>37</code>
   <lhs>%par2</lhs>
   <op>2</op>
   <rhs>1</rhs>
  </Action>
  <Action sr="act23" ve="3">
   <code>37</code>
   <lhs>%HEADSET</lhs>
   <op>2</op>
   <rhs>1</rhs>
  </Action>
  <Action sr="act24" ve="3">
   <code>37</code>
   <lhs>%SILENT</lhs>
   <op>1</op>
   <rhs>off</rhs>
  </Action>
  <Action sr="act25" ve="3">
   <code>61</code>
   <Int sr="arg0" val="100"/>
  </Action>
  <Action sr="act26" ve="3">
   <code>192</code>
   <Int sr="arg0" val="1"/>
   <Str sr="arg1" ve="3">Good news</Str>
   <Int sr="arg2" val="5"/>
  </Action>
  <Action sr="act27" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act28" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act29" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act3" ve="3">
   <code>308</code>
   <Int sr="arg0" val="7"/>
   <Int sr="arg1" val="0"/>
   <Int sr="arg2" val="0"/>
  </Action>
  <Action sr="act30" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act4" ve="3">
   <code>37</code>
   <lhs>%SILENT</lhs>
   <op>1</op>
   <rhs>off</rhs>
  </Action>
  <Action sr="act5" ve="3">
   <code>192</code>
   <Int sr="arg0" val="1"/>
   <Str sr="arg1" ve="3">Flowers</Str>
   <Int sr="arg2" val="1"/>
  </Action>
  <Action sr="act6" ve="3">
   <code>43</code>
   <lhs>%HEADSET</lhs>
   <op>1</op>
   <rhs>1</rhs>
  </Action>
  <Action sr="act7" ve="3">
   <code>192</code>
   <Int sr="arg0" val="1"/>
   <Str sr="arg1" ve="3">Flowers</Str>
   <Int sr="arg2" val="1"/>
  </Action>
  <Action sr="act8" ve="3">
   <code>38</code>
  </Action>
  <Action sr="act9" ve="3">
   <code>61</code>
   <Int sr="arg0" val="1000"/>
  </Action>
  <Img sr="icn" ve="2">
   <nme>nn_play</nme>
   <pkg>net.dinglisch.android.ipack.ilikebuttonshd</pkg>
  </Img>
 </Task>
</TaskerData>

If headphones are connected or phone is on silent mode no sound is played at all. If the message contains something like "Rrruaaarrrr" a dinosaur roar is played at full volume (even with headphones connected) and the phone vibrates for 4 seconds. If a "Miauuu" is in the message a cats miau is played... I'm sure you can do better :)

You can even make Tasker react on a click on one of the notifications, just add the following profile:
Profile: WhatsApp Notification1 Click
 Event: Notification Click [ Owner Application:Tasker Title:%WHATSAPP_NOTIFY1 ]
Enter: Open WhatsApp
 A1: Load App [ App:WhatsApp Data: Exclude From Recent Apps:Off ]
Duplicate this profile two times so you can click on any of our three custom notifications.
Profile: WhatsApp Notification2 Click
 Event: Notification Click [ Owner Application:Tasker Title:%WHATSAPP_NOTIFY2 ]
Enter: Open WhatsApp
 A1: Load App [ App:WhatsApp Data: Exclude From Recent Apps:Off ]
Profile: WhatsApp Notification3 Click
 Event: Notification Click [ Owner Application:Tasker Title:%WHATSAPP_NOTIFY3 ]
Enter: Open WhatsApp
 A1: Load App [ App:WhatsApp Data: Exclude From Recent Apps:Off ]


I added another profile which deletes all our custom made WhatsApp notifications automatically after opening WhatsApp. Looks like this:
Profile: WhatsApp opened
 Application: WhatsApp

Enter: WhatsApp Notification clear
 A1: Notify Cancel [ Title:%WHATSAPP_NOTIFY1 Warn Not Exist:Off ]
 A2: Notify Cancel [ Title:%WHATSAPP_NOTIFY2 Warn Not Exist:Off ]
 A3: Notify Cancel [ Title:%WHATSAPP_NOTIFY3 Warn Not Exist:Off ]
 A4: Variable Clear [ Name:%WHATSAPP_NOTIFY* Pattern Matching:On ]
 A5: Stop [ With Error:Off Task:WhatsApp Notification ]

Have fun and use this knowledge wisely. Please leave your thoughts in the comments, I'm very excited about your implementations. Hope you read this Ruy Aguilar ;)

Thursday, May 16, 2013

[Tasker] Energy saving mode

Battery life isn't great on smartphones these days... So it's no surprise the Nokia 105 was in the news when it was announced earlier this year. It claims to have 30 days of battery life and is sold for only 20$. It would be nice to have a smartphone lasting that long. I will show you an easy way to expand the battery life of an android smartphone with Tasker. Nowadays smartphones are online all the time, radiating information continuously. I noticed that it makes a huge difference in battery life wether I'm connected to a WiFi AP or not. Even data connection (4G/3G/EDGE/GPRS) seems to have a significant impact on the standby time of my phone. Permanently disconnecting from the internet is no solution in the 21. century, you will miss all the notifications, messages and other goodnesses of our information age. A solution I came up with is to connect to the network only once every 14 minutes.

Our task, lets call it "periodic internet", will disconnect the phone from the network for 14 minutes, then connect for 1 minute and get all the notifications before starting over again by disconnecting for 14 minutes... All calls and SMS will be received in real time, while all the notifications will be delayed by up to 14 minutes. The benefit is the significantly improved battery life. Because of this task, my phone uses only 2% of the battery per hour! I configured Tasker to run this task while I'm at the gym, or at night when not connected to a power supply. Sometimes I activate it manually, because I know my phone won't make it trough the day otherwise.

What are we going to do:
  • We will configure a widget on our home screen one can tap to activate and deactivate the "periodic internet" task
  • We will show a permanent notification while running this task, after clicking the notification the task we be canceled and the permanent internet connection will be restored
  • The notification will show the time when the phone was connected to the internet the last time and how often the internet has been turned off and on already
What do we need:
  • Android phone
  • Tasker - create your own small programs
  • Zoom - an app able to create interactive widgets, install it after Tasker.
  • Crystal Project HD icon pack - we will use one of the icons
  • 10-20 minutes lifetime

The "periodic internet On" task

The task checks which internet connection radios are on, saves them into global variables for later use and turns WiFi and data off for 14 minutes, after that it turns them on for 1 minute before repeating itself by turning them off again. At the beginning of the task a zoom widget is modified, I will explain this later. Moreover a notification informing that the task is running is shown. Skip the line A2, add it later after you have created a "Periodic internet widget" as described later in this post.
Periodic internet On
  Abort Existing Task
  A1: Variable Set [ Name:%PERIRADIO To:1 Do Maths:Off Append:Off ]
  A2: Zoom Element Visibility [ Element:Periodic Radio.w / StateON Set:On ]
  A3: Variable Set [ Name:%num To:0 Do Maths:Off Append:Off ]
  <Loop>
  A4: Anchor
    A5: Variable Add [ Name:%num Value:1 Wrap Around:0 ]
    A6: Notify [ Title:Periodic internet Text: Icon:ipack:crystalhd:quick_restart Number:%num Permanent:On Priority:3 ]
    A7: Variable Set [ Name:%MOBILDATA To:1 Do Maths:Off Append:Off ] If [ %AIR ~ off ]
    A8: Variable Set [ Name:%MOBILDATA To:0 Do Maths:Off Append:Off ] If [ %AIR !~ off ]
    A9: Variable Set [ Name:%WLANTMP To:1 Do Maths:Off Append:Off ] If [ %WIFII ~R CONNECTION ]
    A10: Variable Set [ Name:%WLANTMP To:0 Do Maths:Off Append:Off ] If [ %WIFII !~R CONNECTION ]
    A11: Variable Set [ Name:%noradio To:%MOBILDATA+%WLANTMP Do Maths:On Append:Off ]
    A12: If [ %noradio ~ 0 ]
      A13: Stop [ With Error:Off Task: ]
    A14: End If
    A15: Mobile Data [ Set:Off ]
    A16: WiFi [ Set:Off ]
    A17: Wait [ MS:0 Seconds:0 Minutes:14 Hours:0 Days:0 ]
    A18: WiFi [ Set:On ] If [ %WLANTMP ~ 1 ]
    A19: Mobile Data [ Set:On ] If [ %MOBILDATA ~ 1 ]
    A20: Wait [ MS:0 Seconds:0 Minutes:1 Hours:0 Days:0 ]
  A21: Goto [ Type:Action Label Number:1 Label:Loop ]
Click here to see the periodicinterneton.tsk.xml you can import directly into Tasker.
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
    <Task sr="task175">
        <cdate>1366139544095</cdate>
        <edate>1368747046322</edate>
        <id>175</id>
        <nme>Periodic internet On</nme>
        <pri>10</pri>
        <rty>1</rty>
        <Action sr="act0" ve="3">
            <code>547</code>
            <Str sr="arg0" ve="3">%PERIRADIO</Str>
            <Str sr="arg1" ve="3">1</Str>
            <Int sr="arg2" val="0"/>
            <Int sr="arg3" val="0"/>
        </Action>
        <Action sr="act1" ve="3">
            <code>721</code>
            <Str sr="arg0" ve="3">Periodic internet.w / StateON</Str>
            <Int sr="arg1" val="1"/>
        </Action>
        <Action sr="act10" ve="3">
            <code>547</code>
            <Str sr="arg0" ve="3">%noradio</Str>
            <Str sr="arg1" ve="3">%MOBILDATA+%WLANTMP</Str>
            <Int sr="arg2" val="1"/>
            <Int sr="arg3" val="0"/>
        </Action>
        <Action sr="act11" ve="3">
            <code>37</code>
            <lhs>%noradio</lhs>
            <op>1</op>
            <rhs>0</rhs>
        </Action>
        <Action sr="act12" ve="3">
            <code>137</code>
            <Int sr="arg0" val="0"/>
            <Str sr="arg1" ve="3"/>
        </Action>
        <Action sr="act13" ve="3">
            <code>38</code>
        </Action>
        <Action sr="act14" ve="3">
            <code>433</code>
            <Int sr="arg0" val="0"/>
        </Action>
        <Action sr="act15" ve="3">
            <code>425</code>
            <Int sr="arg0" val="0"/>
        </Action>
        <Action sr="act16" ve="3">
            <code>30</code>
            <Int sr="arg0" val="0"/>
            <Int sr="arg1" val="0"/>
            <Int sr="arg2" val="14"/>
            <Int sr="arg3" val="0"/>
            <Int sr="arg4" val="0"/>
        </Action>
        <Action sr="act17" ve="3">
            <code>425</code>
            <lhs>%WLANTMP</lhs>
            <op>1</op>
            <rhs>1</rhs>
            <Int sr="arg0" val="1"/>
        </Action>
        <Action sr="act18" ve="3">
            <code>433</code>
            <lhs>%MOBILDATA</lhs>
            <op>1</op>
            <rhs>1</rhs>
            <Int sr="arg0" val="1"/>
        </Action>
        <Action sr="act19" ve="3">
            <code>30</code>
            <Int sr="arg0" val="0"/>
            <Int sr="arg1" val="0"/>
            <Int sr="arg2" val="1"/>
            <Int sr="arg3" val="0"/>
            <Int sr="arg4" val="0"/>
        </Action>
        <Action sr="act2" ve="3">
            <code>547</code>
            <Str sr="arg0" ve="3">%num</Str>
            <Str sr="arg1" ve="3">0</Str>
            <Int sr="arg2" val="0"/>
            <Int sr="arg3" val="0"/>
        </Action>
        <Action sr="act20" ve="3">
            <code>135</code>
            <Int sr="arg0" val="1"/>
            <Int sr="arg1" val="1"/>
            <Str sr="arg2" ve="3">Loop</Str>
        </Action>
        <Action sr="act3" ve="3">
            <code>300</code>
            <label>Loop</label>
        </Action>
        <Action sr="act4" ve="3">
            <code>888</code>
            <Str sr="arg0" ve="3">%num</Str>
            <Int sr="arg1" val="1"/>
            <Int sr="arg2" val="0"/>
        </Action>
        <Action sr="act5" ve="3">
            <code>523</code>
            <Str sr="arg0" ve="3">Periodic internet</Str>
            <Str sr="arg1" ve="3"/>
            <Img sr="arg2" ve="2">
                <nme>quick_restart</nme>
                <pkg>net.dinglisch.android.ipack.crystalhd</pkg>
            </Img>
            <Int sr="arg3">
                <var>%num</var>
            </Int>
            <Int sr="arg4" val="1"/>
            <Int sr="arg5" val="3"/>
        </Action>
        <Action sr="act6" ve="3">
            <code>547</code>
            <lhs>%AIR</lhs>
            <op>1</op>
            <rhs>off</rhs>
            <Str sr="arg0" ve="3">%MOBILDATA</Str>
            <Str sr="arg1" ve="3">1</Str>
            <Int sr="arg2" val="0"/>
            <Int sr="arg3" val="0"/>
        </Action>
        <Action sr="act7" ve="3">
            <code>547</code>
            <lhs>%AIR</lhs>
            <op>2</op>
            <rhs>off</rhs>
            <Str sr="arg0" ve="3">%MOBILDATA</Str>
            <Str sr="arg1" ve="3">0</Str>
            <Int sr="arg2" val="0"/>
            <Int sr="arg3" val="0"/>
        </Action>
        <Action sr="act8" ve="3">
            <code>547</code>
            <lhs>%WIFII</lhs>
            <op>11</op>
            <rhs>CONNECTION</rhs>
            <Str sr="arg0" ve="3">%WLANTMP</Str>
            <Str sr="arg1" ve="3">1</Str>
            <Int sr="arg2" val="0"/>
            <Int sr="arg3" val="0"/>
        </Action>
        <Action sr="act9" ve="3">
            <code>547</code>
            <lhs>%WIFII</lhs>
            <op>12</op>
            <rhs>CONNECTION</rhs>
            <Str sr="arg0" ve="3">%WLANTMP</Str>
            <Str sr="arg1" ve="3">0</Str>
            <Int sr="arg2" val="0"/>
            <Int sr="arg3" val="0"/>
        </Action>
    </Task>
</TaskerData>


The "periodic internet Off" task

This task must be executed to turn the periodic internet mode off. Skip the line A6, code it after adding the "Periodic internet widget" on your home screen:
Periodic internet Off
  A1: Stop [ With Error:Off Task:Periodic internet On ]
  A2: Mobile Data [ Set:On ] If [ %MOBILDATA ~ 1 ]
  A3: WiFi [ Set:On ] If [ %WLANTMP ~ 1 ]
  A4: Notify Cancel [ Title:Periodic internet Warn Not Exist:Off ]
  A5: Variable Set [ Name:%PERIRADIO To:0 Do Maths:Off Append:Off ]
  A6: Zoom Element Visibility [ Element:Periodic internet.w / StateON Set:Off ]
Click here to see the periodicinternetoff.tsk.xml you can import directly into Tasker.
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
 <Task sr="task176">
  <cdate>1366195609780</cdate>
  <edate>1368748409608</edate>
  <id>176</id>
  <nme>Periodic internet Off</nme>
  <pri>10</pri>
  <Action sr="act0" ve="3">
   <code>137</code>
   <Int sr="arg0" val="0"/>
   <Str sr="arg1" ve="3">Periodic internet On</Str>
  </Action>
  <Action sr="act1" ve="3">
   <code>433</code>
   <lhs>%MOBILDATA</lhs>
   <op>1</op>
   <rhs>1</rhs>
   <Int sr="arg0" val="1"/>
  </Action>
  <Action sr="act2" ve="3">
   <code>425</code>
   <lhs>%WLANTMP</lhs>
   <op>1</op>
   <rhs>1</rhs>
   <Int sr="arg0" val="1"/>
  </Action>
  <Action sr="act3" ve="3">
   <code>779</code>
   <Str sr="arg0" ve="3">Periodic internet</Str>
   <Int sr="arg1" val="0"/>
  </Action>
  <Action sr="act4" ve="3">
   <code>547</code>
   <Str sr="arg0" ve="3">%PERIRADIO</Str>
   <Str sr="arg1" ve="3">0</Str>
   <Int sr="arg2" val="0"/>
   <Int sr="arg3" val="0"/>
  </Action>
  <Action sr="act5" ve="3">
   <code>721</code>
   <Str sr="arg0" ve="3">Periodic internet.w / StateON</Str>
   <Int sr="arg1" val="0"/>
  </Action>
 </Task>
</TaskerData>


Turn off "Periodic internet" by clicking on the notification

Create a new Tasker profile, name it "Periodic internet Off". Select event, UI, notification click. Owner Application is "Tasker" and the title should be "Periodic internet". As the performed action select the just created "Periodic internet Off" task.

The "periodic internet On/Off" widget

Now we need the above mentioned program "Zoom", this will allow us to place a interactive widget on our home screen so we can turn our new battery saving mode on and off by tapping on it. Import the widget template by copypasting the following code into a "Periodic_internet.ztl.xml" file or follow the instructions bellow to create a widget yourself.
<class name="Template" index="">
 <backColour>#00000000</backColour>
 <borderColour>#FFFFFFFF</borderColour>
 <borderWidth>0</borderWidth>
 <cellData>160,200,20,18;212,148,0,0</cellData>
 <cellsHigh>1</cellsHigh>
 <cellsWide>1</cellsWide>
 <marginWidth>4</marginWidth>
 <name>Periodic internet</name>
 <class name="Element" index="elements0">
  <elementType>Image</elementType>
  <heightLand>191</heightLand>
  <heightPort>191</heightPort>
  <name>StateOFF</name>
  <visible>true</visible>
  <widthLand>151</widthLand>
  <widthPort>151</widthPort>
  <xLand>0</xLand>
  <xPort>0</xPort>
  <yLand>0</yLand>
  <yPort>0</yPort>
  <class name="ImageElement" index="state0">
   <alpha>75</alpha>
   <stateName></stateName>
   <uri>ipack://net.dinglisch.android.ipack.crystalhd/quick_restart</uri>
   <class name="TaskAction" index="onClick0">
    <name>Periodic internet On</name>
   </class>
  </class>
 </class>
 <class name="Element" index="elements1">
  <elementType>Image</elementType>
  <heightLand>191</heightLand>
  <heightPort>191</heightPort>
  <name>StateON</name>
  <visible>false</visible>
  <widthLand>151</widthLand>
  <widthPort>151</widthPort>
  <xLand>0</xLand>
  <xPort>0</xPort>
  <yLand>0</yLand>
  <yPort>0</yPort>
  <class name="ImageElement" index="state0">
   <alpha>255</alpha>
   <stateName></stateName>
   <uri>ipack://net.dinglisch.android.ipack.crystalhd/quick_restart</uri>
   <class name="TaskAction" index="onClick0">
    <name>Periodic internet Off</name>
   </class>
  </class>
 </class>
</class>
Start Zoom and tap on the green plus in the lower right corner of the templates register. Configure it like this and tap on the green check button:
  • name: Periodic internet
  • cell width x height: 1 x 1
  • background colour: #00000000
  • margin width: 0
  • border width: 0
  • border colour: #ffffffff
  • visible: true
Now we will need an image element, therefore long press on the blank black area and select image. Fill in the fields like this:
  • name: StateOFF
  • source: select a nice looking icon. I like the "quick_restart" icon from the Crystal Project HD pack, you can see it on the screenshot at the top of this post.
  • alpha: 75 (that's important)
  • Click action: select the Tasker task "Periodic internet On"
Accept with the green check button. Long press on the newly created image and select Fit to widget. Now we will create a second image on top of this one. Press the menu button of your phone and select Add element. Select image again but configure it this time like shown here:
  • name: StateON
  • source: select the same nice looking icon
  • alpha: 255
  • Click action: select the Tasker task "Periodic internet Off"
After accepting, expand the image again over the whole widget area. You should end up with one image on top of the other, covering it completely. That's perfect, accept again with the green check button. You should see the template window again with a Periodic internet template. Exit Zoom by clicking on the button in left bottom corner (green check).

Now we need to place the widget on our home screen, just add a Zoom 1x1 widget and select the "Periodic internet" template when asked, confirm every dialog. Make sure the Zoom Element Visibility lines in our Tasker tasks (lines A2 and A6 respectively) point to the created "Periodic internet" Zoom widget on your home screen. Check it!

That's it! Now it's your turn - automate the activation and deactivation of the "periodic internet" task, I'm excited to hear about your experience with it! The only limit is yourself!

Sunday, May 12, 2013

[Tasker] Check a website for specific information

One useful thing Tasker can do is fetch a website and scan it for specific information you are interested in. If the information you are looking for is present, Tasker can notify you and your friends. After clicking on the notification you will be redirected to the information of interest.

I want to show you how to check a bargain website like mydealz.de for posts containing the keywords "Kino" (Cinema in German) and "Knaller" (price hit) and notify you and your friends about them. Deals posted with the keyword cinema often contain information on how to get a discount for a certain movie or how to watch it for free. Often the amount of discounted tickets is limited so one has to react quickly to get one. It can be a huge advantage to know about this deals as soon as possible. So lets make Tasker look out for these discounts and inform us about the interesting ones!

In principle the task is build like this: We have a global variable which contains all the interesting keywords separated by a semicolon ";". In out example the Variable is called "%WANTED" and has the value "Kino;Knaller". Of cource it can contain more keywords, just separate them correctly. The task downloads the html file of the website by using the HTTP GET command and reads it in into a new local variable %mydealz. Afterwards the variable %mydealz is searched with regular expressions for headings. All the headings are saved in an array. If a keyword occurs in a heading a notification is shown and a SMS is sent to provided numbers.

Here the code description:
MyDealz check
A1: Variable Query [ Title:What are the keywords to look for? (Semicolon separated) Variable:%WANTED Input Type:Normal Text Default:SSD;Plasma;House Background Image: Layout:Variable Query Timeout (Seconds):300 Show Over Keyguard:Off ] If [ %WANTED ! Set ]
A2: Variable Set [ Name:%wanted To:%WANTED Do Maths:Off Append:Off ]
A3: Variable Split [ Name:%wanted Splitter:; Delete Base:Off ]
A4: HTTP Get [ Server:Port:www.mydealz.de Path: Attributes: Cookies: Timeout:30 Mime Type:application/octet-stream Output File:Tasker/log/MyDealz.html ]
A5: Read File [ File:Tasker/log/MyDealz.html To Var:%mydealz ]
A6: Variable Search Replace [ Variable:%mydealz Search:<h2>
<a href="http://www.blogger.com/.*">.*</a></h2>
A7: For [ Variable:%element Items:%wanted() ]
A8: For [ Variable:%num Items:%array() ]
A9: If [ %num ~R %element ]
A10: Variable Convert [ Name:%num Function:HTML to Text Store Result In:%mydealztext ]
A11: Variable Search Replace [ Variable:%num Search:".*" Ignore Case:Off Multi-Line:On One Match Only:On Store Matches In:%MYDEALZ_NOTIFY_URL Replace Matches:Off Replace With: ]
A12: Test [ Type:Variable Length Data:%MYDEALZ_NOTIFY_URL1 Store Result In:%urllength ]
A13: Variable Subtract [ Name:%urllength Value:2 ]
A14: Variable Section [ Name:%MYDEALZ_NOTIFY_URL1 From:2 Length:%urllength Adapt To Fit:Off Store Result In:%MYDEALZ_NOTIFY_URL1 ] If [ %MYDEALZ_NOTIFY_URL1 ~R " ]
A15: Variable Convert [ Name:%num Function:To MD5 Digest Store Result In:%num ]
A16: For [ Variable:%allreadyfound Items:%MYDEALZFOUND() ]
A17: If [ %allreadyfound ~ %num ]
A18: Goto [ Type:Action Label Number:1 Label:next ]
A19: End If
A20: End For
A21: Array Push [ Name:%MYDEALZFOUND Position:1 Value:%num Fill Spaces:On ]
A22: Variable Clear [ Name:%MYDEALZFOUND4 Pattern Matching:Off ]
A23: Variable Set [ Name:%MYDEALZ_NOTIFY To:%element bei myDealz Do Maths:Off Append:Off ]
A24: Notify Sound [ Title:%element bei myDealz Text:%mydealztext Icon:ipack:ilikebuttonshd:perspectivebutton_reboot Number:0 Sound File:/system/media/audio/alarms/Serene_morning.ogg Priority:3 ]
A25: Perform Task [ Name:SMS send Stop:Off Priority:5 Parameter 1 (%par1):%element on myDealz: %NEWLINE%mydealztext %MYDEALZ_NOTIFY_URL1 Parameter 2 (%par2):0123456789 Return Value Variable: ]
A26: End If
<next>
A27: Anchor
A28: End For
A29: End For 
The task is long, so I provide here a XML file for you to import it directly into Tasker. Just save the file on your phone. Open Tasker, long press on Tasks, choose Import and navigate to the path where you saved the file. Check the imported task.

You can run the task whenever you want, for example every hour or every time you are connected to a WiFi network. Enjoy and don't miss a deal any more :)

Download or copy paste into a file named "MyDealtCheck.tsk.xml" the following code:
Click to expand the code
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
<Task sr="task170">
<cdate>1358719750905</cdate>
<edate>1368371947116</edate>
<id>170</id>
<nme>MyDealz check</nme>
<pri>10</pri>
<Kid sr="Kid">
<launchID>131</launchID>
<pkg>com.gmail.bennylinnik.mydealzcheck</pkg>
<vnme>1.0</vnme>
<vnum>2</vnum>
</Kid>
<Action sr="act0" ve="3">
<code>595</code>
<lhs>%WANTED</lhs>
<op>10</op>
<rhs></rhs>
<Str sr="arg0" ve="3">What shall I look for?</Str>
<Str sr="arg1" ve="3">%WANTED</Str>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3">SSD;Plasma;Kino</Str>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3">Variable Query</Str>
<Int sr="arg6" val="300"/>
<Int sr="arg7" val="0"/>
</Action>
<Action sr="act1" ve="3">
<code>547</code>
<Str sr="arg0" ve="3">%wanted</Str>
<Str sr="arg1" ve="3">%WANTED</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act10" ve="3">
<code>598</code>
<Str sr="arg0" ve="3">%num</Str>
<Str sr="arg1" ve="3">".*"</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="1"/>
<Int sr="arg4" val="1"/>
<Str sr="arg5" ve="3">%MYDEALZ_NOTIFY_URL</Str>
<Int sr="arg6" val="0"/>
<Str sr="arg7" ve="3"/>
</Action>
<Action sr="act11" ve="3">
<code>115</code>
<Int sr="arg0" val="11"/>
<Str sr="arg1" ve="3">%MYDEALZ_NOTIFY_URL1</Str>
<Str sr="arg2" ve="3">%urllength</Str>
</Action>
<Action sr="act12" ve="3">
<code>890</code>
<Str sr="arg0" ve="3">%urllength</Str>
<Int sr="arg1" val="2"/>
</Action>
<Action sr="act13" ve="3">
<code>597</code>
<lhs>%MYDEALZ_NOTIFY_URL1</lhs>
<op>11</op>
<rhs>"</rhs>
<Str sr="arg0" ve="3">%MYDEALZ_NOTIFY_URL1</Str>
<Int sr="arg1" val="2"/>
<Int sr="arg2">
<var>%urllength</var>
</Int>
<Int sr="arg3" val="0"/>
<Str sr="arg4" ve="3">%MYDEALZ_NOTIFY_URL1</Str>
</Action>
<Action sr="act14" ve="3">
<code>596</code>
<Str sr="arg0" ve="3">%num</Str>
<Int sr="arg1" val="26"/>
<Str sr="arg2" ve="3">%num</Str>
</Action>
<Action sr="act15" ve="3">
<code>39</code>
<Str sr="arg0" ve="3">%allreadyfound</Str>
<Str sr="arg1" ve="3">%MYDEALZFOUND()</Str>
</Action>
<Action sr="act16" ve="3">
<code>37</code>
<lhs>%allreadyfound</lhs>
<op>1</op>
<rhs>%num</rhs>
</Action>
<Action sr="act17" ve="3">
<code>135</code>
<Int sr="arg0" val="1"/>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">next</Str>
</Action>
<Action sr="act18" ve="3">
<code>38</code>
</Action>
<Action sr="act19" ve="3">
<code>40</code>
</Action>
<Action sr="act2" ve="3">
<code>590</code>
<Str sr="arg0" ve="3">%wanted</Str>
<Str sr="arg1" ve="3">;</Str>
<Int sr="arg2" val="0"/>
</Action>
<Action sr="act20" ve="3">
<code>355</code>
<Str sr="arg0" ve="3">%MYDEALZFOUND</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">%num</Str>
<Int sr="arg3" val="1"/>
</Action>
<Action sr="act21" ve="3">
<code>549</code>
<Str sr="arg0" ve="3">%MYDEALZFOUND4</Str>
<Int sr="arg1" val="0"/>
</Action>
<Action sr="act22" ve="3">
<code>547</code>
<Str sr="arg0" ve="3">%MYDEALZ_NOTIFY</Str>
<Str sr="arg1" ve="3">%element bei myDealz</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act23" ve="3">
<code>538</code>
<Str sr="arg0" ve="3">%element bei myDealz</Str>
<Str sr="arg1" ve="3">%mydealztext</Str>
<Img sr="arg2" ve="2">
<icn>2130837538</icn>
</Img>
<Int sr="arg3" val="0"/>
<Str sr="arg4" ve="3">/system/media/audio/alarms/Serene_morning.ogg</Str>
<Int sr="arg5" val="3"/>
</Action>
<Action sr="act24" ve="3">
<code>41</code>
<Str sr="arg0" ve="3">0123456789</Str>
<Str sr="arg1" ve="3">%element on myDealz:
%mydealztext %MYDEALZ_NOTIFY_URL1</Str>
<Int sr="arg2" val="0"/>
</Action>
<Action sr="act25" ve="3">
<code>38</code>
</Action>
<Action sr="act26" ve="3">
<code>300</code>
<label>next</label>
</Action>
<Action sr="act27" ve="3">
<code>40</code>
</Action>
<Action sr="act28" ve="3">
<code>40</code>
</Action>
<Action sr="act3" ve="3">
<code>118</code>
<Str sr="arg0" ve="3">www.mydealz.de</Str>
<Str sr="arg1" ve="3"/>
<Str sr="arg2" ve="3"/>
<Str sr="arg3" ve="3"/>
<Int sr="arg4" val="30"/>
<Str sr="arg5" ve="3">application/octet-stream</Str>
<Str sr="arg6" ve="3">Tasker/log/MyDealz.html</Str>
</Action>
<Action sr="act4" ve="3">
<code>417</code>
<Str sr="arg0" ve="3">Tasker/log/MyDealz.html</Str>
<Str sr="arg1" ve="3">%mydealz</Str>
</Action>
<Action sr="act5" ve="3">
<code>598</code>
<Str sr="arg0" ve="3">%mydealz</Str>
<Str sr="arg1" ve="3">&lt;h2&gt;&lt;a href=".*"&gt;.*&lt;/a&gt;&lt;/h2&gt;</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Str sr="arg5" ve="3">%array</Str>
<Int sr="arg6" val="0"/>
<Str sr="arg7" ve="3"/>
</Action>
<Action sr="act6" ve="3">
<code>39</code>
<Str sr="arg0" ve="3">%element</Str>
<Str sr="arg1" ve="3">%wanted()</Str>
</Action>
<Action sr="act7" ve="3">
<code>39</code>
<Str sr="arg0" ve="3">%num</Str>
<Str sr="arg1" ve="3">%array()</Str>
</Action>
<Action sr="act8" ve="3">
<code>37</code>
<lhs>%num</lhs>
<op>11</op>
<rhs>%element</rhs>
</Action>
<Action sr="act9" ve="3">
<code>596</code>
<Str sr="arg0" ve="3">%num</Str>
<Int sr="arg1" val="7"/>
<Str sr="arg2" ve="3">%mydealztext</Str>
</Action>
<Img sr="icn" ve="2">
<icn>2130837538</icn>
</Img>
</Task>
</TaskerData>

[Tasker] Silent your phone after turning it face down for longer than 10 seconds

Update:

Amjan noticed (see comments below) that this task won't work if you have your "Proximity Sensor watching" not enabled in Tasker, therefore do the following before you start:
Press "menu key" while in Tasker -> "Preferences" -> "Monitor" tab -> Search for the label "Proximity Sensor" and select "Yes".

It is a very simple but also very effective Tasker profile is to silent your phone by turning it face down. Instead of turning it instantly into silent mode I want to show you a way to wait for a certain time before muting it. Therefore you reduce the chance to mute it by accident.

The trick is to create two Tasker profiles. The first one sets a global variable to 1 when the phone is turned face down and to 0 if its not in this state any more. The second profile is activated when the global variable is changed to 1. In the task the second profile launches there is a wait (f. e. 10 seconds) followed by a check if the global variable is still set to 1. If the check evaluates to true, then the phone is still in the face down state and it is turned silent.

Here is the complete code:

Profile: Display down

State: Orientation [ Is:Face Down ]
Enter: Display down on
A1: Variable Set [ Name:%SCRDWN To:1 Do Maths:Off Append:Off ]

Exit: Display down off
A1: Variable Set [ Name:%SCRDWN To:0 Do Maths:Off Append:Off ]
A2: If [ %TMPSILENT ~ 1 ]
A3: Silent Mode [ Mode:Off ]
A4: Variable Set [ Name:%TMPSILENT To:0 Do Maths:Off Append:Off ]
A5: End If

Profile: Turn silent

Event: Variable Set [ Variable:%SCRDWN Value:1 ]
Enter: Silent
A1: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A2: If [ %SCRDWN ~ 1 ]
A3: If [ %SILENT ~ off ]
A4: Silent Mode [ Mode:On ]
A5: Variable Set [ Name:%TMPSILENT To:1 Do Maths:Off Append:Off ]
A6: End If
A7: End If