Home (Monitor) Presence App V2

Ah thanks for this @servido, I never envisaged some might use it for beacons only. But are the bands not regular Bluetooth devices? If they are, so use “known_devices” and not “known_beacons”. If not, well I got to make a quick change to the app. As I said earlier, never thought I’d users using it for beacons only.

Thanks for the quick reply. The I’m using two xiaomi mi band 3 and they are beacons, I’m not tracking phones.

Will be waiting for the change!
If you need more info just ask

Ok no worries @servido considering it’s a serious issue, will do a release this evening. Just update within the next hour or so.

On another note, I have no beacons so not sure how robust it works. So if anything, just update me and I will make any amendments to help improve on it.

Regards

Just update and now and I cant make it work. Always invalid

2020-03-06 18:25:37.476399 WARNING AppDaemon: File '/config/appdaemon/apps/apps.yaml' invalid structure - ignoring
2020-03-06 18:25:37.508067 INFO AppDaemon: /config/appdaemon/apps/Monitor-App/home_presence_app.yaml added or modified
2020-03-06 18:25:37.509976 INFO AppDaemon: Found 1 total apps

Just to double check, the apps.yaml is blank and the app is in home_presence_app.yaml
image

And with this structure the home_presence_app.yaml was replace by the example when updated

What else can i do?

To make this work at the end I erase home_presence_app.yaml and add the home_presence_app in the apps.yaml Was the only way
Now its working and I’m undestanding more and more, so will check how it goes with the beacons and come back with some feedback

Thanks! Great app

Thanks for making such a wonderful app! I managed to get it all up and working properly (i think) and I wanted to post this to be sure that I’m using this to it’s full potential. This is my first time using AppDaemon, and I only got Monitor up and running a day before finding this project (so still new). I love that I am able to configure (virtually) everything from apps.yaml. The readme doesn’t have the usual flow of install steps then configure then done format, which is probably why I’m only partly sure that I have it set up correctly. I also have done some initial testing and have found that arrival to be a bit slow. Departure is quite slow and that isn’t an issue at all since the only trigger points I have are my doors and I usually do spend some time in the drive way in range of my main pi zero before leaving. Perhaps I can make a change based on your feedback.

My setup is I’m running hassio (now home assistant) and so I installed the AppDaemon addon and then Monitor-App via HACS. I’m running 3 pi zeros. My main one in the front of the house is running with the flags “-tdr -a -b” as suggested. (Though I may remove the -b as I don’t think I’ll add beacons) and the pi zeros at the back of the house and the garage are running flags “-tad -a -b” again as suggested. The code I have in apps.yaml is the following.

home_presence_app:
  module: home_presence_app
  class: HomePresenceApp
  plugin: 
    - HASS
    - MQTT
  depart_check_time: 240
  home_gateway_sensors:
    - binary_sensor.front_door_status
    - binary_sensor.side_door_status
  scheduled_restart: 
    time: "00:00:01"
    days:
      - wed
      - sat
  known_devices:
    - XX:XX:XX:XX:XX:XX my-phone #My Pixel
    - XX:XX:XX:XX:XX:XX wife-phone #Wife's One Plus
    - XX:XX:XX:XX:XX:XX mom-phone #Mom's Galaxy8
  home_motion_sensors:
    - binary_sensor.bathroom_occupancy_occupancy
    - binary_sensor.dining_room_occupancy_occupancy
    - binary_sensor.bedroom_motion
    - binary_sensor.laundry_room_occupancy
    - binary_sensor.kitchen_occupancy_occupancy
    - binary_sensor.livingroom_occupancy_occupancy

Some changes I made are the depart check, again, it usually takes a while to get out of the driveway, especially if my wife is putting my daughter in the car seat. I’m not quite sure what the motion sensors are doing for me. I read that it’s for help with room detection. I don’t care about that. I thought it might have something to do with checking if the house is empty for a depart scan? Maybe I’m wrong and I don’t need it.

Did I get this right? Is there something anyone might recommend I change to speed up arrival? Thanks again!

Hello @thefarelkid,

Thanks for the compliment. I do understand what you are saying, and first you right in increasing the depart_check_time, but since you still in the drive way can be an issue. If you are not interested in the nearest_monitor stuff, might be better to remove the motion sensors. As how it works is it scans for rssi, if the app had ran the depart scan and said you have departed, and it still senses you have an rssi, it will run arrival again.

