Home (Monitor) Presence App V2

Hello,

Been over 18 months since I released the first Monitor App I wrote, to assist with the integration of the great Monitor Script by @andrewjfreyer, and this is an update to it. This new version brings some upgrade to the previous one, thanks to the work by @shbatm and @TheStigh. It is hoped that with this upgrade, you should be able to install your monitor system and forget about it (literally). As the app now should be able to assist in making your system more reliable, by even rebooting the nodes if for example the script was to go offline but the hardware still on the network; all options are configurable of course, for those that fear security vulnaribilities :wink: . To access the app and read its full features, kindly access it via this repository. A summary of a few of its new features are outlined below:

  • Integration via HACS
  • Ability to auto reboot the the nodes on the network. Either via MQTT (if wanting to do it from HA), service call or via a pre-configured scheduler
  • Added service calls, that can be called from other AD apps
  • If wanting to use device_trackers , it is possible to config the app to use device_tracker instead of binary_sensors for each device. The app will update the state as required; that is use home / not_home instead of on / off . - contributed by shbatm
  • The name of the sensors for everyone_home , everyone_not_home and someone_is_home can be modified to use other names as required. - contributed by shbatm
  • Added install script, which can assist in installing both AD and the App or upgrading the App, for non-Hass.io users. - contributed by TheStigh
  • Publishing of the entire monitor system’s state over MQTT using monitor/state. This can be used to create sensors in HA like telling when its scanning and how many nodes on the network
  • Publishing of per node’s state over MQTT eg monitor/<location>/state. This can be used to create sensors in HA, like telling if online/offline and when it was last_rebooted
  • The binary_sensors created per device now has a nearest_monitor attribute, which shows the devices closest node. - contributed by shbatm
  • Other improvements to the app’s over all performance.

In addition to the above, unfortunately there are some breaking changes, from the previous version to take note of:

  • Confidence sensors have been renamed from sensor.<device name>_<location> to sensor.monitor_<device name>_<location>_conf
  • The binary_sensors for presence have been renamed from binary_sensor.<device name>_home_state to binary_sensor.monitor_<device name>
  • The default MQTT event listened by the app is MQTT_MESSAGE from MQTT

Hope you enjoy the new upgrades, and await your feedbacks from those that have been using it. Those new to it, hope you enjoy the app, and the simplicity it brings to your monitor installation.

11 Likes

I just saw this post. Went back and read some of the previous posts.
Can you explain to me once it is installed in HACS what I do.
I do not understand what to do or where to place the app config.
Thank you.
carltonb

Hello @carltonb,

Thanks for your interest in the app. Honestly I don’t use HACS, but you can read more about it here. It was just added to the HACS default repository, so will should be available in about a few hours. The other option is just to download the repository and move the folder home_presence_app to your apps directory. AD will auto pick it up, and configure the home_presence_app.yaml as you want based on the docs.

Hope it helps? Regards

Thanks. I have it installed in HACS and the files seem to be there.

Question is where does the following get put.

# Monitors all events in INFO log level
events:
  module: event_monitor
  class: EventMonitor
  level: 'INFO'

Into what yaml file?
Thank you

1 Like

Actually that is not my my app, as file should look like this. I didn’t expect it to be avialable so quick really.

Do let me know when its available.

regards

Hi, thanks for the great work!

I’m running this new version and so far its better than the old standalone version. Two questions:

  1. I’m running Appdaemon in a docker and I’d like the reboot monitor functionality to work. The instructions mention the need to install requirements.txt for Appdaemon. However, since I’m running the docker container, any installation will be lost when that container is created. Any suggestions on how to make it work with AppDaemon in a docker container? My HA Core is also running in docker on a Ubuntu base VM.

  2. I noticed that when I restart HA with AppDaemon still running. The Monitor entities are not re-created in the restarted HA instance. From what I can infer, this means that the entities are only created in HA by AppDaemon on AppDaemon start. Because once I restart AppDaemon the entities show up again. I’m not sure if this is expected behaviour, but if so, this is an issue because I often restart my HA without restarting AppDaemon and would then lose those Monitor entities. Or is there a way to remote restart AppDaemon from HA as part of an automation/script?

