Android as it requires tasker - https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm&hl=en
Telegram account - https://telegram.org
Telegram-cli - https://github.com/vysheng/tg
So a little back story, for a few months now I’ve been helping a co-worker with his openHAB implementation, and like most Android phones he had some phones switch to newer versions of Android causing a lot of problems with being properly identified when he or his family was home (also lots of random lights ON/OFF events).
Like me he has a Raspberry Pi and I shared the python bluetooth detection scripts that I use on my Pi and don’t have issues; however while this helped it still was not a stable solution for him.
Back in Sept I posted how you can use keywords/codes in a telegram message to a group chat or a saved message; reference Controlling OpenHAB by Telegram?. This will require two scripts and a custom virtual switch to represent your phone.
Fantastic, but get to the point!
As I had also talked my co-worker into purchasing tasker for his phone I had the idea to use tasker to send a message via telegram with keywords based on him being connected on his home WiFi.
- Within tasker:
Set a state profile and search for Wifi Connected
Put in your home SSID (case sensitive)
- Add a task
Setup a variable for your chat ID and other long character values that telegram requires.
Setup a HTTP Post action and use the following blog to complete the task (covers the variable setup too, which can be optional) - http://www.marrold.co.uk/2017/04/push-notifications-from-tasker-to.html
- Add a task
Setup a HTTP POST action and set the server port to your myopenHAB.org
Call your REST API item in the Path
For Data / File the command supported by that item (if a light switch ON or OFF)
- End Alternative
- Duplicate the task you created in step 2 and name it differently.
Change the text value to the other keyword you setup within telegram-cli and add this to the profile you setup for the WiFi connection as an Exit task. Also put a wait in place on the exit task, so your phone has enough time to flip on the mobile data radio (perhaps even a ping to something on the Internet to ensure you have connectivity) or tasker will throw a error, basically stating it can’t do the HTTP Post as you aren’t connected to the Internet.
You should have two tasks assigned to the profile, the first will send the telegram command to tell openHAB you have arrived home, the other task is used for when you leave your WiFi and should change your status to OFF.
Also keep in mind you will need to disable any items that are configured for network pings or bluetooth detection as the only trigger should be tasker.
That should be all that is needed to start using this method to inform openHAB if you are home or away.