⚙️ Using Tasker with Home Assistant (V2)

Did you managed to get it working?

This article is nothing more than a translation of my old tutorial, which has nothing to do with the current one.

You link is totally misleading and I suspect it’s just a bad way to advertise your blog :confused:

Was this implemented, or did you manage to find a workaround? thanks

same with me - can’t get past this “network error” after setting up the HA server entry and selecting “test server”. It’s a reported issue on his github, but still open.

I first tried to use the Tasker plugin, but that didn’t work for me, so I’m now carefully following your nice instructions. One thing you might add is to be sure to turn off Beginners mode in Tasker, otherwise the VARS tab does not show up.

My problem now is that I’m unable to import the generic tasks. Using method 1, the green Import button does nothing in Chrome. No popup to import data or anything.

So on to method 2… downloaded both xml files fine - but when selecting the tasks to import, tasker crashes. Rebooted, tried again several times. No go.

I’m repurposing an old Galaxy S3 phone running Android 4.4.2 in an attempt to dedicate it as a Tasker server for various HASS automations. From all that I’ve read, this older version of Android should be usable with Tasker.

Do you have any advice for me on what I can try next? Is there another way to get those tasks entered?

If you can’t get this project working, you can try this one: Automagic & Home Assistant (plus NFC automation example)

Thanks Giovanni for the advice! I suspect my problem with Tasker is that the Android 4.4.2 version is just too old for the app. I also tried Automagic on this same phone and it also dies with the error javax.net.ssl.SSLException: Connection closed by peer when trying to connect to HA. However, Automagic was able to detect an alert message and auto-open an app. This further implicates an SSL connectivity issue with Android 4.

In any case, I don’t want the automation to be relying on my personal phone. It has to be done on a dedicated phone or tablet which is why I’m attempting to use an ancient Galaxy S3. My next step will be to head over to XDA developers and try to install a custom Android 7 ROM .

The flow is correct. Json is formatted in the third block. It must work as it is.
Check if tou have api enabled in your HA config
https://developers.home-assistant.io/docs/en/external_api_rest.html
Add api string

Maybe you can find a suitable Tasker version here: https://tasker.joaoapps.com/download.html

Thanks @osmoen ! I only found the paid version on GPlay and had no idea there was not only a version suitable for the old Kitkat, but a trial too. I will definitely give this a try as I have had no luck with Automagic authenticating to HA yet.

I have this entry in my configuration.yaml. It is related to api too. You can check if you have that too. I’m speaking about default config row

Giovanni, We should take all further discussion of AutoMagic issues to your initial post and not hijack this Tasker thread. I will be deleting a few of my posts here and moving them to Automagic & Home Assistant (plus NFC automation example) You might also want to delete your last few replies, but I will answer them in the other thread.

Thanks again for all your assistance!

I did try a Tasker version that was supposed to work for KitKat (Android 4.4x), but unfortunately it failed with the same network error as the latest version. Not a dead-end since I will next try installing a custom ROM to bring the old phone up to Android 7.

EDIT: The network error was due to an SSL handshake incompatibility between Home Assistant and the Android 4.4 client. Instead of rebuilding the client - this configuration.yaml http: option solved the server connection error:

http:
  ssl_profile: intermediate

However, importing the XML templates still crashes Tasker. I was able to work around this by using this Tasker plugin.

Been using this setup for a while now with a couple of tasks to switch stuff in HA from buttons on my phone.

I recently tried to set up a switch to be to turned on every 15mins (it runs a automation that then turns the switch back off)

if i run the task by using the “play button” in the task I have never seen in fail and work great.

When i add it to a Time profile to trigger every 15mins then I keep getting the error

java.net.ConnectionException: Failed to connect to …

and the switch does not toggle.

Any ideas

Edit: Some additional testing has shown that it only fails when the phone screen if off. It still works if the phone is locked but the screen is kept on.

