Open skjdghsdjgsdj opened 6 days ago
I think you've got a very good understanding of how OwnTracks and its components work, so congratulations!
Doing this all with HTTP is not easy. For instance the way Recorder handles Friends is a kludge and confusing to set up. To be honest some of us are sad we actually implemented HTTP.
Anyhow, that said, since you run the Recorder, what you might want to do is to use Lua hooks which which you can trigger something to happen (e.g. fire off a shell script, etc.) on an event. There are some example scattered about the documentation and in the Recorder's contrib/
directory.
The three solutions you mention basically aren't. Lua hooks are the way to go if you keep with HTTP.
(In MQTT it all becomes much easier: the broker gets a message (e.g. an enter
event), sends that to any number of subscribers which can do anything they want with the message. This might be inspiration.)
I assume it's not possible for the recorder itself to forward all events to an MQTT broker, but instead all clients must publish their events to the broker directly? I'm hoping to avoid opening another port to the outside world.
That is, without using Lua but just native functionality.
After going down the rabbit hole, I too gave up and switched to MQTT, despite my insistence that HTTP could work. But I at least secured it by:
certbot
and an actual Let's Encrypt DNS-challenged auto-renewing SSL certificateI switched my phone to the new MQTT endpoint from HTTP(S), which as warned erased my existing state and regions, but now I can see events flowing into Mosquitto and can later set up automations that listen to MQTT, as is its intended purpose.
Side note: the description for how to set up docker-compose.yml
didn't work. I had to set up environment variables as key-value pairs like this:
environment:
OTR_HOST: "a.b.c.d"
OTR_USER: "username"
OTR_PASS: "password"
This format didn't work as the recorder kept trying to connect to localhost:1833
instead of the host I defined:
environment:
- OTR_HOST = "a.b.c.d"
- OTR_USER = "username"
- OTR_PASS = "password"
assume it's not possible for the recorder itself to forward all events to an MQTT broker
That is correct: there's no provision for doing so without writing Lua hooks. This didn't seem a sensible thing at the time, and I think you are the first to request such a feature which, I'm sorry to say, we're not going to implement.
MQTT remains our preferred protocol.
I think I'm fundamentally confused about OwnTracks' architecture.
I have the recorder installed and running via Docker and a
docker-compose.yml
. My phone is pointing to the server and is successfully sending location events, and when I go to the web UI for the recorder, I see my phone's location. On my phone, I defined some regions (geofences) and my phone correctly notifies me as I enter and leave them.I configured the server to only listen to HTTP events, not MQTT. This is because I'm proxying it through Caddy and exposing it publicly via HTTPS.
What I don't understand is: how can I have the server do something when a region is entered or exited? Or generically: I see how to publish events, but how can I subscribe to them? I have use cases around home automation, so I want to configure OwnTracks to do something when I get home and something else when I leave.
I figure one of several solutions is applicable, but I don't understand how to implement them:
Thanks.