Create your own personal assistent with Tasker (in multi language) + Google Now integration

This is a tutorial how you can control your devices by using your voice in your own language…
All this can be also triggered by Google Now.

Requirements:

  • An android phone
  • Tasker
  • Autovoice

Setup Tasker:

Configuration File

First I like to setup several thing, so I made a task, that I only need to run once… I’m putting my host, password and my devices in here. (When a device changes, then I only need to change it on 1 place, and all the other tasks will change as well).
So a config task would be like this in tasker:

- Variable set: %HASS_PSW To ?api=xxxxx
- Variable set: %HASS_HOST To http://yourhost:8123
- Variable set: %HASS_SERVICE to %HASS_HOST/api/services/
- Variable set: %HASS_STATE to %HASS_HOST/api/states/

Then your devices with your correct ID of HASS eg:

- Variable set: %HASS_WOL to switch.wol
- Variable set: %HASS_TOPLIGHT to light.living_toplight
- Variable set: %HASS_SIDELIGHT to light.living_sidelight 

After creating this, you need to run this task, so Tasker knows all the variables and remember it.

In the autovoice plugin:

  • Activate Google Now integration, if you want integration with Google Now
  • Set your language: General settings > Default Recognize Settings > Language Settings > Language (Also Language Code)
  • Don’t forget to enable in your android settings, the accessibility for Autovoice

In tasker:

Create a general profile

- Create a new profile
- Choose Event > Plugin > Autovoice Recognize
- Checkmark Event Behaviour
- As command filter use: (?<task>.+) my (?<device>.+)
(beware of typo mistakes)
- Checkmark regex

Create a new task

  • Work with if-else function

Example 1: task to turn off/turn on task with if-else statements inside the task

I prefer to use just the If statement instead of the if-else statement, because I can collapse my code…

- If %task ~ turn on AND %device ~ living lights (turn on living lights)
 - Variable set: %service to light/turn_on