Is there a way to add Tasker variables to the service data (%par2) string? I have AutoVoice set up to change the temperature of my thermostat and create a variable of the temperature as %desiredtemp. In %par2 I have:
{"entity_id": "climate.main_floor", "temperature": %desiredtemp} and that gives me an error.
If I put:
{"entity_id": "climate.main_floor", "temperature": 20} it works fine.

How do I allow it to change the number with a variable so I don’t need a profile for every possible temperature change?

Thanks!

Are you sure %desiredtemp is well defined?
Can you use the Flash action to display the whole body before sending it to home assistant?

Also, have you checked the error log of home assistant?

1 Like

@bokub Thanks for this, its really handy. One note though, when I imported your tasks I noticed that you have the collision handling on these tasks set to the default which is Abort new task. Since these are very generic tasks likely to be called all over from Tasker and don’t attempt to modify any global variables I’d recommend changing that to Run Both Together. Otherwise if two different tasks attempt to do a call-service simulataneously one will just be aborted and lost without the user knowing the call got dropped.

Also I needed a make use of a few more tasks for APIs in my own Tasker so I expanded the list of tasks to include HA create-event and HA set-state. They’re pretty straightforward, %par1 is the name of the event or sensor (for create-event and set-state respectively) and %par2 is the body of the API call.

I also made an HA get-state for convenience. It doesn’t do anything you couldn’t do with HA Template its just a bit easier if you only need the state or one attribute of something. %par1 is the name of the entity you want and %par2 is the name of the field or attribute you want. Note that this one does depend on AutoTools for its JSON Read functionality which may make it less useful to people. It could be pretty easily adjusted to ignore %par2 and just return the JSON and then have no dependency on AutoTools.

One other note, since there’s 5 of these now I refactored error handling into a common task I called HA API Error so anyone using my tasks will need that as well. I tweaked your HA call-service and HA template to switch the collision handling mode and use my common error handling task.

Anyway just wanted to share, thanks again.

[EDIT] Oh I almost forgot, I added one other convenience to HA call service in my copy. If par2 does not start with { (and therefore isn’t JSON) then assume it is an entity_id and set the body to {"entity_id":"%par2"}. Seemed to simplify a few common service calls for me.

2 Likes

Ah, rookie mistake.
My regex was pulling out “20 degrees” instead of just 20.

Thanks for suggesting to use Flash, that made it extremely obvious where the mistake was.

Woah, you took it to another level, for sure!

I’ve edited my tasks so they have the Run Both Together option selected. Thanks for your suggestion :+1:

About your create-event and set-state tasks, I personally never use these features of home assistant, and I preferred to keep it simple, but it’s great that you could adapt this tutorial to your own needs!

1 Like

Yea those two are definitely way less common, I’m sure most people don’t need them.

create-event I use basically as a way to trigger a Node-RED flow from tasker. I do most of my automation in Node RED but I prefer to have everything external go through HA rather then directly to Node-RED HTTP In nodes. I also generally prefer to have all those flows be state driven but there are a few exceptions I can’t avoid.
For example, the Nest x Yale smart lock has no way to integrate with HA at all (don’t buy this thing, learn from my mistake haha). So as a workaround I settled on using AutoNotification to look for the “Door unlocked” notifications and create a door_unlocked event that Node-RED can then use to trigger “someone we know besides us used a code to enter our home” automation.

set-state I only use for one thing, I have my phone report in to HA with its basic state. There’s a sensor in HA with basic details of my phone like is power connected, is bluetooth turned on, is wifi turned on, what’s the battery level, is my phone connected to my car, etc. Everytime a state of my phone I’m interested in changes it reports in to HA and updates this sensor.
I was doing this mostly to workaround issues with the HA android app since it reported only a limited amount of state and was very slow to react to changes (like plugging in the battery charger). That’s been improving quickly though so this one may go away soon. I’d definitely prefer to just let the HA app handle this.