HomeTaskerTasker: Perfect AutoNotifications

Tasker: Perfect AutoNotifications

Create any AutoNotification in seconds using a single profile!

Are you still creating notifications on your Android device like it’s 1969? Instead of creating AutoNotifications for each event, do it the smart way! Use Tasker: Perfect AutoNotifications instead. You will save time and make your notifications better! Perfect Notifications can be used with NodeRED, EventGhost and other Android devices.

From Near Perfect AutoNotifications to Tasker: Perfect AutoNotifications

If you are a fan of automation, you probably stopped creating AutoNotifications manually a long time ago using Near Perfect AutoNotifications. As the name suggests, this was an inferior, sting based method. While this is still a perfectly viable way of creating AutoNotifications, it comes with limitations.

To create a Near Perfect AutoNotification entire string had to be created, even if you had no intentions of using all the custom fields. The AutoRemote string would look like this:

NOTIFICATION silent=:=This is the title=:=This is the text of the message that will have over 37 characters to illustrate the point=:=messageID=:=#5481D4FA=:=2=:=notification=:=notificationbig=:=button1=:=button1action=:=button2=:=button2action

Thanks to JSON, I could finally make my system ideal with Tasker: Perfect AutoNotifications.

Tasker: Perfect AutoNotifications

I mentioned JSON a moment ago. Please don’t panic. First of all, read the 5 min guide to JSON. This will make things super simple to understand. Secondly, you can just modify the existing template. This way, you can create your own notifications.

To make the system work, I need three Joao’s plugins. First is fairly obvious: the AutoNotification, other ones are AutoRemote to send the notifications from one device to another and AutoTools to read JSON format and assign the variables.

Tasker: Perfect AutoNotifications are available without root, and compatible with NodeRED, EventGhost and other Android devices. Thanks to JSON I no longer have to define all values used in the AutoNotification and I can send as little info as I need without breaking the system.

JSON Template

This is a sample template. There are more fields you can configure this way, just take a look at settings in AutoNotification. If the setting contains a variable to control it, you can use the key and value pair to pass the correct information.

{
  "text": {
    "text": "some text",
    "textexpanded": "some expanded text"
  },
  "title": {
    "title": "some title",
    "titleexpanded": "some expanded title"
  },
  "icons": {
    "navbaricon": "icon path",
    "bigicon": "icon path",
    "smallicon": "icon path",
    "iconexpanded": "icon path"
  },
  "notificationid": "someID",
  "persistent": True,
  "priority": 3,
  "color": "#b9512c",
  "backgroundcolor": "#fafafa",
  "picture": "pictureurl",
  "buttons": [
    {
      "button1": {
        "icon": "iconURL",
        "label": "label text",
        "command": "command"
      },
      "button2": {
        "icon": "iconURL",
        "label": "label text",
        "command": "command"
      },
      "button3": {
        "icon": "iconURL",
        "label": "label text",
        "command": "command"
      },
      "button4": {
        "icon": "iconURL",
        "label": "label text",
        "command": "command"
      },
      "button5": {
        "icon": "iconURL",
        "label": "label text",
        "command": "command"
      }
    }
  ]
}

I mentioned that you can use several systems to send an information to your Android device. Tasker: Perfect AutoNotifications works well with NodeRED, EventGhost or other Android devices.

Tasker: Perfect AutoNotifications for NodeRED

I’m a big NodeRED fan, you probably know this. It should come as no surprise that I tried to send the notification from the NodeRED server first. It took me some time to actually find a correct way of passing this information to my Android device. The flow is very simple.

Everything happens inside a single Function node. There are several fields that have to be configured to compose the final message and send it as an HTTP POST request.

NodeRED: Function Node
  • key  – AutoRemote key of the target device – here obtained using NodeRED Credentials
  • command – Tasker’s AutoRemote Event command that will trigger the profile
  • body – the actual JSON object
