Monday, January 11, 2016

Using Android's BATTERY_CHANGED Intent in Tasker

Monitoring the status of my tablet's battery has always been part of the Digital Dash project (http://mikesgeneralblog.blogspot.com/2015/06/digital-dash-documentation-part-4.html).  And later the function was expanded to bring in the phone's battery information as well.  That part of the project has always worked pretty well and I haven't changed the code in a long time.

Now, however, I've discovered a more efficient way to gather this information and have rewritten that part of the system to take advantage of it.  It allows me to replace what had been two profiles and three tasks, with a single profile with one task attached to it.

The key is another Android Broadcast Intent, similar to the TIME_TICK intent I wrote about in my last post. (http://mikesgeneralblog.blogspot.com/2016/01/using-androids-timetick-intent-in-tasker.html)  The main difference is that where the TIME_TICK intent didn't provide any real information (it was just a synchronizing pulse), the BATTERY_CHANGED intent that we'll be using has a payload that contains a lot of info about the device's battery.

Setup to monitor this intent is nearly identical to the TIME_TICK: Create a new Event profile and choose "Intent Received" from the "System" category.  In the "Action" field enter "android.intent.action.BATTERY_CHANGED" (without quotes).  Then link to the task you want to run from this profile.

Here's what mine looks like:

Profile: V3_ BatteryTracker (472)
        Cooldown: 10
        Event: Intent Received [ Action:android.intent.action.BATTERY_CHANGED Cat:None Cat:None Scheme:* Mime Type:* ]
        State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_BattMon (483)
        A1: Variable Set [ Name:%V3_BatteryDisplay To:%level% Do Maths:Off Append:Off ] If [ %plugged = 0 ]
        A2: Variable Set [ Name:%V3_BatteryDisplay To:<u>%level%</u> Do Maths:Off Append:Off ] If [ %plugged > 0 ]


(Note that, as usual, my profile has a second context, %V3_DrivingMode Set, to keep it from firing unless my Digital Dash system is running.  You don't need that context just to monitor the battery.)

Although this is pretty simple arrangement, there are a couple of points to keep in mind if you're thinking of using this intent.  First of all, notice that I've put a 10-second cooldown on the profile to limit it's maximum firing rate.  That's because this intent will change any time one of several battery conditions changes.  It's not quite like Tasker's built-in "Battery Changed" event that only fires when the battery level changes.  The BATTERY_CHANGED intent (which Tasker is undoubtedly monitoring behind the scenes) puts out new information not only when the battery level changes, but also when the powered status changes, when the battery health changes, and when the the battery temperature changes, along with several other triggers.  

The upshot is that this intent can be updated very frequently and since I don't need or want to have that kind of granularity, I've restricted the profile to firing only once every 10 seconds, at a maximum.

The second things to take note of are the names of the Tasker variables that I'm using: %plugged and %level.  They're obviously local variables, but I didn't make up the names; they are the ones created by Tasker and based on the names provided by the intent itself.  Since there are a lot of other variables associated with this intent (and no real documentation about how they translate to Tasker) it's probably worth a few minutes to lay it out. (You can't just choose these variables from Tasker's drop-down list because they are generated dynamically at runtime.) 

The Android system documentation contains a section on the "Battery Manager" class, which provides the details of this intent.  You can find it here: http://developer.android.com/reference/android/os/BatteryManager.html

There you'll find a list of all the constants used by this class and the information they can contain.  This document is the key to sorting out the Tasker names and knowing what values to look for.

For example, let's take the %plugged variable.  As you can see in the code above, if this variable is not 0, I wrap the battery level in HTML underline tags before displaying it.  This gives me a visual indicator of the power state on the main screen.

If you look at the Battery Manager documentation, you'll see this entry:

public static final String EXTRA_PLUGGED

Added in API level 5
Extra for ACTION_BATTERY_CHANGED: integer indicating whether the device is plugged in to a power source; 0 means it is on battery, other constants are different types of power sources.
Constant Value: "plugged"
The "Constant Value" gives you the name of the Tasker variable (once you add the leading %).  It also give you a hint about what the variable might contain, but there's more information available.
If you scroll up a bit, you'll find these entries, all with the word "plugged" in their names:

public static final int BATTERY_PLUGGED_AC

Added in API level 1
Power source is an AC charger.
Constant Value: 1 (0x00000001)

public static final int BATTERY_PLUGGED_USB

Added in API level 1
Power source is a USB port.
Constant Value: 2 (0x00000002)

public static final int BATTERY_PLUGGED_WIRELESS

Added in API level 17
Power source is wireless.
Constant Value: 4 (0x00000004)
These are the other values that might be present in the %plugged variable.  Knowing that you can test for any state and act accordingly.
Likewise, you can find the names for other variables, such as the ones for health, voltage, status, and so on.  By linking the names back to the constants, you can determine what type of information can be retrieved.
Some variables, like temperature, require a little more digging, however.  If you set up the profile and flash the %temperature value, you might see something like: 223  Don't worry; it doesn't mean your battery is at the boiling point.  The intent reports the battery temperature in tenths of a degree Celsius.  So, a value of 223 means 23.3 degrees Celsius or about 72.14 degrees Fahrenheit.  So, basically room temperature.
The fact that this intent contains the battery temperature is the main reason I put the cooldown period on the profile.  When my Digital Dash project begins ramping up, the battery temperature changes rapidly and I didn't want to have the profile firing every time the temperature changed a tenth of a degree.
This single intent could be a starting point for a pretty comprehensive Tasker-based battery monitoring system.  Take a look at the documentation and see just how much information you can gather with just one profile.





Friday, January 08, 2016

Using Android's TIME_TICK intent in Tasker

I keep coming back to the TimeAndTorque task.  Not because it's all that important, but because I keep finding better ways to execute it.

It started off as a looping task (http://mikesgeneralblog.blogspot.com/2015/06/digital-dash-documentation-part-9.html) and then moved to being triggered by a Schrödinger's Profile, (http://mikesgeneralblog.blogspot.com/2015/12/schrodingers-profile.html) and now it's being driven by Android's TIME_TICK Broadcast Intent.

If you don't know what a Broadcast Intent is, you can think of it as an olde tyme town crier.  The town crier would wander the streets calling out the time and any relevant news.  The Broadcast Intent is basically the same thing; it's just a message that the Android system sends out.  Like the town crier, the system doesn't really know or care it anyone is listening; it's job is just to send out the message.

There are a lot of Broadcast Intents that the system sends out, but the one we are interested in here is called the TIME_TICK.  This message is broadcast at the top of every minute and can be used for triggering events or synchronizing information.

Other apps can broadcast intents as well.  I use one generated by PowerAmp to grab and display music track and artist information (http://mikesgeneralblog.blogspot.com/2015/06/digital-dash-documentation-part-5-music.html).

Fortunately, Tasker makes it easy to listen for these intents and harness them for our own uses. To begin listening for the TIME_TICK, create a new Event profile and choose "Intent Received" from the System category. In the Action field enter "android.intent.action.TIME_TICK" (without the quotes).  You can leave all the other fields blank.  Then, just exit the event configuration and choose the task that you want to run when this intent is received.

Here's what the code looks like for my TimeAndTorque profile and task:

Profile: V3_TimeTick (484)
        Event: Intent Received [ Action:android.intent.action.TIME_TICK Cat:None Cat:None Scheme:* Mime Type:* ]
        State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_TimeAndTorque (336)
        A1: Variable Split [ Name:%TIME Splitter:. Delete Base:Off ]
        A2: Variable Subtract [ Name:%TIME1 Value:12 Wrap Around:0 ] If [ %TIME1 > 12 ]
        A3: Variable Set [ Name:%V3_DispTime To:%TIME1:%TIME2 Do Maths:Off Append:Off ]
        A4: Run Shell [ Command:/data/data/burrows.apps.busybox/app_busybox/tail -1 /storage/emulated/0/torqueLogs/trackLog.csv Timeout (Seconds):0 Use Root:Off Store Output In:%obd_log Store Errors In: Store Result In: Continue Task After Error:On ]
        A5: Variable Split [ Name:%obd_log Splitter:, Delete Base:Off ]
        A6: Test Element [ Scene Name:V3_LH Element:LowFuel Test:Element Visibility Store Result In:%lowdistanceindicator Continue Task After Error:On ]
        A7: If [ %obd_log6 < 60 & %lowdistanceindicator ~ false ]
        A8: Element Visibility [ Scene Name:V3_LH Element Match:LowFuel Set:True Animation Time (MS):0 ]
        A9: Say [ Text:Warning.  Range limit under sixty miles. Engine:Voice:default:default Stream:3 Pitch:5 Speed:4 Respect Audio Focus:On Network:Off Continue Task Immediately:Off Continue Task After Error:On ]
        A10: End If
        A11: If [ %obd_log6 > 60 & %lowdistanceindicator ~ true ]
        A12: Element Visibility [ Scene Name:V3_LH Element Match:LowFuel Set:False Animation Time (MS):0 ]
        A13: End If

Once every minute, the profile will become active and run the TimeAndTorque task, grabbing the time (and synchronizing my on-screen display) and running the low-fuel check (If you want more detail about the task itself, check the documentation in the first link, above.)

This method is simple, clean, and reliable.  I doubt that I'll find a better way to run this task, but who knows; I learn something new about Tasker amost every day.
       

Tuesday, December 22, 2015

Happy Holidays!



Merry FishMoose!

(See, because it's a fish bottle, with a moose candle...  Never mind.  Whatever you celebrate, enjoy the holidays.)

Physical Controls for the Digital Dash, Part 3

After careful thought and consideration (Yes, I'm serious.) I've decided to retire my gamepad side-arm controller in favor of my original scheme of using a Flic to control app access on the Digital Dash.  There are a couple of reasons for that:

1) The Flic is simply more reliable and easier to use.  It doesn't require recharging, connects automatically, and handles it's sleep mode more elegantly.  It also responds more quickly than the gamepad.

2) Many of the functions that the gamepad controls are either no longer necessary or are otherwise handled.  I don't need to download A-GPS data since I'm using the "Device Only" mode for GPS and I've brought the external temperature reading to the main screen, eliminating the need to pull up the Weather Channel app just to get that information.  And, of course, by installing a Flic dedicated to music control, I no longer need those functions on the gamepad.

3)  Finally, on our last few drives I kept closer track of just exactly how I was interacting with the system.  By far, the thing I did most often was to switch over to Google Maps to see the next turn information.  And that didn't happen very often.  I used to switch over more often to see the ETA information, but since bringing that to the main screen as well, it's available without any interaction.  The second most common thing was to check MyRadar to see incoming weather, but again, that was relatively rare.  Other things, such as switching music sources or setting a navigation destination simply didn't happen during the drive; I tended to do that at the beginning of a trip and never needed to change it en-route.

Taking all that into account, I decided to set up a second "App Control" Flic with the following functions.

When the main screen is showing:

  • Short Click - Launch Google Maps
  • Long Click - Launch MyRadar
  • Double Click - Launch GasBuddy

When on any screen EXCEPT the main screen:

  • Short Click - Return to the main screen

When on the Google Maps screen:

  • Long Click - Toggle Voice Navigation Guidance on or off

That seems like a pretty short list, but it represents all the things I'm likely to do while driving.  Of course, if I need to I can map a few other functions to the button, either by manipulating profiles (adding a triple click, for example) or by taking more contexts into account (such as a double click launching the navigation panel only when the Maps screen is showing).  I also have three other Flics that I could dedicate to controlling certain subsystems.

Time will tell what, if any, changes need to be made.



Wednesday, December 09, 2015

Schrödinger's Profile

How do you define when a Tasker profile is active?

One way, is to say it's active when all of its contexts are true.  In practice, though, that can sometimes be difficult to monitor directly, so we tend to use another method.  Commonly, we assume a profile is active when it runs its Entry task.

Normally, these two metrics align exactly and can be considered equivalent.  However, there are some profiles where that's not true; where the contexts are active, but the Entry task hasn't been run.

Since, depending on which definition we use, the profile can be considered both active and inactive, we call these Schrödinger's profiles.  (Yeah, okay.  Fine.  I'm the only one that calls them that, but I like it, and it's my blog.)

So what makes a profile behave like that, and what is it good for?

Creating a Schrödinger's profile is very easy; all you need to do is go into the profile properties and configure the Cooldown time.  Cooldown is a little-used parameter in Tasker that keeps a profile from running it's entry task until the the Cooldown time has elapsed.  If you set a Cooldown of 20 seconds, the profile can't activate any more often than that, even if all the explicit contexts for it are true.

One thing this type of profile is good for is ignoring some triggers, while allowing others of the same type to be acted on.

For example, in the Digital Dash project, I have a profile that watches for changes in the Google Maps navigation notification so that I can display ETA information on the main screen.
(As described here: http://mikesgeneralblog.blogspot.com/2015/10/navigation-eta-information-revisited.html.)

That notification can update many times a minute, particularly when there are a lot of navigation events happening close together, and when it starts counting down distance in tenths of a mile.  I'm not displaying the navigation instructions at all, and I don't really need second-by-second updates, so I've added a 30-second Cooldown to the profile that monitors the notification.  That way I still get data with the granularity I need, but don't waste a lot a system resources processing useless information; I get updates every 30 seconds even though the notification itself updates much more often than that.

The other thing you can do with a Schrödinger's profile is use it to replace a looping task.

I've never been conceptually happy with the Time and Torque task in the system.  I've previously described it as a "rogue task" because it's the only one that isn't triggered directly by some action. (http://mikesgeneralblog.blogspot.com/2015/06/digital-dash-documentation-part-9.html)  Instead, it gets kicked off by the Digital Dash startup task and simply loops about every 30 seconds until the system kills it via the shutdown task.  And that's always bothered me.  I'd prefer that it not run constantly in the background, and a profile with a Cooldown allows me trigger it to run regularly and on-demand without a loop.

Let's take a look at how to get that set up.  Let's say that, for some ungodly reason, you want Tasker to beep at you every five seconds.  We can make that happen.

The first thing to do is base a profile on a context that is always true.  For example, set up a global variable and Set it to something; doesn't matter what it is.  Then, you use a context of "Variable IS Set" in your profile.

Here's what that might look like (Assuming you've Set the %MyLoop variable elsewhere.)

Profile: Looper (468)
        Cooldown: 5
        State: Variable Value [ %MyLoop Set ]
Enter: Action (466)
        A1: Beep [ Frequency:8000 Duration:1000 Amplitude:12 Stream:3 ]


Enter this into Tasker and back all the way out.  After five seconds, you'll get a beep.  And after another five seconds you'll get...nothing.  And every five seconds after that, you'll get nothing.  You get one beep, and that's it.  Clearly, this isn't working.

That's because the Cooldown is really just a timer.  It gets triggered when the profile becomes active and starts counting down.  Once it reaches the end, the profile is allowed to run its Entry task.  The problem is, Cooldown doesn't automatically reset itself.  It only starts when the profile becomes active, and since, in the example above, the profile never becomes inactive, the Cooldown timer won't fire again.

So, we need to make the profile go inactive and then activate it again so the timer can restart itself.

We can easily add a line to the Entry task to accomplish the first part:

Profile: Looper (468)
        Cooldown: 5
        State: Variable Value [ %MyLoop Set ]
Enter: Action (466)
        A1: Variable Clear [ Name:%MyLoop Pattern Matching:Off ]
        A2: Beep [ Frequency:8000 Duration:1000 Amplitude:12 Stream:3 ]



By clearing the %MyLoop variable, we've made the profile go inactive because its context is no longer true.  Of course, we're still not going to get repeating beeps, because all we've done at this point is turn off the profile.  Now we need to activate it again.  We can do that by adding an Exit task.

Profile: Looper (468)
        Cooldown: 5
        State: Variable Value [ %MyLoop Set ]
Enter: Action (466)
        A1: Variable Clear [ Name:%MyLoop Pattern Matching:Off ]
        A2: Beep [ Frequency:8000 Duration:1000 Amplitude:12 Stream:3 ]

Exit: Reaction (467)
        A1: Variable Set [ Name:%MyLoop To:True Do Maths:Off Append:Off ]



So, what happens is, when the profile runs its Entry task (after the Cooldown period has expired) it gets turned off by line A1 in the Entry Task.  This causes it to immediately run its Exit task, which resets the %MyLoop variable, making the context True again, and restarting the Cooldown period.  Note that deactivating the profile does not stop the entry task from running to completion, so we get our beep.  And every five seconds after that, we'll get another beep until we go into Tasker and either disable the profile with its On/Off switch or explicitly clear the %MyLoop variable on the Var panel.

This is the technique I used to convert the Time and Torque loop to a triggered task rather than a loop, and it's working quite well.  I still get regular updates, but nothing is sitting in a Wait state.  And I'm happier with that.


Friday, November 20, 2015

Another Bluetooth Button Control Scheme

My post on adding button control to my Digital Dash project (http://mikesgeneralblog.blogspot.com/2015/08/physical-controls-for-digital-dash.html) has turned out to be one of the most popular ones that I've written. (Around here that only means about 550 views, but it's something.)  It's been linked to in a couple of places and over on the AutoApps forum someone asked me if there was a way to make a button continually perform a task as long as it was held down.  It turned out to be pretty easy, so here's an example that controls the Media Volume of a device.

I chose to use the "Media Rewind" keycode to lower the system's media volume because it made sense in the physical layout of the Bluetooth Gamepad I was using, but you can, of course, use any key you want. To make a companion way to increase the volume, just copy the profiles and tasks and rename them with "Up" instead of "Down" in the names and change the "-1" in line A1 of the first task to a "+1". You'll also need to modify the IF clause in line A3 so that it checks for a maximum value rather than a minimum.

Profile: Vo!umeDownStart (437)
Event: AutoInput Key [ Configuration:Keys: Media Rewind
Key Action: Key Down ]
Enter: VolDown (436)
A1: Media Volume [ Level:%VOLM-1 Display:Off Sound:Off ]
A2: Wait [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A3: Goto [ Type:Action Number Number:1 Label: ] If [ %VOLM > 0 ]

Profile: VolumeDownStop (438)
Priority: 11
Event: AutoInput Key [ Configuration:Keys: Media Rewind
Key Action: Key Up ]
Enter: VolDownStop (439)
A1: Stop [ With Error:Off Task:VolDown ]

A couple of things to note: The first profile triggers on the Key Down event and the second one triggers on Key Up. Be sure you bump up the priority for launched tasks in the second profile; it needs to be greater than the the task it's trying to stop. You'll also need to run AutoInput's KeySupress function before you use these profiles and then disable key suppression when you're done. The 250 ms delay in line A2 seems to give a nice response ramp, but if you want something a little faster, just decrease that value.  Finally, you'll probably need to disable "Restore Settings" in the first profile to make the volume changes stick.

Hope this helps someone.

Wednesday, November 18, 2015

Another (Very) Minor Tweak

I have a control on the main screen that allows me to toggle the tablet's AutoBrightness on and off, but it doesn't get used very much.  99% of the time we're driving in the sun with the top down and I want the tablet at full brightness.  About the only time I use it is on those rare occasions  when we are traveling at night.

It occurred to me today, though, that if I do dim the screen on the tablet, the phone will remain at full brightness.  That would be annoying and since I don't really have a control interface on that unit, changing the brightness would be distracting and annoying, requiring me to go into settings and fumble around.

I don't really want to put controls on the phone, so instead I used AutoRemote.  Now when I toggle the screen brightness on the tablet, it sends a direct message to the phone, which causes it to toggle as well.

As I said, a very minor thing, but when I need to use it, it will be handy.

Wednesday, November 11, 2015

Torque and Tasker

If you're interested in getting data from the Torque app into Tasker, take a look at the video I posted on YouTube:

https://www.youtube.com/watch?v=bjFLbbYakBo

It begins by showing you how to set up Torque, then steps through gathering the information and tools that you need, and finishes up with some actual Tasker code.

Thursday, October 29, 2015

Some More On-Screen Information

I've added a couple more pieces of information to the on-screen display.  Nothing major, just some more things I like to be able to see at a glance without having to interact with the system.

When I first made the Digital Dash, I was using the WeatherAce plugin to query a server and return the nearest local environment temperature.  It worked fine, but when I decided to mount the phone as a secondary screen dedicated to running Waze, I realized that it would be exposed to approximately the same temperature environment as the people in the car would.  So, I set up a task on the phone that would send an AutoRemote message containing data from the phone's built-in temperature sensor over to the tablet about every 30 seconds.  This gave me hyper-localized data, and I figured that if I wanted the surrounding area temp, I could just pull up the Weather Channel app.

But the more I thought about it, the more I realized that I wanted to see both values at any time; essentially an interior and exterior temperature display.  This time, however, instead of using WeatherAce, I decided to just use AutoNotification to scrape the temperature from the Weather Channel's notification.

Because I didn't want to make another display element (that I didn't really have room for) I just stacked the two temperatures into a single variable and linked it to the existing display.  In the screenshot, below, the interior (phone temp) is on top and the environmental temp (from the Weather Channel notification) is on the bottom.  There was enough extra room in the element that I didn't even need to change the font size.




The other piece of data I'm now sending to the tablet is the phone's battery level, along with its charging status.

Since the phone is mounted on the driver's "wing" window, and I don't like stringing cables across the car from the utility port, I normally just plug it into my Anker battery pack, which rides in a door pocket right below the phone.  The only problem is that on more than one occasion I've forgotten to push the button on the pack that starts the charging process.  I thought the phone was plugged in and didn't realize I was draining the battery until the phone put up its low battery warning.

Now, however, I can see the battery level and charging status for both the phone and the tablet right on the main screen.  In the screenshot, above, the tablet is the top entry, and the phone is the bottom one.  This also shows that the phone is plugged in and charging because the data is underlined.  (The tablet entry has the same capability.)

To make this work, I set up two new profiles on the phone.  One is a Power ANY profile with both an entry and exit task, and the other is a Battery Changed profile, which only has an entry task.

Here's the Powered profile:

Profile: V3_PoweredCheck (240)
State: Power [ Source:Any ]
State: Variable Value [ %TabletConnected Set ]

Pretty simple.  The profile just watches for a change in charging status.  The secondary context keeps it from firing unless the Digital Dash system is actually running.  The %TabletConnected variable is set when the phone project runs its startup sequence after it receives a command to start Bluetooth tethering from the tablet.  It's the equivalent of the tablet's %V3_DrivingMode.

Enter: V3_Plugged (241)
A1: Variable Set [ Name:%V3_PowerState To:-1 Do Maths:On Append:Off ] 
A2: Perform Task [ Name:V3_SendBatt Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ] 

Exit: V3_Unplugged (242)
A1: Variable Set [ Name:%V3_PowerState To:1 Do Maths:On Append:Off ] 
A2: Perform Task [ Name:V3_SendBatt Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ] 

The entry and and exit tasks are nearly identical.  They both adjust the value of the %V3_PowerState variable and then call the task that actually sends the AutoRemote message to the tablet.

Because I actually need to send two pieces of information in each message, I use a little simple math to concatenate the data.  As you can see, the entry tasks sets the %V3_PoweredState to "-1", while the exit task sets it to just "1".  Before the data gets sent, I multiply this variable by Taskers built-in %BATT (which contains the actual battery charge level).  So, when the phone is plugged in, the data sent is a negative number, and when the phone isn't charging, it sends a positive number.

Over on the tablet, I make a check for these conditions and use the result to decide whether or not to wrap the battery value in html underline tags.

(This seems a bit convoluted, and in theory AutoRemote can send multiple pieces of data in a single message, but I was never able to get that to work.  The messages just stopped going out, with no error indications.  So I went with this scheme instead.)

Profile: V3_BattTracker (244)
Event: Battery Changed
State: Variable Value [ %TabletConnected Set ]

The battery tracking profile is just as simple.  Any time the battery level changes and the tablet is connected, it executes the task that sends the AutoRemote message.  That's the same task called by the charging/not charging profile.

Enter: V3_SendBatt (243)
A1: Variable Set [ Name:%mybatt To:%V3_PowerState*%BATT Do Maths:On Append:Off ] 
A2: Variable Set [ Name:%tempmessage To:https://autoremotejoaomgcd.appspot.com/sendmessage?key=(My AutoRemote Key)&message=%mybatt=:=Batt Do Maths:Off Append:Off ] 
A3: HTTP Post [ Server:Port:%tempmessage Path: Data / File: Cookies: User Agent: Timeout:10 Content Type: Output File: Trust Any Certificate:Off Continue Task After Error:On ] If [ %TabletConnected Set ]

The messaging task does the multiplication I mentioned above and prepares an AutoRemote message.  The preparation must be done in a separate Variable Set action because if you try to add variables directly to the HTTP Post step, they won't be interpreted and only the variable names themselves will be sent.

This task, like the one that sends the phone's temperature, uses AutoRemotes direct messaging option.  I prefer this, because it doesn't need an internet connection to function.

That's it.  Pretty minor modifications, but nice to have.


Tuesday, October 27, 2015

Navigation ETA Information Revisited - Revisited

I had hoped that my solution to the missing information in the Google Maps navigation notification would be a temporary one.  While it does work, it's definitely a kludge and I'm happy to be able to go back to gathering that content via AutoNotification.

Thanks to a user in one of the AutoApps forums, I learned that the ETA information is available in the variable %antextsbig4 under Lollipop. (Formerly it had just been in %antexts.)  With that knowledge I was able to re-do my profile and task and get them working again, so I thought I would post the solution here.


Profile: V3_ETAScrape (109)
Cooldown: 30
Event: AutoNotification Intercept [ Configuration:Event Behaviour: true
Persistency Type: Both
Notification Apps: Maps
Get All Fields : true ]
State: Variable Value [ %V3_DrivingMode Set ]

This is the profile itself.  It triggers when Google Maps puts up a notification AND the %V3_DrivingMode variable is set.  AutoNotification is set as the event handler and configured to look at both created and persistent notifications.  I've also set the flag so that AN will get all the fields in a notification.

The other thing to note is that there is a 30-second Cooldown set on the profile.  This keeps it from constantly firing as Maps updates the notification.  While it does reduce the granularity of the information somewhat, it keeps this profile from blocking other tasks and may make it a bit more stable.

When the profile fires, it gathers the information from the notification and populates a number of AN variables.  However, for this job we only need one of them: %antextsbig4.  It will contain data that looks something like this:

3.2 mi - Continue onto US 20

2 hr 52 min (165 mi) to destination
Estimated arrival at 2:39 PM

If I had enough room on my main screen, I could just display that info in a text box, but I really don't have that kind of real estate available to me, so I need to take it apart and shorten it up.

Enter: V3_NotificationQuery (102)
A1: Variable Set [ Name:%ret To:
Do Maths:Off Append:Off ] 

The first thing the entry task does is define the %ret variable.  Blogger doesn't show it, but the variable is filled simply by hitting the "Enter" key when you create the variable.  This is necessary because we need to split %antextsbig4 based on line returns and Tasker doesn't allow you to enter a return directly in the Variable Split action.

A2: Variable Split [ Name:%antextsbig4 Splitter:%ret Delete Base:Off ] 

As promised, we first use the %ret variable to split %antextsbig4 into its individual lines.  After the split, %antextsbig41 will contain the turn-by-turn info and %antextsbig42 will be a blank line.  I don't care about either of those, so they remain unused.

A3: Variable Split [ Name:%antextsbig43 Splitter:) Delete Base:Off ] 

%antextsbig43 contains the first line of the ETA information.  By splitting it with a parenthesis I can extract just the first part of the line and ignore the "to destination".

A4: Variable Split [ Name:%antextsbig44 Splitter:at Delete Base:Off ] 

Now I split %antextsbig44, which contains the second line of the ETA info. I use the word "at" as the splitter, which isolates the first part of the line,"Estimated arrival", and leaves me with just the arrival time. (Splitters never become part of a variable, so the "at" is gone as well.)

A5: Variable Set [ Name:%V3_ETA To:%antextsbig431)
ETA: %antextsbig443 Do Maths:Off Append:Off ] 

The last step is to populate the %V3_ETA variable, which serves as the source for my onscreen text display.  It's simply a matter of taking the parts of the lines I've split and concatenating them.  Note that I had to add the ) back in because it was used as the splitter in an earlier step and was, therefore, discarded out of the variable.


This is a pretty simple, but very useful addition to the Digital Dash project and I'm glad to have it working properly again.


Saturday, October 03, 2015

Physical Controls for the Digital Dash , Part 2

Well, it took a bit longer than I expected (about six months longer) but I finally got my Flic Bluetooth buttons.  And I like them; see my full review here: 
http://mikesgeneralblog.blogspot.com/2015/09/flic-bluetooth-button-review.html

I'm not quite sure what I'm going to do with all of them (I have five), but I have added one on the right-hand side of the center console in the Z3 as a music control.

I also thought about mirroring its functions to another button on the back of the steering wheel, but I've found that the car's cabin is small enough that I can reach the button while driving without even shifting position, so I've dropped that idea for the moment.

Here are the functions the button performs.

When the main screen is showing:

Short Click - Next (random) track when PowerAmp is the music source.  When Pandora is playing instead, Skip the current track.

Double Click - Replay the Previous Track (PowerAmp only; no function for Pandora).

Long Click - Display the Favorite Songs menu with a cursor used to highlight selections.

Triple Click - Toggles pause for the currently playing track.

When the Favorite Songs Menu is showing:

Short Click - Cause the music cursor to step down the list to the next entry.  If the bottom of the list is reached, the cursor wraps around back to the top of the list.

Long Click - Select the song under the cursor and have PowerAmp begin playing the track. This causes PowerAmp to display the album art for the song.  After about 5 seconds, the system returns to the main Digital Dash screen automatically.

Double Click - Cancels the Favorite Song menu and removes it from the screen without selecting any track.


If you read the first part of the physical controls documentation, you might recognize those functions as also being performed by the Bluetooth Gamepad that I've re-purposed into a sidearm controller.

In fact, I just reused the same code I wrote for that.  In order to make the Flic perform those functions, all I had to do was create the profiles that caught the various activations.  Once I had done that, I just linked to the existing tasks.  I don't think that it took me 10 minutes to get everything working.

We've taken a few drives and tried out the Flic and it has worked beautifully.  It's much easier (and safer) to click the button than it is to try hit the on-screen controls.

Monday, September 28, 2015

Flic Bluetooth Button Review

I had mentioned the flic Bluetooth buttons earlier when I was talking about adding physical controls to my Digital Dash Project (http://mikesgeneralblog.blogspot.com/2015/08/physical-controls-for-digital-dash.html).  I had been an early backer of the project on Indiegogo with the idea of using them specifically for that system.  I ended up ordering five of them, and four were delivered over the weekend. (Not sure what happened to the fifth one, but it was a late addition and may not come for a while.)

Although I won't be using them entirely as I planned, I've installed one in the car and will be experimenting with the others.  Since these are new, I thought I'd do a review.

What is a flic?

A flic is a self-contained Bluetooth button that can be connected to both Android and IOS devices to perform tasks when pressed.  The free flic software has direct integration with a number of apps and can be used with both IFTT and Tasker (Android only) to control nearly any action that you care to automate. Each flic can recognize three different activation types (Click, Double-Click, and Hold).  You can program these separately, so each button can essentially do three things.

Flics are the brainchild of a Swedish company, Shortcut Labs, who used Indiegogo to crowd fund the startup.  They reached their initial funding goal in only 30 hours and ended up with over $900,000 in pledges; 801% of their original goal.

Packaging

The flics arrived in an attractive box that has a thank you message to Indiegogo backers on the bottom.  The Flics themselves are nestled in custom foam cutouts inside the box.  There are two layers of these, and each one can hold three flics, so each box can contain six buttons.  The foam rests on a cardboard stand which has some space underneath where the optional clips are stored.  

There was also an insert directing you to the website (https://flic.io/), and a large round sticker that  you can use to show your support.

All in all, the packaging provides a nice presentation and holds the contents securely and safely.







Hardware

Each flic is slightly larger than a U.S. quarter and just over a quarter-inch thick.  The body is covered with a textured, velvety rubber embossed with the cursive version of the name from the logo.  

The back is hard plastic that comes covered with thin transparent shield.  Removing that exposes the reusable adhesive that you use to stick the flic to a non-porous surface. If the adhesive loses its stickiness, you can just clean it with water and it will regain its holding power.  I had originally intended to mount a couple of these to the back of the steering wheel in my car, but I don't think the adhesive would be up to that task; it holds the button just fine on the console, however.




The unit is entirely self-contained and powered by a button cell battery that the company claims will last up to five years.  They also claim that the battery is common item and can be easily replaced, although there are no instructions that tell you what to get or how to change it.

Flics come in black, white, green, yellow, turquoise, but I choose all black ones for my application.

The button is light, but it has very nice tactile experience and a satisfying physical "click" when pressed.

There's also a small clip that you can attach to your flic so that you can clip the button to clothing.  The company suggests you might want to do this for personal safety or to provide a way of faking a phone call to get out of a bad Tinder date.

Software

The free flic app is available in both the Apple and Google app stores and is required for operation.  It is used for pairing the button to your device, assigning actions, and changing settings.  You do need a free flic account to use the software.

The flic app is also where you start and stop the flic service.  This service must be running in order to use a flic on your device.  By default, it runs as a foreground service that starts when your device does and puts up a persistent notification.  You can use it as a background service as well, but then it is subject to be killed by memory management.  There doesn't seem to be any appreciable battery drain from this service when it isn't being used, so there's really no need to ever turn it off, but you can if you'd really like to.  

Once you've set up a flic (See Operation, below) you can access the individual functions.  There are 46 built-in app integrations and most of them give you several options to choose from.  You have free rein to set things up as you wish.  That is, one button can control up to three different apps: a single-click might turn on your Phillips Hue lights, while a double-click might send a text message, and a hold command could start a Skype call.

More sophisticated options such as IFTT and "Send Intent" allow for even greater control.  (And, of course, there's Tasker, integration, which means you can do anything you want.  Tasker is covered separately, below.)

I won't cover all the settings, but there is one that I particularly like.  By default, a flic will play pleasant sounding chimes through your device to indicate that it has been pressed.  Each action type has a different chime associated with it, so you know right away if your press has been registered.  For my Digital Dash project, this is ideal and I've left it enabled, but you can turn it off if you wish.

Finally, the app also has a help section that explains most functions, but it also has context sensitive help that walks you through most operations.

This is a nice, simple piece of software that gets the job done.  It has a clean and open look that make it easy to navigate and use.

Operation

Here are the basic steps to using a flic.

Pairing

Pairing is a simple operation.  Just open the flic app and press the button once.  The app generates a key and links the button to your device.  Once that is done, the process is automatic from then on.  Flic appears to use Bluetooth Near to detect the button and activate it.  You don't need to turn it on, wake it up, or do anything else; it's just there when you need it. Once it's in range, it's active.  Once the button is paired, you can go ahead and rename it and configure it.

Configuring

Open the app and touch the button entry on the screen.  It will then take you to another screen where you can add actions for each type of button press.  Just tap the plus sign to get a list of programs.  Click one of those and the system will guide you through the steps to get everything set up.  If you already have an action, there is a standard "three dot" menu that allows you to Remove, Edit, or Execute the action.






Use with Tasker

When I first opened the flic app and began scrolling through the list of possible integrations, I was a bit concerned because I didn't see Tasker anywhere on the list.  I was afraid it didn't make the initial release cut and that I'd need to wait before I could use it.

However, on a hunch, I went into Tasker itself, created an Event profile, and chose the Plugin category.  Sure enough, there was flic.  Installing the app also installed the Tasker plugin.

Using it is very simple.  Once you chosen flic as the Event handler, you just click the standard Tasker plugin configuration icon and you are taken to a screen where you choose the flic you are programming and which of the three activation types you are trying to capture.  Once you've done that, you link the profile to the task you want to execute.  In other words, it's just like every other Tasker plugin you've ever used.  Note that the plugin gives you a few more options, such as triggering on either the up or down portion of a press and executing a task based on the button connecting or disconnecting.




It only took me a few minutes to program the flic to act as a Next Track button for both Pandora and PowerAmp.  In the next day or two I'll be programming its other functions to provide additional music control and I'm confident that it will work as expected.


Notes and Observations

Here are a few random things about using the flic.

You can have up to eight (8) flics connected to a single device.

A flic can only be paired to one device at a time.  If you want to use it with a new mobile, you need to disconnect it from the old one first and move it to the new one by opening the flic app on the new device and pressing and holding the button for at least seven seconds.  The app will connect to the flic servers and download the button's key.  Since all this is stored in your flic account, it will also download the configuration for the button, so your programmed actions come over as well.

Response time is excellent.  When my Digital Dash project is in full swing, it really works the tablet; running turn-by-turn navigation, regularly querying web servers via Bluetooth tethering, running Torque (which is also writing it's own log file), sending and receiving AutoRemote messages, handling interactive screen overlays, playing music, and more.  Despite all that, there was never any lag between pressing the the flic and hearing the confirmation chime.  This is a very fast implementation.

There is a "Providers" screen under settings where you can disable apps or services that you don't use or configure the ones you do.

Conclusions

I like these little buttons a lot. There were some delays in getting them out, but I'm glad the company chose to delay and release a product that they were happy with rather than putting out something that wasn't quite finished.  I feel that they delivered exactly what they promised and I have no regrets about backing them.

As of the time of this review, flics are not yet shipping to the general public.  However you can pre-order them on their website (https://flic.io/) with an estimated time delivery of about eight weeks.

If you need or want a simple physical control for a project, flics are a good choice.