Odianosen25 / Monitor-App

Appdaemon App for Andrew's Monitor Presence Detection System
74 stars 9 forks source link

binary_sensor.everyone_home flags to on during HA restart even if not everyone is home. #53

Closed skynet01 closed 4 years ago

skynet01 commented 4 years ago

Noticed this on the current none dev branch, when HA restarts binary_sensor.everyone_home is marked on even though some people are not home.

I have this in my automation (from before your plugin.. but this shouldn't affect it)

 - id: reboot_presence_monitoring  
  alias: Restart Presence Scan on boot
  initial_state: 'on'
  trigger:
    platform: homeassistant
    event: start
  mode: single
    - service: mqtt.publish
      data_template:
          topic: 'monitor/scan/restart'
          payload: >-
            {
              "message": ""
            }  
Odianosen25 commented 4 years ago

@skynet01,

Thats interesting, as in the present dev, I am doing the exact same thing. When HA restarts it

So not sure how the everyone_home comes in. Unless when it restarts, as it doesn't know the true definition of everyone_home, then maybe that is actually it.

The everyone_home sensor is not based on those devices declared in the config, but the devices it had seen overtime. Maybe I should change that. Will add it to my list of to do.

Do kindly check the other stuffs I have added if it works fine, so after fixing this bug will do a release.

Regards

skynet01 commented 4 years ago

From my observation, it looks like it's not waiting long enough before checking if everyone_home and setting it. The nodes are still scanning but it already marked "everyone_home". Maybe wait until all nodes are reporting idle before checking for "everyone_home" it's weird that it only happens on HA restart.

After i removed monitor/scan/restart automation it seems everyone_home is working properly again, still not sure why triggering the scan manually results in incorrect number :)

p.s.: I checked your somebody_home counter update and universal entities fix. Both cover & lock entities trigger scans properly :)

Odianosen25 commented 4 years ago

Ok I think I will look into your method of only checking it after all nodes have scanned when HA restarts, that should be straight forward enough

Odianosen25 commented 4 years ago

@skynet01,

Ok check now it that's all fixed, as I want to release this, before considering other fixes.

Thanks for confirming the other ones are fine

skynet01 commented 4 years ago

Ok I think I will look into your method of only checking it after all nodes have scanned when HA restarts, that should be straight forward enough

I was just thinking that a maybe better way to implement this is to just monitor the mqtt triggers that activate node functions like "/monitor/scan/ARRIVE" or "monitor/scan/restart". Then wait until nodes are idle again before doing the count. This way if someone uses those mqtt calls in automation or any other way, you will always have the correct count of people

Odianosen25 commented 4 years ago

@skynet01,

I do something similar, but with the timer responsible for running the everybody_home or not_home. What I had noticed was that I wasn't cancelling a previous one, when a new one was initialised, and what I felt was causing it.

There is a fix now, is it not working?

Regards