var key = global.get('AR_Pixel');
var url = "https://autoremotejoaomgcd.appspot.com/sendmessage";
var command = "NOT20";
var body = {
    "title": {
        "title": "AN title",
        "titleexpanded": "AN expanded title"
  },
  "text": {
        "text": "AN text",
        "textexpanded": "AN expanded text"
  },
  "icons": {
    "navbaricon": "local path or URL",
    "bigicon": "local path or URL"
  },
  "notificationid": "someID",
  "persistent": true,
  "priority": 1,
  "buttons": [
    {
      "button1": {
        "icon": "local path or URL - NOTE not available on Lolipop+ devices",
        "label": "Button Label",
        "command": "Button command"
      }
    }
  ]
};
msg.data = body;
var x = JSON.stringify(body);
var encodedBody = encodeURIComponent(x);

msg.url = url + "?key=" + key + "&message=" +command + "=:="+ encodedBody;
return msg;

I mentioned, that you don’t have to configure every field. Just the ones that you want to display in the Perfect AutoNotification. Once msg.object is formatted, it is sent to HTTP POST node that handles the rest.

Tasker: Perfect AutoNotifications for EventGhost

EventGhost has the ability to send the POST requests using Python. The process is very similar to the one described above. To issue the request we have to use Python Script – action. The action should be configured in the following way:

EventGhost: Python Script
  • key  – AutoRemote key of the target device – here obtained using EventGhost Credentials
  • command – Tasker’s AutoRemote Event command that will trigger the profile
  • armessage – the actual JSON object
  • Booleans values, unlike in JavaScript have to be spelt with upper case letters (True|False)
import requests
import json
import urllib

key = getattr(eg.globals, "AR_Pixel")
url = "https://autoremotejoaomgcd.appspot.com/sendmessage"
command = "NOT20"

armessage = {
    "title": {
        "title": "Did I mention EventGhost Support",
        "titleexpanded": "EventGhost works just the same"
  },
  "text": {
        "text": "Send your notifications from NodeRED and EventGhost",
        "textexpanded": "Or from one device to another"
  },
  "icons": {
    "navbaricon": "/storage/emulated/0/Tasker/icons/random_icons/checkbox-marked-circle.png",
    "bigicon": "/storage/emulated/0/Tasker/icons/random_icons/checkbox-marked-circle.png"
  },
  "notificationid": "someID",
  "persistent": True,
  "priority": 1,
  "color" : "#0097a7",
  "buttons": [
    {
      "button1": {
        "icon": "https://raw.githubusercontent.com/google/material-design-icons/master/file/2x_web/ic_file_download_black_48dp.png",
        "label": "Cool",
        "command": "Download"
      }
    }
  ]
};
payload = command + "=:=" + json.dumps(armessage)

headers = {'Content-Type': 'application/json'}
param = {'key': key, 'message': payload}
response = requests.post(url, headers=headers, params=param, json=payload, verify=False)

This action will issue the notification for you. Note, that using EventGhost variables, you can set JSON fields dynamically, it will make the action more complex, but you won’t be forced to create a Python action every single time you want to create a new notification.

Tasker: Perfect AutoNotifications Tasker Profile

Now, that we know how to send the JSON message to our Android device, we have to create a Tasker profile to handle this. Before you do this, you can decide what kind of notification you can create. AutoNotification allows you to create several types of Android notifications. All of them can be controlled in the same way, however, you will need one Tasker: Perfect AutoNotification profile per each notification type.

I’m only going to focus on the most popular type. You will see that translating this to other types is simple.

TASKER PROFILE: Perfect AutoNotification
Profile: Perfect AutoNotification 
	Event: AutoRemote [ Configuration:NOT20 (regex) ]
Enter: PN Create Notification 
A1: Variable Set [ Name:%Test To:%arcomm
	Recurse Variables:Off Do Maths:Off Append:Off ] 