HTTP Post:
- Service port: %HASS_SERVICE%service%HASS_PSW
- In data / file: {"entity_id":""%HASS_TOPLIGHT","brightness":"255"}
- content/type: application/JSON
- End if

- If %task ~ turn off AND %device ~ living lights (turn off living lights)
 - Variable set: %service to light/turn_off
HTTP Post:
- Service port: %HASS_SERVICE%service%HASS_PSW
- In data / file: {"entity_id":""%HASS_TOPLIGHT"}
- content/type: application/JSON
- End if

...

Example 2: Dim lights task

Create first a profile with the following command:

dim (?<device>.+) to (?<percentage>.+)%

Then your task:

- If %device ~ living lights 
 - Variable set: %service to light/turn_on
HTTP Post:
- Service port: %HASS_SERVICE%service%HASS_PSW
- In data / file: {"entity_id":""%HASS_TOPLIGHT","brightness":"%percentage"}
- content/type: application/JSON
- End if

Commands

Above a little example to turn on or turn off things, but you can create also other profiles likes:

- dim (?<device>.+) to (?<percentage>.+)%
- activate (?<scene>.+) mode
- ....

You only need to change data and attributes…

The beauty of this, is that I can use Google now, so I can use Google AI to recognize my speech, and when I say a command by saying OK Google, it will also send it to my tasker autovoice…

Those examples are in english, but I on my phone I’ve all the commands in dutch. It works great… But I couldnt post it here in dutch, because nobody would understand :stuck_out_tongue:

I’ve not yet made a video demo of integration of HASS.
But I’ve an 2 year old demo of tasker + autovoice for automation my phone (a small part what my personal assistent can do): https://www.youtube.com/watch?v=DsF2PelmX_E and here a demo in dutch (3 year old video): https://www.youtube.com/watch?v=8OAo8ehBAzU
Now I will also integrate HASS in my personal assistent

PS: if you are not familiar with tasker, follow me… I’ve made more then 100 tutorials and my Google+ community counts around 6600 subscribers

14 Likes

Have you thought about leveraging hass’ built in conversation process to do this? I use Tasker and Autovoice as well. I have it set up to listen for the keyword “home assistant” and then send everything it hears after that to the conversation process of hass. I use a plugin for Tasker called RESTask, which sends {“text”: “%avcommnofilter”} (%avcommnofilter is the local variable that holds the text that comes after my keyword on the voice activation) to http://your-server:8123/api/services/conversation/process. It works very well and there is no need to crete a bunch of complicated if/then statements!

I know what %avcommnofilter is… and yes you can process that to the build in conversation. But that is limited in only english… And its only limited to turn on and turn off things. The way I present will support also other languages as well and by using different profiles you can also manipulate other stuff…Eg. you can creat profile for dimming lights, activate scenes, and way more… And I tested also conversation before, it doesn’t recognize everything very well… If I use google now integration, it use google AI what recognize way better…

Well by using the conversion plugin via the REST-API it is not used to convert speech to text. But I do see the limitation in conversation to only turn on / off things. Maybe there is a way to make it more configurable by using the alexa component somehow.

Cheers

I just took a quick look into the Alexa documentation over here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference#intentrequest

And it seems very possible to do it this way. So for people using alexa this might actually be easier to implement that way.

Cheers

Alexa, one on the biggest limitation and dissappointment for people is; not supporting multilanguage…
I agree, for people who want to use english as native language it maybe great…

Best solution for people who want multilanguage is for now Tasker + Autovoice, also it has way more possibilities, only a little bit more work to setup… but once done, it’s great…

1 Like

I think I might have not been clear or you might have misunderstood me. We would not use anything from amazons alexa actually but only the component of HA for alexa.

We could then use tasker to send REST calls to the HA-Alexa API (and as the voice recognition is completly handled on your android it is multilanguage) )with the schema mentioned by me above. Again: This is about the same (maybe even a bit more) work than your approach but for people already using Alexa or wanting to do more complex things (condtions / scripts / templating) I think that would be a good alternative.

Cheers

After trying to get this to work for some time…
I think you have misspelt entity as entitity. :slight_smile:

Ooops, my mistake… Where are my thoughts, lool :grin:
I will correctit

1 Like
- Variable set: %HASS_PSW To ?api=xxxxx

Should be

- Variable set: %HASS_PSW To ?api_password=xxxxx

Had me pulling my hair out that it was not working :slight_smile:

I have it working now and am super excited!

If you are only using this at home you might want to whitelist the IP of your mobile. Then you would not need a password :slight_smile:
Cheers

1 Like

Can you expand a little on this? I’m trying to get this setup. Mainly with Restask fields. I have Request type as Get and Host details but that’s it.

Thanks ahead.

Basically what I am doing is using the built-in HASS conversation API endpoint to process the text instead of processing it in Tasker. Using AutoVoice, you can set it up so that when you do a voice search with Google, it listens for a keyword. In my case, I set my keyword to “Home Assistant”. Once it hears the keyword, it automatically starts capturing anything that you say after that. AutoVoice saves what it hears in a Tasker local variable called “%avcommnofilter”. I then take that variable (which contains something like “turn living room off”, for example) to the HASS conversation API at http://your-server:8123/api/services/conversation/process in the form of {“text”: “%avcommnofilter”}. HASS then interprets the input and turns the living room group off.

To set up Restask:

  1. Set request type to Post

  2. Set your host.

  3. Scroll down on the settings page and check “Enable custom body”

  4. In the custom body field, enter what you want to post to the API. In my case it is {“text”: “%avcommnofilter”}

  5. Slide over to the Headers tab

  6. Add a header with the name “X-H-Access” (minus the quotes) and the value your HASS front-end password

  7. Test your connection with the play button in the top right corner. If it is connecting you should get a return value of 200 or 201.

1 Like

Hey @broesie,

Thank you for sharing this. I’m starting to play with Tasker and looks interesting.

Quick question. Do you have by any chance an example on how to read a state from a HA entity in Tasker? I’m interested in how to process the json result in Tasker.

An example of like to understand might be something as simple as the current temperature from a forecast sensor.

Thank you in advance!

1 Like

Yep, true :slight_smile:

When something changes, Home Automation will direct send Tasker values. I use Join (Send Tasker Command) in HASS… Then I can do whatever what I want with that value in Tasker… (Just add some automation in HASS)

Also I added today, that I can control it directly from my quick settings. (Android 7.0 and up).

Also if you are super excited, check this post as well, so you can directly control it by using your Quick Settings:

But in your case, if you followed this tutorial, you have made already the most things, so then you need only create your toggle tasks :slight_smile:

1 Like

Thank you for great tutorial @broesie. You convienced me to buy AutoVoice :slight_smile:

I am using HA with Lets Encrypt and DuckDNS…so it’s SSL and my %HASS_HOST is therefore https://myaddress.duckdns.org . Does Tasker work with SSL?

I did all the steps you have written down, but it’s not working for me, I changed ?api=xxxxx to ?api_password=xxxxx as @iantrich has written in his post.

When I use vocie commands, I get a toast notification:
Received possible command: turn on ambient

Which is correct.

My tasker:

I found a mistake. In your tutorial you have written (every time):

- In data / file: {"entity_id":""%HASS_TOPLIGHT"}

It’s one double quote too much, it should be:

- In data / file: {"entity_id":"%HASS_TOPLIGHT"}

It’s all working nicely now :slight_smile: