HomeHome AutomationThree ways to send data from Tasker to Raspberry Pi

Three ways to send data from Tasker to Raspberry Pi

Getting Raspberries to talk to your Android devices

It’s been two years since my Tasker automation profiles are complimented by a Raspberry Pi board. I understand that spending $30-40 on a new and shiny Raspberry Pi 3 may not be within your reach, but we have Raspberry Pi Zero and ZeroW out and this would be the best $5-10 ever spent! Trust me! I’m going to show you three ways you can connect Tasker and Raspberry Pi together.

Sending data to Tasker and Raspberry Pi

There is a reason why companies want to use a hub or a central server to handle the requests and process the data.  It saves the battery power and CPU use. Plus if you change your phone, or want to add an additional device, the whole process is much simpler to perform.

AutoRemote

I will assume, that you know how AutoRemote plugin works already. If not please have a look here. You’ll need curl installed on your Raspberry Pi (new Raspbian Jessie versions should have it already)

 sudo apt-get install curl

Open AutoRemote app and get the personal URL. Open in in the web browser – you will see the URL change once the website is loaded. Copy the key that starts after the:

 https://autoremotejoaomgcd.appspot.com/?key= 

you will need this to complete the URL later.

Check your external IP or set up a DNS if you want to have an access to the device from outside of your local network. Google My IP to get the IP address or use https://www.noip.com/   to set up a free domain. Make a note of it.

Edit the following URL accordingly:

curl "https://autoremotejoaomgcd.appspot.com/registerpc?key=YOUR_KEY&name=NAME_TO_APPEAR_ON_YOUR_PHONE&id=ANY_UNIQUE_ID&type=linux&publicip=YOUR_PUBLIC_IP_OR_HOST_NAME&localip=$(sudo ifconfig eth0 |grep "inet addr" |awk '{print $2}' |awk -F: '{print $2}')"
YOUR_KEY - The key obtained in the point 2
NAME_TO_APPEAR_ON_YOUR_PHONE - Give it a name ie RPI3
ANY_UNIQUE_ID - make up an ID ie 314
YOUR_PUBLIC_IP_OR_HOST_NAME - the IP or DNS obtained in the point 3

Modify the URL and open up a terminal on the Raspberry Pi you wish to register. It will register the device running the AutoRemote. Paste the URL and hit enter.

If you are running Raspbian Stretch, please note that the code above refers to eth0, which means you will have to update your interface name in the code or tell Stretch to use old interface names. See this post for a detailed explanation of the changes.

Open up a file /etc/ssh/sshd_config

sudo nano /etc/ssh/sshd_config

and scroll down to the end. You will need to add the following line

KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1

Then Ctrl-X to close and Y to save the changes.

Your device will be visible in the AutoRemote app, you should be prompted to enter SSH username and password. If this won’t happen automatically when clicking on the device in AutoRemote hold down the device to bring up the options.  Enter the username and password  (default:  pi, raspberry)Click a message icon and send a test command:

date

After a shoer moment you should see a toast with the current date. If you have disabled the toasts previously, you can access the log to check if the message has been received. Each response issued back to the AutoRemote will have the following format:

linux=:=message

To send messages back to the tasker you can use either:

curl “https://autoremotejoaomgcd.appspot.com/sendmessage?key=YOUR_KEY&message=TYPE_MESSAGE_HERE”
OR
import urlib.request
urllib.request.urlopen(https://autoremotejoaomgcd.appspot.com/sendmessage?key=YOUR_KEY&message=TYPE_MESSAGE_HERE).read()

NodeRED and HTTP requests

Ever since NodeRED is my favourite way of managing smart devices at home, I needed a better way of interacting between a Raspberry Pi and Tasker. Turns out, that NodeRED and HTTP requests are pretty powerful.  While you can’t really send the HTTP request back to Tasker (I use AutoRemote based node – more on that in a moment) due to unknown IP, you always know your NodeRED server address.  HTTP requests are powerful, as data is processed in a JSON style, available to be used in NodeRED.

Use HTTP POST action in Tasker.

Server:Port
YOUR_IP or DNS:1880
Path:
some/directory/
Data:
key1=value1
key2=value2 
Trust Any Certificate 
YES

The information is sent as JSON style values. For each value you have to specify the name of this value (key). If you want to send multiple values, use a new line.

To receive data in NodeRED, use HTTP POST node connected to a HTTP response node. The POST node has to have the same directory as the one specified in the Tasker HTTP request.

Data is received as as key specific payloads. If I was sending the data above, NodeRED would store it as:

msg.pyload.key1  =  value1
msg.pyload.key2  =  value2

You can use this data and pass it forward as a regular payload using a function node:

msg.payload = msg.pyload.key1;
return msg;

To send the message back to Tasker, use HTTP POST node and AutoRemote link used in a previous method.

https://autoremotejoaomgcd.appspot.com/sendmessage?key=YOUR_AR_KEY&message={{payload}}

AutoTools and SSH

AutoTools is easier to use and set up, however, the main limitation is that you cannot message the Tasker enabled device directly. When the SSH message is initiated, you will obtain the response from the Raspberry Pi. You will have to forward the port 22 in your router (default one unless changed) and point it to the local IP of the Raspberry Pi. Mine is 192.168.0.12.

  1. Enter the IP or Hostname
  2. Enter the port number (22 is the default one for SSH)
  3. Enter your username (default: pi)
  4. Enter the password (default: raspberry)
  5. Enter a command to run (ie: date)
  6. Enter the name of the variable which will hold the response (ie: result)
  7. If you want to add files add local paths or online folders

Easy enough. Bear in mind, that if want the Raspberry Pi to send a message to the phone or tablet, it won’t be possible until you will add another solution – ie AutoRemote or NodeRED.

Conclusion

You have plenty of choices on how to send the data between Tasker and Raspberry Pi. Pick the best suited to your situation. I will be using NodeRED for sure, as this is a very approachable programming tool with great support for Alexa, Google Home and other devices.

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)?