I just wanted to say thanks to the OP for sharing this. It is, by far, the best solution I have found for integrating tasker to Home Assistant. I like the fact that it is secure and works whether you are connected to your home network or not. Also, since you are calling the existing API it gives you access to a great deal of functionality without any special setup on the home the assistant side.
My task keeps running. So my light switch keeps going on when I switch it off via Home Assistant.
I want to run it only once. I did exactly what’s in the OP. Do I miss something?
Solved it:
I made the action to turn on the light inside th task “CALLHA”. But it has to be a task . So on the same level as “CALLHA”.
Now it works great. Thanks!
Hi, with GET request, do you know if a variable is created with the output?
I currently try to create tasks to control my harmony hub which is connected to home assistant. The tasks will switch activities and also if the activity “watch tv” is currently active and I start the task “watch tv” again, everything will power off. So each task will also act as on/off button.
To archive this I need to know the current activity.
Harmony component has sensor.harmony_activity that always has the current activity stored.
So I tried api/states/sensor.harmony_activity to get that.
Do you know if output gets stored in a variable or how I could do that?
Thx for the reply, I’m no pro in Tasker and home assistant so I have to ask:
So %http_data is a local variable which means it’s only existing in the http request task, right?
I’d need it in the “perform task” task I guess, because executing it and then sending a notification popup with “%http_data” the current activity isn’t in there.
Can you elaborate on how you get the current activity with json read? I also have the autotools plugin but never used json read.
Yes, local variables are limited to the task you’re currently running. In your case, could it be an issue with backslashes? It depends on what your URL is and whether it’s followed by a /. Does /api/states/sensor.harmony_activity work?
In AutoTools JSON read I keep simple mode checked, input %http_data as the Json string, and enter whatever fields I want in Fields (state). An Alert -> Flash -> %state should then show you the state.
I only now understood how it works
I thought it just returns the state in normal text. So sth. like autotools json read is mandatory for it to work.
One problem left though:
How can I get everything into one Task? http_data is a local variable again, so I guess it’s just there in the “http request” task. In the “perform task” task it’s not existent.
Perform task needs a task name to work but I cannot rename the “single line task http request”.
Great! While AutoTools isn’t required it does simplify getting the field you want.
Getting it all into one task is relatively straight forward but could you clarify what you’re trying to achieve in detail? The task setup depends on what states you’re dealing with and whether you need to specify an entity_id.
I’m embarassed to share the task, I’m sure it’s overly complicated.
Basically for every harmony activity I’ll create one task. Then I will create a homescreen shortcut to the task. Tapping on it will switch to the activity. Tapping again will send PowerOff.
So in each task I use if and else.
Example Watch Tv button/shortcut: If %state is “play xbox” or “listen to radio” or “PowerOff” then send the POST command to start the activity “Watch Tv”
else send POST command “PowerOff”.
…Of course I could leave that away and just add a “PowerOff” button/shortcut but for me it’s much more convenient this way.
Right now this is done with the help this Plugin: Harmony Tasker Plugin but since now I run home assistant server and it can do this and much more I think it’s better to do it via home assistant.
Ok. Eventually you may consider having Home Assistant push state changes to your Android device but for now you can go the route of getting them via HTTP GETs.
Action 1:
Perform Task (GET)
Set %par1 = /api/states/sensor.harmony_activity
Action 3:
Perform Task (POST) %par1 = /api/services/harmony/watch_tv (or whatever the actual service call is) %par2 = {“entity_id”: “entity here”} If %state !~ Watch TV
Action 4:
Perform Task (POST) %par1 = /api/services/harmony/PowerOff (or whatever the actual service call is) %par2 = {“entity_id”: “entity here”} If %state ~ Watch TV
Whether Action 3 or 4 triggers depends on what the returned state is.
Thank you for the guide, I have tried this and have also double checked all settings as per your screens and it is not working for me. No errors even. Are you able to help point me in the right direction?