Tutorial: Using the new Auth system with tasker

I only now understood how it works :grin:
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.

:smiley: 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.

Looks like this:

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 2:
AutoTools JSON Read
Simple Mode checked
Fields = state

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.

Pretty good plugin for Tasker available here, no need to mess around with the HTTP requests:

Tip: Auto tools can build your JSON for you

1 Like

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?

Oh, I missed your reply 'cause you didn’t reply to my post :smiley:
However in the meantime found a solution, a bit different:

In the “Call HA get” Task (the one with http request and autotools json read) I added task -> return action.
In there I entered the %state variable. This is specifically made for “perform task”.
Now in the “perform task” task there is a field “Return Value Variable” where you put in a variable that gets the content of the %state variable from “Call HA get” Task :slight_smile:

Thanks for this write-up !

I can git it to work, but i have to execute the task 2 times in a row for it to work. If i only run it once, nothing happens. Anyone else experiences this behavior ?

I am using Home Assistant cloud BTW.

I’m trying to get a toggle switch working but i’m stuck on the current state part.
I tried this solution without luck: "Quick Settings" Toggle Tiles by Tasker on Android

A few things were suggested in that thread but since this one is more active i thought dropping my question here.

Like i said i’m stuck in getting the current state when submitting my POST request, lights switch on and off but i can not get the current state.

I did some reading here: https://developers.home-assistant.io/docs/en/external_api_rest.html
And if i’m correct the only status you will get returned are:

Successful calls will return status code 200 or 201. Other status codes that can return are:

  • 400 (Bad Request)
  • 401 (Unauthorized)
  • 404 (Not Found)
  • 405 (Method not allowed)

Is that correct or am i missing something?
The only solution i can think of is to do a GET directly after the POST to get the current status or can it be done more simple?

I use the Join notifier to send me every state update for the entity_ids I define. While HTTP Get works I find the notifier approach is more streamlined.

Is Join notifier sending silent notifications then?
I don’t need an extra notification just to toggle a icon to show it’s status if you understand what i mean.

Yes, they’re silent. Meaning they utilize the AutoApps command system to update the global variables I’ve assigned in my setup. I use KWGT to display my current sensor states in a custom widget. For more pressing events, like door lock events or if a door stays open for more than 2 minutes, I use AutoNotification to generate custom notifications.

Here’s my motion and door sensor update automation:

- id: '1293844881759'
  alias: Sensor Update
  trigger:
  - platform: state
    entity_id: binary_sensor.wyzesense_7782663d, binary_sensor.wyzesense_778376d9, binary_sensor.wyzesense_77850f6d, binary_sensor.wyzesense_778b9919, binary_sensor.wyzesense_778bc206, binary_sensor.wyzesense_778265c5, binary_sensor.wyzesense_7781a5a0, binary_sensor.wyzesense_77837920, binary_sensor.ring_front_door_motion
  action:
    service: joaoapps_join.send_tasker
    data_template:
      command: >
         {% set Data1 = 'Sensor_' + trigger.to_state.attributes.friendly_name %}
         {% set Data2 = trigger.to_state.state %}
         {% set Data3 = Data1 + '_update' %}
         {% set Data4 = now().strftime('%D %H:%M') %}
         {% set output = 'sensor=:='+Data1+'=:='+Data2+'=:='+Data3+'=:='+Data4 %}
         {{output}}

I am trying to update my “input_datetime.flemming_phone_next_alarm_date_and_time”, but I can’t get it working. I have tried for days without any solution, the sensor will not update.

This is the closest I think is right, but it don’t work:
par1
/api/services/input_datetime.set_datetime
par2
{"entity_id":"input_datetime.flemming_phone_next_alarm_date_and_time","state":"%year-%month-%day %hour:%minute:00"}

normal “toggle”, “on”, “off” tasks works fine, but they only have entity_id in par2.

What stands out is the dot in par1. Try replacing it with a /: /api/services/input_datetime/set_datetime

At least I got another error message :wink: so I think it is closer.
But it don’t work.
Now I got Javascriptlet: line 8 :400 - 400: Bad Request

To me it looks like you need to replace “state” with “datetime” in par2? Could that be the issue?

hmm, not, same error

Update. If I hard-code it like this it works:
{"entity_id":"input_datetime.flemming_phone_next_alarm_date_and_time","date":"2019-10-31","time":"10:15:00"}
“Just” have to make the AutoAlarm variables work then

image
After some more work I can confirm this working:
{entity_id":"input_datetime.flemming_phone_next_alarm_date_and_time","date":"%year-%month-%day","time":"%hour:%minute:00}
It turns out I disabled alarm during diagnosis and AutoAlarm variables don’t have a value if alarm is not set.

Did you get any solution. I am also stuck at same

So, I’ve created a version 2 of this tutorial, which should be a lot easier to follow

It uses generic tasks with a nice error handling, simpler parameters, and no javascript :wink: