This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.

Setup Homey with MQTT for location detection

1567810

Comments

  • Ergens in je app zit een typo, want ik zie dit in de logs:

    20170814-10:17:56 Received Fence = home trigger fenve = *
  • PimBliek said:
    Ergens in je app zit een typo, want ik zie dit in de logs:

    20170814-10:17:56 Received Fence = home trigger fenve = *
    Is aangepast in de 2.0.0 versie (herschreven voor Sdk2). Gaat binnenkort naar het bèta kanaal. 
  • Another great tool to use with Owntracks is ot-recorder: https://github.com/owntracks/recorder

  • I have installed Mosquitto on my Qnap and when I configure Owntracks on my android (Galaxy S8) it is working fine. But when I install Owntracks on another android device (Galaxy S5) it says that it is connected but I can't see this Galaxy S5 on my Galaxy S6. Do I need to configure anything to see the friends on the android devices?
  • Count_B said:
    I have installed Mosquitto on my Qnap and when I configure Owntracks on my android (Galaxy S8) it is working fine. But when I install Owntracks on another android device (Galaxy S5) it says that it is connected but I can't see this Galaxy S5 on my Galaxy S6. Do I need to configure anything to see the friends on the android devices?

    The way those owntracks phone apps work is that they publish location and transition messages on a topic. They are also subscribed to a topic. As soon as a phone publishes a message, all devices that are subscribed also receive that message. And as result display the location on a map. 

    When you can't see any friends, that means the phone did not receive any messages. Causes can be:
    1. No messages were published 
    2. The phone doesn't have the correct authorization on the topic (no read rights) 

    Did you use different users to login to the MQTT broker? So for each device a seperate user? If not, then please do so. 


  • PhuturistPhuturist Member
    edited August 2017
    @MennoVanGrinsven

    I just started experimenting with MQTT and Owntracks since my Smart Presence stopped working properly after updating my phone to Android 7.1.2. I run into the issue that the Homey apps crashes once I leave my home geolocation with the following stacktrace.

    TypeError: Cannot read property 'length' of undefined
    at setFence (/global.js:292:30)
    at Object.setFence (/global.js:33:7)
    at receiveMessage (/messagehandling.js:56:26)
    at Object.receiveMessage (/messagehandling.js:8:7)
    at MqttClient.<anonymous> (/broker.js:91:27)
    at emitThree (events.js:135:13)
    at MqttClient.emit (events.js:216:7)
    at MqttClient._handlePublish (/node_modules/mqtt/node_modules/mqtt/lib/client.js:819:12)
    at MqttClient._handlePacket (/node_modules/mqtt/node_modules/mqtt/lib/client.js:286:12)
    at process (/node_modules/mqtt/node_modules/mqtt/lib/client.js:242:12)

    Exit code: 1
    Exit signal: null
    I have added the home geoloaction in the Owntracks smartphone app and manually added this location with the same name in the settings page of the Homey Owntracks app. Is that how it is supposed to be setup up, and if so, any idea why the app crashes?

    Here is some of the Homey app loging.
    20170816-12:05:59 Registered topics:
    20170816-12:05:59 Retreiving userArray failed: Error: ENOENT: no such file or directory, open '/userdata/owntracks.json'
    20170816-12:05:59 Retreiving fenceArray failed: Error: ENOENT: no such file or directory, open '/userdata/owntracks_fences.json'
    20170816-12:06:00 Trigger Arguments for enterGeofence: owntracks/mosquitto/Jelger/event
    20170816-12:06:00 Registered topics:owntracks/mosquitto/Jelger/event
    20170816-12:06:00 connectedClient == null
    20170816-12:06:00 Broker URL: mqtt://192.168.0.110:1883
    20170816-12:06:00 rejectUnauthorized: true
    20170816-12:06:01 Subscribed to owntracks/#
    20170816-12:06:01 createAutocompleteActions called
    20170816-12:06:01 listenForMessage called
    20170816-12:06:01 createAutocompleteActions called
    20170816-12:06:01 registerConditions called
    20170816-12:06:01 MQTT client connected
    20170816-12:06:01 Connected Topics: owntracks/mosquitto/Jelger/event,owntracks/#
    20170816-12:06:01 reconnectedClient false
    20170816-12:06:01 OnMessage called
    20170816-12:06:01 received '{"_type":"location","tid":"JH","acc":1544,"batt":0,"lat":5x.24xx8039,"lon":x.513xx841,"t":"c","tst":1502877923}' on 'owntracks/mosquitto/Jelger'
    20170816-12:06:01 We have received a location message
    20170816-12:06:01 Set battery percentage for mosquitto to 0%
    20170816-12:06:38 getLogLines called
  • @Phuturist
    For the app crash there is already a new version pending approval. 
    I see that you are using the topic based triggercards. Please use the trigger cards based on username / fence name. The topic based trigger cards will be removed in th Sdk2 version of the app.

    Secondly use your name as username to login to mosquitto. You are using mosquitto as username now. 

    When creating a  region / Geofence in the owntracks phone app, enable share. If share is not enabled, the name of the fence is not included in the location messages. If you enabled share, the created fence is automatically added to owntracks and you get a notification in homey. Don't forget to provide a radius in the phone app. Otherwise it's not a Geofence. 

    In the trigger cards you can use the autocomplete fields to select user and known fences. 

    Since you are using MQTT, usernames are automatically added. When using HTTP you have to add a new user manually (for security reasons ofc.) 
  • @Phuturist
    For the app crash there is already a new version pending approval. 
    I see that you are using the topic based triggercards. Please use the trigger cards based on username / fence name. The topic based trigger cards will be removed in th Sdk2 version of the app.

    Secondly use your name as username to login to mosquitto. You are using mosquitto as username now. 

    When creating a  region / Geofence in the owntracks phone app, enable share. If share is not enabled, the name of the fence is not included in the location messages. If you enabled share, the created fence is automatically added to owntracks and you get a notification in homey. Don't forget to provide a radius in the phone app. Otherwise it's not a Geofence. 

    In the trigger cards you can use the autocomplete fields to select user and known fences. 

    Since you are using MQTT, usernames are automatically added. When using HTTP you have to add a new user manually (for security reasons ofc.) 
    Thanx for the response.

    I only have one test flow but I'll start using the username/fence cards when I'm satisfied with how it works and while replacing my Smart Presence flows. I'll await the new version that fixes the app crash before continuing to test it.

    I use mosquitto as username as this is the system user under which Mosquitto has been installed on my Synology NAS. What other user could I use for this, it seems to work now? And something else, does the Homey Owntracks app support websockets, I could not get this to work after configuring Mosquitto with websockets.

    I have enabled sharing of my geolocations and that does indeed add them automatically to the Homey app, thanx.

    Let's hope Athom approves the app soon, it looks promising so thanx for the app.


  • edited August 2017
    @phuturist do you use the beta version or the stable version? 
    You don't have to use MQTT anymore. You can use plain https through the athom cloud. 

    Or use your own web server as proxy (for https).
  • PhuturistPhuturist Member
    edited August 2017
    @phuturist do you use the beta version or the stable version? 
    You don't have to use MQTT anymore. You can use plain https through the athom cloud. 

    Or use your own web server as proxy (for https).
    I just moved to the beta channel of the app and I'm now using 1.5.4. I'm have set up  MQTT because in the readme of the app it was mentioned this was the most secure solution and it was the only option completely documented (in the opening post by Ingmar). It was actually quite easy to set up and it works now.

    I'll have a look at the HTTPS option (a suggestion, add the tutorial from a page back to the app readme or openingspost, I had not found it at first). It indeed seems easy but I like to be independent of 3rd party cloud services so I'll probably stick with my own MQTT server.
  • @phuturist @ingmar is the only one that can change the first post. But indeed MQTT is the most secure solution. 

    Only problem is that the username that you login with is used by the owntracks app as user and as such also in the homey app. So multiple users will prove to be difficult. As I don't know the Synology implementation of MQTT, I can't say how to change that. Ideal would be to create a user for homey, and for each person that is in the house. 


  • Normally you would add a user with https://mosquitto.org/man/mosquitto_passwd-1.html

    And create authorization to the topics
  • PhuturistPhuturist Member
    edited August 2017
    Normally you would add a user with https://mosquitto.org/man/mosquitto_passwd-1.html

    And create authorization to the topics
    Ok, the server was configured by default to allow anonymous access. Appearantly that still seemed to work with your app but I just disabled this and added a Homey user for the Owntracks app and users for every person in the house. Everything seems to work at the network level, I can see the messages being received by the Owntracks Homey app but for some reason the flows are not triggered. Below is a message that is received. Do you see anything strange here?

    20170816-22:31:09 changedSettings called
    20170816-22:31:09 [object Object]
    20170816-22:31:09 topics:
    20170816-22:31:09 topics:
    20170816-22:31:09 Registered topics:
    20170816-22:31:10 Registered topics:
    20170816-22:31:10 connectedClient == null
    20170816-22:31:10 Broker URL: mqtt://192.168.0.110:1883
    20170816-22:31:10 rejectUnauthorized: true
    20170816-22:31:10 Subscribed to owntracks/#
    20170816-22:31:10 MQTT client connected
    20170816-22:31:10 Connected Topics: owntracks/#
    20170816-22:31:10 reconnectedClient true
    20170816-22:31:10 OnMessage called
    20170816-22:31:10 received '{"_type":"location","tid":"JH","acc":1741,"batt":17,"conn":"w","lat":x3.28xx932,"lon":x.53xx253,"t":"u","tst":1502xxx85}' on 'owntracks/Jelger/Jelger'
    20170816-22:31:10 We have received a location message
    20170816-22:31:10 Set battery percentage for Jelger to 17%




  • edited August 2017
    @Phuturist The flows will only be triggered when there is a transition event (i.e. you enter or leave a geofence). Such messages have "_type":"transition"  and will include the field "desc":"<geofencename>" 

    I would suggest to make a flow that will trigger on every event, something like:



    and let it run for a while and see if you get those messages.

    You really need to go out the house to get it to work. Make sure you leave the Share  option in geofence on your phone enabled, otherwise those events cant be processed by the homey app.

    If you want to test, you can always install something like MQTTLens in chrome and send test messages to see if the flow triggers .
    test.png 454.7K
  • PhuturistPhuturist Member
    edited August 2017
    @Phuturist The flows will only be triggered when there is a transition event (i.e. you enter or leave a geofence). Such messages have "_type":"transition"  and will include the field "desc":"<geofencename>" 

    I would suggest to make a flow that will trigger on every event, something like:



    and let it run for a while and see if you get those messages.

    You really need to go out the house to get it to work. Make sure you leave the Share  option in geofence on your phone enabled, otherwise those events cant be processed by the homey app.

    If you want to test, you can always install something like MQTTLens in chrome and send test messages to see if the flow triggers .
    Yeah, was messing with MQTTlens and a test flow similar like that but the flow has not triggered yet even though I see somthing like this in the logs.
    20170816-22:53:24 Fence: Thuis changed
    20170816-22:53:24 Trigger generic card for Thuis
     But I'll leave it be an see what happens when I go to work tomorrow. Thanx for all the help.
  • @phuturist @ingmar is the only one that can change the first post. But indeed MQTT is the most secure solution. 

    Only problem is that the username that you login with is used by the owntracks app as user and as such also in the homey app. So multiple users will prove to be difficult. As I don't know the Synology implementation of MQTT, I can't say how to change that. Ideal would be to create a user for homey, and for each person that is in the house. 



    @MennoVanGrinsven , just let me know what you want to be changed to the 1st post and I'll look into it. Or make an update instruction and I will link to it from the 1st post.
  • @ingmar I really need to find time to write stuff down about all this. 
  • @ingmar I really need to find time to write stuff down about all this. 

    Sounds familiar ;-)
  • kooskortekaaskooskortekaas Member
    edited March 2018
    I tried the settings in the first page, but the Owntracks app status didn’t connect.

    I get the status: 

    idle The operation couldn’t be completed. Connection refused {

        "_kCFStreamErrorCodeKey" = 61;

        "_kCFStreamErrorDomainKey" = 1;


    Resolved!  :D

  • exiofexiof Member
    Instead of the nightmare with wife + 3 kids i ended up using "native" logic instead of Better Logic since Native tags supports variables in tag names

    Tags i use
    <username>_home (Boolean)
    home_somebody (Boolean)
    home_update (Number)

    OT Enter Home
    This is fired everytime a user comes home and it creates the Boolean Tags with <username>_home and sets the value



    OT Leave Home
    When a user leaves a Geofence it sets the boolean tag to false and fires update all flow to check if house is empty


    OT Update All
    Checks all users if they are home if all is out it sets someone_home to false this is the only flow you have to update to check if house is empty


    This is way easier to manage than the tutorial in this document - thread - since it only relies on a minimum of flows and they are not "user" specific

    Of course the Send Push is not needed its only for testing - so you can remote that
  • pim555pim555 Member
    Thanks for the nice article! 

    I managed to set-up a private MQTT broker running on a RPI3 with dedicated users (homey and family members) and user/pass authentication for each of them. Presence detection is working well.

    Would like to enable TLS authentication/encryption and have tried to follow various articles found in the internet but have not been successfull so far.

    Does anyone have a set by step instruction for enabling TLS based security?
  • edited May 2018
    pim555 said:
    Thanks for the nice article! 

    I managed to set-up a private MQTT broker running on a RPI3 with dedicated users (homey and family members) and user/pass authentication for each of them. Presence detection is working well.

    Would like to enable TLS authentication/encryption and have tried to follow various articles found in the internet but have not been successfull so far.

    Does anyone have a set by step instruction for enabling TLS based security?

    If you would consider using the MQTT Broker for Homey combined with owntracks:
    https://forum.athom.com/discussion/4169/how-to-selfsigned-certificates-with-mqtt-broker-for-homey

    Otherwise checkout things like letsencrypt to automatically get SSL certificates. Then configure the broker to use the key and certificate. But perhaps i am kicking in open doors. 
  • Hi, 

    I must do something wrong, but I can't seem to get Homey to know where I am. 
    I've set up MQTT on my Synology, installed Owntracks on Homey and my iPhone. 
    The app on my phone says I am connected, the Homey client sees my user (Patrick) and my fence (Thuis). 
    But on the tab "Huidige gegevens" I see User: Patrick, Fence: 'empty' 

    What am I doing wrong? Any settings I need to share for more info? 

    Thanks in advance!
    Patrick
  • When I left home today, I did get a notification, even though I thought it wasn’t setup right. Sorry for my previous message, it seems to work right. 
  • When I left home today, I did get a notification, even though I thought it wasn’t setup right. Sorry for my previous message, it seems to work right. 


    Owntracks works based on events. You either enter or leave a fence. If you create a fence and not enterer or left it yet, the status will be unknown until a leave or enter message is received for that fence. 
  • Yeah, it seems to work like a charm! Very nice solution compared to the standard location feature of Homey. 
    Hoping this keeps working like it does, thanks a lot for this work! 
  • I do have another question (or rather a feature request): 
    Currently it is possible to have a trigger when a battery is low, but this is not an option in the 'and' column. 
    I would really like that, since I would like to use the following flow: 
    When #user enters 'Home' AND #percentage is under 25% THEN send push notification. 

    Also, I would like to have more options in the AND column regarding who is home. Now the only options are: someone present in geofence and someone nog present in geofence. 
  • pim555pim555 Member
    @MennoVanGrinsven thanks for the reply. Was not aware of the MQTT broker for Homey but given the limitations around running many apps in Homey I prefer to keep on using my private MQTT broker.

    So I guess I am down to generate my self-signed certificates. Any step-by-step guidelines are appreciated. I have tried to generate those using a script from the owntracks repo
    https://github.com/owntracks/tools/blob/master/TLS/generate-CA.sh

    but cant get it to work...

    Other Q

    My owntracks app seems to publish old fences even after I delete them and create others. Any idea how to get rid of this?

  • Is it possible to use two users with OwnTrack but not see each other in the app? 
    Right now my girlfriend and I always know where the other is... 
  • edited June 2018
    Is it possible to use two users with OwnTrack but not see each other in the app? 
    Right now my girlfriend and I always know where the other is... 

    Depends on what you are using as a MQTT broker.
    If you are not using the MQTT broker app for Homey (that one does not have ACL implemented), you could deny your girlfriend and yourself  read access on the topic.

    Your phones are subscribed to the owntracks topic and what a MQTT broker implements is a Publish/Subscribe mechanism. So your phones sends a message, and that messages is send to all devices that are subscribed to the topic.
Sign In or Register to comment.