A2: AutoTools Json Read [ Configuration:Input Format: Json
		Json: %Test
		Fields:         text.text,
				text.textexpanded,
				title.title,
				title.titleexpanded,
				icons.navbaricon,
				icons.bigicon,
				icons.iconexpanded,
				buttons[0].button1.label,
				buttons[0].button1.icon,
				buttons[0].button1.command,priority
		Separator: , Timeout (Seconds):60 ] 
			A4: AutoNotification [ Configuration:Title: %title_title
		Text: %text_text
		Icon: %icons_bigicon
		Status Bar Icon Manual: %icons_navbaricon
		Status Bar Text Size: 16
		Background Color: %color
		Colorize Background: true
		Id: test
		Priority: %priority
		Title Expanded: %title_titleexpanded
		Text Expanded: %text_textexpanded
		Icon Expanded: %icons.iconexpanded
		Separator: ,
		Button 1: %buttons_button1_command
		Label 1: %buttons_button1_label
		Action Icon 1 Manual: %buttons_button1_icon Timeout (Seconds):20 ] 

Create the AutoRemote Event trigger that will respond to a command. In my example I have NOT20 – it’s unique enough and It’s unlikely that I will pass this value accidentally in the JSON file.

The JSON message will be stored in %arcomm and processed by AutoTools JSON Read action. I have transferred the data from local %arcomm to %Test so you could see it first. Make sure that AutoTools JSON Read action doesn’t use “simple” option, as we have to use verbatim data structures. Fields to get are:

text.text,text.textexpanded,title.title,title.titleexpanded,icons.navbaricon,icons.bigicon,icons.iconexpanded,buttons[0].button1.label,buttons[0].button1.icon,buttons[0].button1.command,priority

You can add more or limit the fields that you want to obtain. It’s up to you.

Next is the AutoNotification action. As you can see in the description, I only assigned a couple of most used values. Feel free to populate the AutoNotification fields to your liking. Each JSON field will be translated by AutoTools JSON Read:

text.text  = %text_text

Populate the AutoNotification action to your liking and you are done!

Tasker: Perfect AutoNotifications for other devices

If you have the need to send the message from one device to another or create the notification locally, Tasker: Perfect AutoNotifications can be also modified to support it.

Sending AR to another device

Create an AutoRemote Message action in Tasker then type in the command followed by the JSON message.

NOT20=:={JSON object}

The AutoRemote profile above will take care of the message once sent to another Android phone.

Sending AR to create AutoNotification locally

In a similar fashion, the JSON object can be used to create a new notification on your phone. This means that next time instead of creating the entire AutoNotification, all you need to do is send the JSON message as the AutoApps command.

You will need a separate profile that will respond to the AutoApps command instead, but the process of creating AutoNotifications is exactly the same. You can even link it to the same task.

Conclusion

Finally, AutoNotifications are perfect. I no longer have to configure each notification on the phone. Typing it all out as a JSON file in a notepad or web-based JSON editor, then pasting the string to a script or action is so much easier. Hope you will start using this method as well.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How to wake on LAN computers and put it to sleep with Power Menu,...

0
How to Wake on LAN properly via Android, Alexa, Google Assistant and Web

7 awesome Bluetooth keyboard shortcuts for Android

0
7 unique Android shortcuts that you can add to any Bluetooth keyboard.

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

One thing that Join app can’t do and how to fix it with Tasker

0
It's not possible to share the clipboard automatically between join accounts registered to 2 different emails. But you can fix this with tasker.

Essential Guides

Tasker: Seconds into DD:HH:MM:SS (dynamic)

0
It's time to.... ok it's a pun, but I will show you how to master time and convert seconds to DD:HH:MM:SS dynamically

4 ways to organise Tasker projects

0
Keep your Tasker tidy!

A better way to store Tasker credentials

0
The more clever way of managing credentials

Annoyed with dozens of AutoApps populating your app drawer? Here is a fix!

0
Clear your app drawer from the clutter in seconds

Putting AutoTools pie chart to a good use – SSID logger

0
Who wants a piece of the pie (chart)?