Presence detection via Tasker and MQTT (Android only)

I have some led strips that I’ve connected to HA through Wemos D1-minis and mqtt.

Using tasker I set a profile for “Alarm Done” and then have a task that starts sending messages over mqtt to slowly increase the brightness of the leds. By the time snooze is over (6 mins) the lights have reached full brightness. If you get up before snooze fires there’s a tasker task to set the lights to max and then turn them off (to kill the prior task as it’s running in a loop).

thanks for the tip

No the app does not need the phone to be rooted

My server setup is relatively complicated. Everything runs on one computer (host) all in separate docker containers. Including the ngix web server for the reverse proxy. The reverse proxy basically sends the web traffic to my different docker containers depending on the incoming DNS name.
Each docker container responds to is unique port from the same host IP. Docer forwards requests to the internal IP and port of the docker container. i.e.
Host IP is 192.168.178.58
Docker containers run in 172.17.0.x
Request to 192.168.178.58:1884 gets forwarded internally to 172.17.0.2:1883
Docker networking is effectively like setting up port forwarding on your home router.

My router is configured to forward port 443 to my inside computer (docker host) and then on to my ngix reverse proxy docker container

So to try and explain better from an outside my network point of view when you add the ngix reverse proxy:-

I have a letsencrypt certificate for each domain name in the nginx docker container.

Clear as mud?

1 Like

coza73 did you use a more automations with tasker? if yes please share.

Just started to utilize tasker in my automation’s so no, no others yet.

1 Like

Why mosquito double passage?

You use duckdns.org?

In letsencypt how you choose sub domains?

Like
mynane-mosquitto.duckdns.org
Abd
mynane-hass.ducjdns.org

Or?

I have my own .com domain name. I use cloudflare to manage it (free). So I effectively have unlimited sub-domains.
In letsencypt you get a separate ssl certificate per sub domain.
I did hear somewhere that lets encrypt may be doing wildcard ssl certificates soon so in theory you could have one ssl certificate for all. But you will need your own domain name to do that.

I see.

I managed to have nginx, on a pi3, work for HASS using letsencypt and duckdns.org.
So far so good.

Now I wish to fix mqtt, with SSL, and nginx, having a hard time.

Also i didn’t understand how to configure nginx for accessing other services at home when I am outside my network

You can also use Automate instead of Tasker. I’ve made three Owntracks compatible location Flows you can install directly from the app.

I had issues where Tasker stops publishing mqtt messages without any errors. Now I am using httt post and script to publish mqtt mesagges and it seems that this works more reliably. Also, I do not need to rely on Tasker MQTT plugin which is relatively slower than http post. I am relatively new to home assistant and do not have python knowledge so I may wrong…

I too have switched to http post, yes much more reliable than mqtt…

I have the following setup in tasker / ha / owntracks. Owntracks is set to use private mqtt server running on my hassio.

Tasker: On wifi connect.

  1. Use http post to update a h.a. sensor to the name of wifi ssd i connected.
  2. Use hhtp post to run a script on ha. That script sends an mqtt signal from h.a. to owntracks to force a location update.

Tasker: on wifi disconnect

  1. Update the ha wifissd sensor to ‘away’
  2. Delay 5 min then do a force owntracks mqtt Location update.

Hi - could you share more specifics about how you did the http post with Tasker? I am not having success with doing that. Can’t get the post to deliver json service data. Are you using shell scripts, or what exactly has worked for you? Thanks.

First I assume you have the ability to access home-assistant from outside your home network.

I use the Tasker HTTP Post action:-

In “Server:Port:”

https://home-assistant.wherever.com/api/states/sensor.myphone?api_password=mypassword
Whatever DNS…you really need dns…you have setup to point to your home IP.

if you access via the standard port then:

https://home-assistant.wherever.com:8123/api/states/sensor.myphone?api_password=mypassword

In “Data/File”:

{"state":"%location","attributes": {"battery": "%BATT", "charging": "%Charging","wifi_ssid":"%wifi_ssid","latitude":"%lonlat1","longitude":"%lonlat2"}}

The variable %location for me is either ‘home’ or ‘away’. The rest are pretty obvious

1 Like

Thank you for sharing all those specifics. It turns out that I am able to update a sensor, as you are doing, with Tasker HTTP post. And I am set up just that way, meaning that I have DNS and https. (And by the way, that is pretty cool!)

However when I try to pass data to a service with Tasker HTTP post, for example, by trying to pass properly formed json to /api/services/light/turn_off it always comes back with a 400 error. I have tried all different options for syntax, and none of them work. If I pass no service data at all to the service, then it will turn on all my lights, but I just can’t find a way to use the Tasker HTTP post to send data to a service.

People seem to be successful doing this same thing with curl, but for whatever reason home assistant doesn’t seem to like the way Tasker passes data to a service??

If you are able to succeed using Tasker to post to a service, and turn a light on or off, I would definitely be interested in finding out what the secret sauce is!

i also used http post in the pre token era and now i feel a bit lost…

mqtt sounds nice but is too unreliable for presence detection imho

anyone with a good setup right now that does not require api_password?

The guy in this post provided a solution for the new auth system. It works for me.

2 Likes

Hello everybody,

You may also check this:Ariela - Home Assistant Android Client
Its and android client for Home Assistant with build in device tracker (GPS or Wi-Fi or both), MQTT sensors, push notifications etc.