MQTT/OwnTrack Push Notifications

Now that I’ve gotten OwnTracks, MQTT and the GoogleMaps all working and playing together nicely. I was wondering if there is a way to push notifications to your phone when someone leaves or arrives someplace.

Ie, It would be nice to get a message knowing when my son arrived and left at school each day, etc. Similarly, knowing when he arrived at home.

Yes, you can do this with rules and the SendMessage/SendBroadcastMessage functionality from the myopenhab binding. See the documentation with myopenhab.

Since you have your MQTT broker up and running, and if you are up for a challenge, I would recommend giving mqttwarn a try. It is a little python script written by myself and @jpmens (well mainly JP!) who is also the brains behind Owntracks.

The best approach IMO is to add a series of notification items in openHAB, bound to different MQTT topics.

String      VT_Notify_Trace                     { mqtt=">[mosquitto:/openhab/notification/trace:state:*:default]" }
String      VT_Notify_Info                      { mqtt=">[mosquitto:/openhab/notification/info:state:*:default]" }
String      VT_Notify_Alert                     { mqtt=">[mosquitto:/openhab/notification/alert:state:*:default]" }
String      VT_Notify_Warn                      { mqtt=">[mosquitto:/openhab/notification/warn:state:*:default]" }
String      VT_Notify_Alarm                     { mqtt=">[mosquitto:/openhab/notification/alarm:state:*:default]" }

String      VT_Notify_Ben                       { mqtt=">[mosquitto:/openhab/notification/ben:state:*:default]" }
String      VT_Notify_Renee                     { mqtt=">[mosquitto:/openhab/notification/renee:state:*:default]" }
String      VT_Notify_Kodi                      { mqtt=">[mosquitto:/openhab/notification/xbmc:state:*:default]" }

Then to send a notification in any of your rules it is a very simple case of;

VT_Notify_Info.postUpdate("Information message")
VT_Notify_Alarm.postUpdate("The burglar alarm has been tripped!!")

So far, nice and simple. The clever bit is inside mqttwarn. There is a very good README on the Github page but in essence you setup mqttwarn to subscribe to each of those notification topics and for each subscription define a set of targets.

The available targets are vast, and include things like SMTP, Pushover, Prowl, Twitter etc etc. You simply add/remove targets as required for each different notification level. This means you completely decouple your notifications from openHAB, meaning you don’t require all the different action bindings, and makes it very easy to change your notification delivery method, or add/remove a target destination - just update the mqttwarn config and everything just works.

This was a huge step forward in the maintainability of my rules and notifications in openHAB and has been running this way for well over a year now.

You can use mqttwarn for notifications direct from Owntracks (i.e. no need to involve openHAB at all). mqttwarn can subscribe to the Owntracks topics and be configured to send notifications out via any target, there are even some examples for doing exactly that in the README I think.

1 Like

This is fantastic info.

I’m experimenting now a little with myopenhab. But will definitely give mqttwarn a try later this week.