Edit: One more question…
Trying to install the new version with your installation script. I previously have the old Monitor installed, don’t think that is an issue. In any case, when I run the script and choose the install standalone Monitor or update standalone Monitor option, I get the following error:

bash: $'\r': command not found
bash: line 3: cd: $'~\r': No such file or directory
bash: line 4: $'clear\r': command not found
bash: line 15: cd: $'~\r': No such file or directory
  Preparing update for Monitor-App, requires existing installation of AppDaemon 4.x
  where AppDaemon configuration files are installed to default folder. The script
  will check this and stop the installation if not.

  Assuming path to /conf folder: /home/appdaemon/.appdaemon/conf

bash: line 22: $'\r': command not found
bash: line 23: $'\r': command not found
bash: -c: line 120: syntax error: unexpected end of file

Thanks!

This looks really great! Sorry if this is a noobie question but - can this be used with an ESP32 via ESPHome, or am I better off just getting a USB bluetooth module for the NUC running my hass.io instance?

@emteedubs,

Thanks for using my app.

On point 1 if using docker, just start the docker container and as long as you have the requirements.txt file in the app folder, it will install it at startup. Only issue is, it will have to install each time the docker starts up. To make it permanent, you have to build your own docker image.

On point 2, when HA is restarted, the App definitely rebuilds the entities in HA; this I personally use as my HA restarts quite a bit compared to AD. I am not sure what might be happening, but when you restart HA, give a minute (depending on how many users you got), for them all to show up.

As for the script, that will be @TheStigh to assist with as he developed it. Hopefully when he is online, can answer the question. But I don’t think the script had been designed to replace an old installation, so might need an upgrade.

Regards

Helo @EthanG,

Unfortunately it can’t be used with ESPHome, as I don’t even know how that of the ESPHome functions. But as the App needs an already installed and running Monitor system to function, you will need to have that running somewhere first. So yes putting a USB dongle on your NUC, might be your best friend :wink: .

Regards

Hi @emteedubs

Unfortunately the scripts does not support docker (yet).

You cannot update the older version of Monitor-App (version 1.x) using the script. But I do not understand the error output you are showing me - I’m currently on travel but are back home tomorrow and will look into it (sorry for the delay).

From where do you run the script, hardware, OS and user?

No worries. No rush. In the meantime I’m running off the install with the old method.

For reference I tried running the script on a Raspberry Pi 4b and Pi Zero W both running Buster with latest updates.

And thanks for the reply Odianosen25. I will try your suggestion on Docker and also try to see if the restart works again.

Thats really weird, it was made on a RPi4 with latest Buster. Though, I will go over the scripts first thing tomorrow when I’m back from my travel :slight_smile:

Not sure if you had a chance to try, but still getting that error when running the install script. For reference, I’m trying the Install Monitor Standalone option. Seems like it’s still checking for AD installation and maybe that’s why the script is failing?

Hi, yes it is checking for the configuration folder of appdaemon, if it’s not in a particular location, the installation script fails.

  • How did you install AD?
  • What is the path for your AD configuration files ?

I will come with a completely new install script for both AD and monitor just over the weekend, the script will be a lot smarter.

Hi, im actually using monitor on a rasp W, so I would love to have this integration. I already install AD by the add-on store but I cant find the monitor-app on HACS. Do I need to add a repo? I already update/refresh/reboot
Can anyone tell me the exact name of the app to search in HACS

Thanks all

So my AD is installed as a Docker container on a separate Intel NUC where my Home Assistant is also installed.

The AD path is in the subdirectory of my home assistant path on the NUC. So there is no AD installed on my Pis, only monitor. Which is how it’s currently run via manual install of Monitor.

