Dear community,
Recently joaomgcd of Tasker has released a beta version of Tasker that comes with an extra (and long waited) feature; The Tasker HTTP Request Event and HTTP Response Action functions.
According to joaomgcd on his reddit channel, this releases a range of new features. I agree!
With these new functions we are not only able to not only receive something from tasker but also send something to tasker. Let`s get busy
In this example I will use this new feature to adjust the screen brightness of my tablet running HABpanel without the need of an external service (e.g. myopenhab) or another app (e.g. Fully Kiosk Browser). This is all local from client (OH) to server (tasker)
1) Download and install Tasker Beta
First we need to install the latest beta of Tasker that contains these functions.
The latest beta releases can be found here.
Please note that Tasker is a paid application for Android.
2) Setup Tasker
-
Variable:
First we will create a Global Variable
Go to VARS and add (+) a variable called %VarBrightness -
Tasks:
Go to Tasks and add (+)
First task we name: “Request from OH”
Add action → Variables > Variable Set
Enter name %VarBrightness
Enter To %request
Second task we name “SetBrightnessDisplay”
Add action → Display → Display Brightness
Level → click on the two-arrow-icon on the right
Add %VarBrightness -
Profiles:
Now we add two Profiles
First profile we add (+) event → net → HTTP Request
Configure this profile by
adding to Method: GET
adding to Path /command*
Tasker wants to link this profile to a task, link it to “Request from OH”
Add a second profile name “Event VarBrightness change”
Variables → Variable Set
Enter %VarBrightness as Variable
Link this profile to “SetBrightnessDisplay”
Make sure both profiles are enabled
3) Configure openHAB
Install the exec Binding
Create a script
p.s. I couldn`t get the script started in the script folder so I ended up putting it elsewhere. Depending on the platform you use for openHAB, make sure the script is whitelist and is accessible by OH
#!/bin/bash
# change the IP address to your tasker device
TASKER_URL="http://192.168.88.19:1821/command"
PAYLOAD="$1 $"
# Send the cURL request
curl -X GET "$TASKER_URL" --data "test=$PAYLOAD"
Then we make the script executable by OH
sudo chmod 755 /usr/local/bin/tasker_brightness.sh
Put the script in the whitelist by OH (full path)
/usr/local/bin/tasker_brightness.sh %2$s
Create a thing manually and place it in the things folder, e.g. execute.things
Thing exec:command:ToTasker "Tasker Command Brightness" [
command="/usr/local/bin/tasker_brightness.sh %2$s",
interval=0,timeout=10,
autorun=true ]
please note that wherever you will put your script, it need to be full path as stated in the how-to by Rich
Create two items:
Dimmer TaskerBrightness "Display tablet Brightness "
String TaskerBrightnessOutput {channel="exec:command:ToTasker:input"}
Create a rule:
rule "Send Command Brightness to Tasker"
when
Item TaskerBrightness changed
then
val Number IntBrightness = (TaskerBrightness.state as DecimalType)
//adapt 100% dimming to 8-bit representation
val Number IntBrightnessNew = ((IntBrightness / 100) * 255).intValue()
TaskerBrightnessOutput.sendCommand(IntBrightnessNew.toString())
end
Now whenever TaskerBrightness is changed, the request will be send over to Tasker and it will act accordingly. As Tasker is a very powerfull tool you could almost control the whole android device from openHAB, which makes it really awesome!
Troubleshooting:
As I am not an software engineer I spent a few evenings on this matter. The exec binding is quite old and this forum has alot of old topics regadering the binding. The full example on the exec binding creates a loginfo like such
logInfo("Your command exec", "Raw result:" + yourcommand_Out.state )
This gives a lot of insight of what you are actually sending. Please read the docs for this.
I guess it could be done using the HTTP binding awell.
Now tasker is a bit of a strange duck when it comes to logic. If you run into any problems with Tasker, Joaomgcd created a http request example which you can import into tasker as a project. This could provide some insight in how Joaomgcd thinks and thus how Tasker works.
Goodluck!