The app does have an internal scan counter, that ensures the depart scan runs 3 times. It is exposed but “hidden”, that one can be set by the user as its configurable using depart_scans; I will edit the docs to add this. This will ensure that when running depart scans, it runs it multiple times before stopping. This can really help with your issue. Add the depart_scans to the app config, and see if it helps your case.

For the arrival, well if you are in the drive way, technically you not in the home so it can’t record you as being in the home :wink: . But anyway if you want to be sensed when on the drive way and your node can sense you when on the drive way, I will advise you to add an outdoor camera which watches the drive way and it runs an motion/object detection. You can then add the sensor from the camera as part of the home_gateway_sensors, so when it sees a car or person, it runs the scan.

On maximising the app, well you can check via all the options as it well depends on your use case.

Hope it helps?

Thanks for you reply @Odianosen25,

After posting my comment I realized that departure and arrival scans are both triggered with the gateway sensors. I think that I will either add my camera motion or object detection (If I can manage to get that reliable) as a trigger, or I’ll just add maybe a 3 second delay between the door opening on away mode and sending an alert to my phone. Monitor seems to pick up my phone FAST on the gateway sensor. The whole idea is to not have to open my phone up and turn off away mode before entering the house.

I’ll keep doing some playing around with the departure scans. But I think the real “maximizing” thing for me is to find the right gateway to make arrival scans solid.

Thanks! This app sure beats having to add several sensors and automations. I finally have presence detection! Only took me 2 years!

@Odianosen25 I’m having problems with the xiaomi mi band 3 beacons. Standing in the same place, suddenly the confidence drops to 0 and then jump to 100.
I arrived at 2:00pm to my home and I have been sited in the computer until now (like 2 meters away), and it keep changing from 0 to 100 on confidence
image

Is there a way to add like a recheck on the away status? Like:

  • Monitor check and now confidence goes to 0, can it wait 10 seconds and do a recheck to confirm that confidence is 0 and then change to the away status?

Thanks for the great app and the help

You welcome :slight_smile:

@servido,

Hmmm it does that, just noticed for some reasons when its a beacon I disabled an extra check and can’t for some reasons remember why I did that :thinking: as been a while I wrote that section of the code.

I could enable it regardless and see if anything breaks. Got no beacons to test now now.Pleas report in Git so i remember to look into it.

Regards

1 Like

What kind of settings should be set in the behavior-preferences on the pi that runs Monitor? I keep getting false negatives that last a little over a minute every hour or so. Shouldn’t this app just trigger a depart/arrival scan when the binary_sensor changes state? I haven’t had any false negatives/positives without the app.

Hello @SunMoonStars,

For better stability, the only config in the behavioural preferences that needs updating is the PREF_MQTT_REPORT_SCAN_MESSAGES. It should be set to true. Outside that, should be all good.

Can I know the kind of device you are using? I made some changes to the dev of late to fix some issue over something similar to what you saying. Should be available for upgrade towards the later part of today.

Regards

using iphones and apple watches.

Hi,
I have a couple of Pi’s running Monitor, so I’m moving them over to your app. I’m getting an error in the log that I can’t figure out:

