Home Presence Appdaemon App

Hey @Odianosen25 - can I suggest that you post a link to you work on Andrew’s thread, and in the AppDaemon section?

This deserves a wider audience!

2 Likes

@Odianosen25 Absolutely agree with @PianSom. Great work!

Hello Bro,

Thanks for the suggestion, and I will look at doing that. Honestly not sure how to approach it, but will post it in the thread now.

@andrewjfreyer, so glad to get your remarks on this :blush:. Nothing better than the creator acknowledging your work. Thanks.

Regards

1 Like

This is great. I had started something similar but have not had time to debug and finish!

Any reason you don’t choose mqtt device_tracker over binary sensor?

Thanks for the response @kylerw.

That’s a cool idea, but unfortunately one is limited to supported devices that can be discovered by HA over MQTT. The list can be found Here.

Regards

Thanks, didn’t realize it wasn’t available yet.

I’ve added a feature request: Add device_tracker to MQTT discovery

Thanks for putting in the feature request.

I will edit the app to make it optional for those that want to use device tracker for viewing in HA. It will just be simply Home or Away. So if in the apps.yaml file device_tracker is set to true, it will also send an mqtt message to a certain topic fed off the device name generated.

So in my example above, if I set device_tracker to True, it will send Home or Away to the topic presence/odianosens_iphone. It is up to the user, to set it all up in the configuration.yaml file.

It will mean extra work for the user (which is what I wanted to avoid), but I see the need for simple viewing on the GUI instead of presence type of sensor.

Regards

Any plans to host on github or similar for easy updates/enhancements or do you see this as your “final” version?

Hello @kylerw,

Good point. I have just uploaded it to github as a pull request to @andrewjfreyer main branch here. This should make it easier for others to spot, that might be interested in using the system.

It is not definitely the final version, as I have a major upgrade I need to do to it, based on using different devices based on priorities per device to determine if a person is home or not. As its normal for one to have different Bluetooth devices and I believe it will reduce the probability of being mistakenly set as home/away.

I plan on using some form of Bayesian algorithm for that, but honestly figuring out the best way to approach it when still making it so user friendly is being a herculean task. And I got other projects I am working on, so not having so much time for this.

On the device_tracker side of things, I looked into it and for now the binary_sensor I think works fine as I am using the presence one. In HA, it comes up and either Home or Away which is what we need anyway, as the system doesn’t work outside the home environment. So for now, I wouldn’t be implementing the device_tracker side of things, unless your feature request is supported.

Thanks and regards

@Odianosen25 - I’ve stuck the mqtt plugin in the plugins folder, but the app can’t find the plugin and throws

ModuleNotFoundError: No module named 'appdaemon.plugins.mqtt'

I am getting info in my log that the mqtt plugin seems to be running and is subscribed to #.

Any guidance?

How did you drop it in?

As you need to drop all 3 files within the folder mqtt.

Can I kindly see all the logs related to mqtt?

Regards

@Odianosen25

I created the files in my config directory (using docker) and the cp to the plugins folder

image

2018-09-01 14:53:04.602541 WARNING AppDaemon: ------------------------------------------------------------
2018-09-01 14:53:04.603116 WARNING AppDaemon: Unexpected error loading module: /conf/apps/home_presence/home_presence.py:
2018-09-01 14:53:04.603592 WARNING AppDaemon: ------------------------------------------------------------
2018-09-01 14:53:04.606549 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 2015, in check_app_updates
    self.read_app(mod["name"], mod["reload"])
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1802, in read_app
    self.modules[module_name] = importlib.import_module(module_name)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/conf/apps/home_presence/home_presence.py", line 1, in <module>
    import appdaemon.plugins.mqtt.mqttapi as mqtt
ModuleNotFoundError: No module named 'appdaemon.plugins.mqtt'

2018-09-01 14:53:04.607083 WARNING AppDaemon: ------------------------------------------------------------

2018-09-01 14:53:01.849620 INFO AppDaemon: MQTT: Connected to Broker at URL 192.168.1.188:1883
2018-09-01 14:53:01.850990 INFO AppDaemon: MQTT: Subscribing to Topic: #
2018-09-01 14:53:01.853466 INFO AppDaemon: MQTT: Subscription to Topic # Sucessful
2018-09-01 14:53:01.854961 INFO AppDaemon: MQTT: Subscribing to Topic: location/#
2018-09-01 14:53:01.855669 INFO AppDaemon: MQTT: Subscription to Topic location/# Sucessful
2018-09-01 14:53:01.857508 INFO AppDaemon: MQTT: *** Sending Complete State: {'mqtt.none': {'state': 'None', 'attributes': {}}} ***
2018-09-01 14:53:01.858134 INFO AppDaemon: Got initial state from namespace mqtt
2018-09-01 14:53:01.858715 INFO AppDaemon: MQTT: MQTT Plugin initialization complete
2018-09-01 14:53:01.937995 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/Basement Bedroom Window Sensor/contact, Payload = b'closed'
2018-09-01 14:53:01.939375 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/Basement Bedroom Window Sensor/battery, Payload = b'93'
2018-09-01 14:53:01.940680 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/Office Window Sensor/contact, Payload = b'closed'
2018-09-01 14:53:01.955182 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/Office Window Sensor/battery, Payload = b'89'
2018-09-01 14:53:01.955428 INFO AppDaemon: Got initial state from namespace default
2018-09-01 14:53:01.956685 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/TV Room Window Sensor/contact, Payload = b'closed'
2018-09-01 14:53:01.959027 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/TV Room Window Sensor/battery, Payload = b'92'
2018-09-01 14:53:01.959830 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/Toy Room Window Sensor/contact, Payload = b'closed'
2018-09-01 14:53:01.960667 INFO AppDaemon: MQTT: Message Received: Topic = smartthings/Toy Room Window Sensor/battery, Payload = b'81'

1 Like

Apologies for the late response, but the files shouldn’t be in the config directory but in the python site-packages library directory (at least I think that’s what its called). Now if you using docker, that could be an issue as I don’t know how you can access it. I use pip3 install and I have it in /usr/local/lib/python3.5/dist-packages/appdaemon/plugins.

When I considered using docker and since there is an issue now with custom_plugins folder, I had asked the docker developer to allow for access to the site-packages plugins folder, which I don’t think he has done yet. Without access to that one, for now it will be difficult to use to plugin in docker.

Though I think a few ppl have gotten around this via the use of docker compose to like create another image, out of the original or something. But I know not how to do this I am afriad.

Regards

Hmmm… That’s essentially where mine is at - I created in the config folder but copied to the appdaemon/plugins folder manually.

So you confirming the mqtt plugin folder is in /usr/local/lib/python3.6/site-packages/appdaemon/plugins/? As the picture you gave showed /usr/scr/app/appdaemon/plugins/mqtt

Regards

The docker container installed appdeamom into /use/src/app

Which is basically a pointer to the path you use/reference…

Hmm, maybe not. Let me dig a bit into this.

@Odianosen25 so that did it.

No an error with app_config ["settings"] do you have that app/config you can share?

Hello @kylerw, oh glad you fixed it, can you kindly let me in how you did, as I would like to know in the event I want to use docker.

Well app_config['settings'] is just a way I store all my configurations for my system. I have a separate app (Yaml file really), where I have all my home settings in. So I access a single database for everything appdaemon stores.

What is needed is just a directory to a database it can use. In your case you could try /usr/src/app/database. I will edit the app, so it creates the database locally within where the app file is stored.

Regards

@kylerw,

I have edited the app so it will store the database local to the app’s directory. So no need to worry about the app_config['settings'] side of things