Widget showing home state in real time

(Alex) #1

Hi there,

I wanted to share a a method I used to create an Android widget that shows me the state of my things at home with real time updates.

This is something I cooked up recently, it’s rather rough but it does the job.

The screenshot above actually shows 5 widgets grouped together. The ones of interest here are the two columns of values.

Here’s how it works:
I have a smart app that takes a number of devices I want to monitor. In my case, I monitor doors, locks, lights and presence.

When the state of any of my devices changes, I use Pushbullet service to send a push notification to my Android phone. That push notification contains a JSON string that represents the state of my home.

The JSON string looks something like this:

{"closed":"Front Door","locked":"all","mode":"Home","notPresent":"Mrs","off":"all","on":"none","open":"Garage Door","present":"Mr","unlocked":"none","updated":"12:07 PM"}

This push notification is intercepted and dismissed by Tasker. It’s content is parsed in JavaScript and it passes Tasker variables to Minimalistic Text: Widgets. Then the widget displays the values on the screen.


The app is designed in such a way that it would not send a push notification for events that cancel each other out within one minute. If nothing happens in 15 minutes, the state will be refreshed and pushed to keep things in check. There is no polling from the phone, which is good for data usage and battery life.

Here’s the app:

Here’s the Pushbullet device type that is used by the app:

I hope this inspires someone to make something interesting.

If someone is interested in actually installing and using this, let me know!

Android - Take photo if alarm activated
iOS 8 HomeKit at WWDC
Configure widget so color indicates mode?
(Mike Maxwell) #2

Ahhh, yea, I’m interested.
Not having to plow through all the menus to see device states is worth its weight in gold IMHO
How do the text widgets respond to multi line inputs?

(Alex) #3

I don’t think they would respond too well. I have just a couple of devices to monitor and and wanted to see the overall state at a glance.

I didn’t spend too much time on the layout itself. This is a proof of concept more than anything. Although it works perfectly for me.

Give me some time, I will post detailed installation instructions tomorrow.

(Convinced ST will never be unbroken…) #4

Is your device rooted. How did you get tasker to dismiss a notification it did not create?

(Alex) #5

No, its not rooted.

Tasked tells Pushbullet to dismiss it’s notification. This functionality is baked into Tadker plugin.

I will post step by step instructions tomorrow.

Smart Alarm is here
(Alex) #6

So here are the promised steps to create your own widget.


SmartThings setup

  • Create a Pushbullet device type with this code.

  • This device type holds your Pushbullet credentials and has a function to send a push to your phone.

  • Configure your Pushbullet device with API key and device ID (device settings via IDE or mobile app).

  • Create SmartApp with this code.

  • This SmartApp monitors events from the devices of interest or mode changes. When any event occurs, the app will send a push after 1 minute, so events that cancel out each other will be filtered out. For example, if you unlock-open-close-lock door within one minute, the overall state of your home doesn’t change and a push will not be send. This is done in order to reduce traffic to your mobile device to reduce battery usage. If nothing is happening, a sanity push will be sent every 15 minutes. So the widget is being updated every 15 minutes or when state of the home changes. On the widget screenshot above I display the time-stamp of the latest push so that I know how current my widget is.

  • When sending a push, the app collects the states of all devices, current mode and time-stamp. If all devices are active, it will return “all” rather than the entire list. For example, when all presence sensors are “away” the state will have values “present: none, notPresent: all”. When one of the sensors returns, the state will have values “present: P1, notPresent: P2”.

  • Install SmartApp selecting Pushbullet device above and the devices you want to monitor.