2020-03-30 17:25:41.945478 WARNING AppDaemon: Unknown Plugin Configuration in get_plugin_api()
2020-03-30 17:25:41.946184 WARNING home_presence_app: ------------------------------------------------------------
2020-03-30 17:25:41.946364 WARNING home_presence_app: Unexpected error running initialize() for home_presence_app
2020-03-30 17:25:41.946553 WARNING home_presence_app: ------------------------------------------------------------
2020-03-30 17:25:41.947321 WARNING home_presence_app: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 145, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 276, in run_in_executor
    response = future.result()
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/appdaemon/apps/Monitor-App/home_presence_app.py", line 72, in initialize
    self.mqtt.set_state(
AttributeError: 'NoneType' object has no attribute 'set_state'

Any ideas? Thanks!

Hello @sota,

Did you setup the MQTT plugin as needed?

Thanks

1 Like

Hi @Odianosen25,
Yes, this is my first time using appdaemon but I think the config is correct:

system_packages: []
python_packages: []
init_commands: []
plugins:
  MQTT:
    type: mqtt
    namespace: mqtt
    client_host: 192.168.16.5
    client_user: ****
    client_password: ****

Actually, your question pointed me in the right direction - my appdaemon.yaml was wrong. Fixing it and restarting has got it up and running. Thanks!

One other question: As I mentioned, I already had Monitor installed. Do I just set their config files back to default and use your app to push the known_devices, etc?

@sota,

Well I don’t think you have to. But since you got several might be good you do to ensure they all outputting the same data.

Regards

I have newly installed this my environment is…

  1. Home assistant 107.1 on en Ubuntu VM
  2. Appdemon with HACS in HA
  3. RaspberryPi with monitor.sh installed (because the Monitor dosn’t work in the Ubuntu environment with an HAMA USB Blutooth Stick if got the following error)
Can't create raw socket: Permission denied
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/coreutils/libstdbuf.so' from LD_PRELOAD cannot be preloaded (failed to map segment from shared object): ignored.

i dont find a solution for this so that i change to RaspberryPi

The Monitor Settings on the Raspberry are the following...

# ---------------------------
#								
# MOSQUITTO PREFERENCES
#								
# ---------------------------

# IP ADDRESS OR HOSTNAME OF MQTT BROKER
mqtt_address=192.168.180.224

# MQTT BROKER USERNAME
mqtt_user=user

# MQTT BROKER PASSWORD
mqtt_password=password

# MQTT PUBLISH TOPIC ROOT 
mqtt_topicpath=monitor

# PUBLISHER IDENTITY 
mqtt_publisher_identity='wohnzimmer'

# MQTT PORT 
mqtt_port='1883'

# MQTT CERTIFICATE FILE
mqtt_certificate_path=''

#MQTT VERSION (EXAMPLE: 'mqttv311')
mqtt_version=''

# ---------------------------
#
# BEACON MAC ADDRESS LIST; REQUIRES NAME
#
# 	Format: 00:00:00:00:00:00 Nickname #comments
# ---------------------------
xx:xx:xx:xx:xx:xx BLE GTag Schluessel Finley
xx:xx:xx:xx:xx:xx BLE Tile Schluessel Finley

Log output from monitor.sh

Apr 04 20:12:04 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 08:12:04 pm [DEL-RAND]        RAND 63:D6:48:00:D3:49 expired after 188 seconds
Apr 04 20:09:54 raspberrypi bash[4295]: ./support/btle: line 399: printf: write error: Broken pipe
Apr 04 20:06:39 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 08:06:39 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 186 seconds
Apr 04 20:05:34 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 08:05:34 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 189 seconds
Apr 04 20:04:24 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 08:04:24 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 183 seconds
Apr 04 20:01:44 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 08:01:44 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 187 seconds
Apr 04 19:59:04 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:59:04 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 185 seconds
Apr 04 19:59:04 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:59:04 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 188 seconds
Apr 04 19:59:04 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:59:04 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 189 seconds
Apr 04 19:59:04 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:59:04 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 170 seconds
Apr 04 19:59:04 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:59:04 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 188 seconds
Apr 04 19:57:59 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:57:59 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 189 seconds
Apr 04 19:56:54 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:56:54 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 189 seconds
Apr 04 19:54:24 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:54:24 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 152 seconds
Apr 04 19:52:34 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:52:34 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 189 seconds
Apr 04 19:47:09 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:47:09 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 123 seconds
Apr 04 19:47:03 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:47:03 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 183 seconds
Apr 04 19:46:45 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:46:45 pm [CMD-RSSI]        PUBL xx:xx:xx:xx:xx:xx RSSI: -94 dBm (initial reading | 106 dBm)
Apr 04 19:45:43 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:45:43 pm [DEL-RAND]        RAND xx:xx:xx:xx:xx:xx expired after 168 seconds
Apr 04 19:45:14 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:45:14 pm [CMD-RSSI]        PUBL xx:xx:xx:xx:xx:xx RSSI: -102 dBm (slow movement depart | 21 dBm)
Apr 04 19:45:05 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:45:05 pm [CMD-RSSI]        PUBL xx:xx:xx:xx:xx:xx RSSI: -88 dBm (slow movement depart | 26 dBm)
Apr 04 19:45:05 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:45:05 pm [CMD-RSSI]        PUBL xx:xx:xx:xx:xx:xx RSSI: -62 dBm (slow movement approach | 29 dBm)
Apr 04 19:42:56 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:42:56 pm [CMD-RSSI]        BEAC xx:xx:xx:xx:xx:xx RSSI: -92 dBm (slow movement depart | 21 dBm)
Apr 04 19:41:50 raspberrypi bash[4295]: [+] 0.2.200 04-04-2020 07:41:50 pm [CMD-RSSI]        PUBL xx:xx:xx:xx:xx:xx RSSI: -102 dBm (slow movement depart | 26 dBm)
Apr 04 19:40:43 raspberrypi bash[4295]: > known beacon: xx:xx:xx:xx:xx:xx publishes to: monitor/wohnzimmer/ble_tile_schluessel_finley
Apr 04 19:40:43 raspberrypi bash[4295]: > known beacon: xx:xx:xx:xx:xx:xx publishes to: monitor/wohnzimmer/ble_gtag_schluessel_finley
Apr 04 19:40:40 raspberrypi bash[4295]: > removing web request caches
Apr 04 19:40:40 raspberrypi bash[4295]: > starting monitor.sh (v. 0.2.200)...

The Appdemon Settings on in the HA environment are…

secrets: /config/secrets.yaml
appdaemon:
  latitude: xx.xxxxx
  longitude: xx.xxxxx
  elevation: 2
  time_zone: Europe/Amsterdam
  plugins:
    HASS:
      type: hass
    MQTT:
         type: mqtt
         namespace: mqtt
         client_host: 192.168.180.224
         client_user: user
         client_password: password
         verbose: True

http:
  url: http://127.0.0.1:5050
admin:
api:
hadashboard:

The presence app settings are…

home_presence_app:
  module: home_presence_app
  class: HomePresenceApp
  plugin: 
    - HASS
    - MQTT
  monitor_topic: monitor
  mqtt_event: MQTT
  user_device_domain: device_tracker
  everyone_not_home: everyone_not_home
  everyone_home: everyone_home
  somebody_is_home: somebody_is_home
  depart_check_time: 30
  depart_scans: 3
  minimum_confidence: 60
  not_home_timeout: 60
  system_check: 30
  system_timeout: 60
  home_gateway_sensors:
    - binary_sensor.wohnzimmer
  
  # reboot the all nodes at 12 midnight on Mondays and Thursdays
  scheduled_restart:
    time: 00:00:01
    days:
      - mon
      - thu
    location: all

  # other location configuration options
    #location: living_room, kitchen

    #location:
    # - living_room
    # - kitchen

  home_motion_sensors:
    - binary_sensor.wohnzimmer
#    - binary_sensor.kitchen_motion_sensor_occupancy
#    - binary_sensor.hallway_motion_sensor_occupancy
    
  log_level: DEBUG
  known_devices:
#    - xx:xx:xx:xx:xx:xx Odianosen's iPhone
#    - xx:xx:xx:xx:xx:xx Nkiruka's iPad
  
  known_beacons:
    - xx:xx:xx:xx:xx:xx BLE GTag Schluessel Finley
    - xx:xx:xx:xx:xx:xx BLE Tile Schluessel Finley

  remote_monitors:
    disable: True
    wohnzimmern:
      host: 192.168.180.202
      username: pi
      password: raspberry
      reboot_command: sudo /sbin/reboot now
      auto_reboot_when_offline: True
      time: 02:00:01

My problem is i see no devices like
device_tracker.ble_gtag_schluessel_finley

But i see in de Appdemon many entrys without payload

App demon Log:

2020-04-04 22:22:35.560198 DEBUG home_presence_app: register_service: monitor/load_known_devices, {}
2020-04-04 22:22:35.560824 DEBUG home_presence_app: register_service: monitor/clear_location_entities, {}
2020-04-04 22:22:35.565926 INFO AppDaemon: App initialization complete
2020-04-04 22:22:37.010719 DEBUG home_presence_app: call_service: mqtt/publish, {'topic': 'monitor/echo', 'payload': ''}
2020-04-04 22:22:41.011847 DEBUG home_presence_app: Registering run_in in 0 seconds for home_presence_app
2020-04-04 22:22:41.029483 DEBUG home_presence_app: call_service: mqtt/publish, {'topic': 'monitor/KNOWN DEVICE STATES', 'payload': ''}
2020-04-04 22:23:07.016714 DEBUG home_presence_app: call_service: mqtt/publish, {'topic': 'monitor/echo', 'payload': ''}
2020-04-04 22:23:37.014038 DEBUG home_presence_app: call_service: mqtt/publish, {'topic': 'monitor/echo', 'payload': ''}
2020-04-04 22:24:07.015450 DEBUG home_presence_app: call_service: mqtt/publish, {'topic': 'monitor/echo', 'payload': ''}
....

Has anyone a idea what i make wrong in the Monitor or App Demon or Presence app settings? have i to do any changes in de HA or mqtt config.

many regards for every input on this problem