So that’s probably where the failure is happening because I don’t have AD installed on the devices I’m trying to install standalone monitor. May I ask why it still checks for AD under that option?

Looking forward to the new script and thanks for all the hard work!

It’s called “Monitor-App” under the “AppDaemon” section in HACS. Don’t think you need to add seperate repo.

Ah, you’re trying to install Monitor-App on a different hardware than where you run AppDaemon (AD)?
The script clearly states that it only works if you install AD as a standalone non-docker, perhaps it should be clearer that it doesn’t work if you have AD as docker (note-to-self: make better description).

You will need to install Monitor-App on the same physical device you run AD as the app depends on AD to run. If you install Monitor-App from HA itself, you don’t need the script.

To be clear, there are some ways to install both AD and AD apps;

  1. Install AD as an addon in HA, then you can easily add AD apps from HACS
  2. Install AD outside HA on same or different hardware
    a) Install AD as docker
    b) Install AD standalone (here you can use the install script)

If option 2, you need to install AD apps manually, they can’t be installed through HACS (@Odianosen25, correct me if I’m wrong).

The new script will be for option 2 only and it will support docker installations also.

1 Like

Yes that’s right. HACS only available via Hass.io

Hi, i erased my previous post because I came here to quickly to ask for help. But now I’m really stuck. I configure everything and the appdaemon is connected to the raspW with monitor. I’m lost in the settings of the app regarding the mqtt_event and mqtt_topic. The rasp is publishing on the topic w
image

The setting of home_presence_app.yaml

home_presence_app:
  module: home_presence_app
  class: HomePresenceApp
  plugin: 
    - HASS
    - MQTT
  monitor_topic: monitor
  mqtt_event: MQTT
  #user_device_domain: device_tracker

  depart_check_time: 30
  minimum_confidence: 60
  not_home_timeout: 15
  system_check: 30
  system_timeout: 60
  home_gateway_sensors:
    - binary_sensor.puerta
    
  home_motion_sensors:
    - binary_sensor.movimiento
  
  known_beacons:
    - E5:XXXXXXXXXX A band
    - F5:XXXXXXXXXX B band

In the server its looking good

Should i see here the xiaomi band published by monitor?

But I have this error in the log when starting appdaemon 4 addon

2020-03-06 16:02:06.720331 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/Monitor-App/home_presence_app.py
2020-03-06 16:02:06.736650 INFO AppDaemon: Initializing app home_presence_app using class HomePresenceApp from module home_presence_app
2020-03-06 16:02:06.760049 WARNING home_presence_app: home_presence_app: Entity monitor.monitor_state not found in namespace w
2020-03-06 16:02:06.762833 INFO AppDaemon: home_presence_app: Entity monitor.monitor_state created in namespace: w
2020-03-06 16:02:07.184030 INFO AppDaemon: App initialization complete
2020-03-06 16:02:07.196795 WARNING home_presence_app: ------------------------------------------------------------
2020-03-06 16:02:07.198696 WARNING home_presence_app: Unexpected error in worker for App home_presence_app:
2020-03-06 16:02:07.200805 WARNING home_presence_app: Worker Ags: {'id': 'e7ec75d947bc4f55aa2295cd1efe02ae', 'name': 'home_presence_app', 'objectid': '6fc248cc99d74085a251dd6cee4b248e', 'type': 'scheduler', 'function': <bound method HomePresenceApp.load_known_devices of <home_presence_app.HomePresenceApp object at 0x754ad3d0>>, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'__thread_id': 'thread-0'}}
2020-03-06 16:02:07.202710 WARNING home_presence_app: ------------------------------------------------------------
2020-03-06 16:02:07.208352 WARNING home_presence_app: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 766, in worker
    funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"]))
  File "/config/appdaemon/apps/Monitor-App/home_presence_app.py", line 1105, in load_known_devices
    for device in self.args["known_devices"]:
KeyError: 'known_devices'

Hope the information is usefully for help!

Thanks