Tasker setup

  • Create task “Prase Json” with 2 actions as such:

  • + Action > Variables > Variable Split. Name: %CLIP, Splitter “SmartThings Home State:”.

  • + Action > Script > JavaScriplet. Paste the code below:

    var map = “[”+ global(“CLIP2”).substring(1) +"]";
    var v;
    v = JSON.parse(map)[0];
    for (i in v) {setGlobal(“ST” + i, v[i]); }

    This code creates a global Tasker variable for each key in JSON string that represents the state of your home. The global variable will be “ST”+key for each of these keys: “open”/“closed”, “locked”/“unlocked”, “present”/“notPresent”, “on”/“off”, “mode”, “updated”.

  • Create task “Minimal Text Refresh”

  • + Action > Task > Perform Task > “Parse Json”. This is to run the task you created in the previous step.

  • For each value of the state you are interested in displaying on your widget, + Action > Plugin > Minimalistic Text > Variable name: “variable”, Variable content: “%STvariable”. For example, if you want to display mode, enter Variable name: “mode”, Variable content: “%STmode”.

  • Create a new Tasker profile > event > Plugin > Received a Push. The event is configured as such: If I receive a “note” containing the text “SmartThings Home State” from “myself” then “dismiss” or “delete” the push. Select task “Minimal Text Refresh” that you created in the above step.

Create widget

  • Add widget to your launcher
  • Select widget size (let’s say 4 x 1)
  • Pick style etc
  • Under “Layout”, add Locale Variable. Enter variable name. For mode, enter “mode”.
  • Add the variables that you would like to display.

This is it. It’s really not complicated and should take about 30 minutes to setup a basic widget.

To summarize, the widget works as follows: When an event in ST occurs, a Pushbullet notification containing JSON string is send to your phone. It’s intercepted and dismissed by Tasker, it’s content is copied into clipboard. Then it’s parsed into Tasker global variables and then passed to Minimalist Text widget to be displayed. This could work for any other widgets that are able to display Tasker variables.

(Ryan) #7

@625alex where do I get the API key to get this set up? Is the API key the same as the access token? In pushbullet.com/account that is all I see. I used curl and got the device id though.

(Alex) #8

@ryan3anderson, API key (Access Token) is under account settings.

Device_iden could be obtained from the home page. Click on the device of interest and the device_iden will be in the URL.

Let me know if you have other questions.

I love Pushbullet. It is a great way to set Tasker variables from ST.

I will be posting more integration ideas.

(Justin Wurth) #9

Alex awesome work on this. If you don’t mind I am going to pull some of this into a smart alarm. Essentially I have an old nook color that I cut over to cm11 and then have created a frame and mounted to the wall. I want to use that as a main panel for an alarm system and by pulling this into gecko’s smart alarm I can have smart alarm update the widget and show the status.

On a side note I think there are some problems with the runIn command where it does not properly work all of the time. I think gecko created his own myRunIn function to handle these scenarios.

(Ryan) #10

Thanks for the clarification @625alex, now where do I put the token and device id? Do I plug them into the Pushbullet device type code? If so, where? This is going to be pretty slick once I get it working.

I haven’t used Pushbullet a whole lot, but I feel like you could some pretty cool stuff with it.

@jjhtpc, that is the same thing I am trying to put together, I just couldn’t figure out an easy way to get mode updates to the tablet & tasker. I am using a Nexus 7 that I will have a small riser with velcro on it and a wireless charger underneath as to keep portability and to issue voice commands through tasker for lights/chromecast.

(Justin Wurth) #11

@ryan3anderson This pretty much details it you will use a lot of what alex had here and then smart alarm. Works really well.

(Alex) #12

@ryan3anderson, you should put the tokens in device configuration. Either via IDE in device details or via mobile app.

(Chris W) #13

thank you for sharing 625alex… having problems with tasker action setup when following:

Create task “Prase Json” with 2 actions as such:

  • Action > Variables > Variable Split. Name: %CLIP%, Splitter “SmartThings Home State:”.

I can’t seem to enter %CLIP% into the field… sorry very new to all of this… I can enter %CLIP though…

(Alex) #14

That was a typo, should be %CLIP.

(Mark) #15

I’m struggling to get tasker to send info. Are the quotes “” meant to be taken literally? For example mode should be entered as “mode”. SmartThings Home State should be entered as “SmartThings Home State:”

(Mark) #16

OK I did find one error above. Parse and Prase are both used in examples above. The correct one is Parse.

Still struggling though. Here is whats happening and not:

  1. Pushbullet is working although I’m not certain its copying notes to clipboard. I turned on “Automatically copy links & notes” in settings and “universal copy & paste”. How do I know if, copying notes to the clipboard is working?
  2. I set up the minimalistic text widget as instructed using the example given. In the local variable I put “mode” NO QUOTES. All I get on the screen widget is %STCLOSED all caps. No variable data.

Please assist me. This looks like a great feature

(Alex) #17

I will try to debug in the next couple of days. I don’t have the device right now.

(Mark) #18

I’m sure its something I am doing wrong. I have screen shots of all my setup for tasker and pushbullet.

(Alex) #19

You don’t need universal copy/paste on. In fact that could be interfering.

Lets test this:

Send yourself a push from another device to the device that runs the plugin. Then open a text field (browser f.e.) and theyn paste the content. If you see the content of the push message in the clipboard, then that part is working correctly.

In Pushbullet app, temporarily turn off option to dismiss notifications. Send a push from ST (by tapping the SmartApp icon f.e.) and see if the notification from ST appears.

If this works, we will take if from here.

(Alex) #20

Wow, I’m an idiot, didn’t even see the screen shots. I’m on tiny screen, so everything is messed up. I will get to it this evening.