mKeRix / room-assistant

Presence tracking and more for automation on the room-level
https://www.room-assistant.io
MIT License
1.26k stars 122 forks source link

High CPU usage / not working correctly sometimes #80

Closed septeven closed 3 years ago

septeven commented 5 years ago

Hello, I recently installed the room assistant addon for Hassio. I'm using it for tracking presence of my NUT Mini Smart trackers. Hassio is installed on a Raspberry 3B+ Since then, I noticed high CPU usage (around 25/35%, normal is 4/6%) as well as intermittently working correctly.

First, almost each time after having restarted Hassio, my NUT mini are showing 'Not home'. I have to restart Room Assistant addon in order to get the correct status 'Default-room'.

As for the CPU usage, I have noticed :

FYI, I am using miflora platform for monitoring three mi flora plant sensors and have received warnings for them ('Update of sensor.XXX is taking over 10 seconds'). I tried to deactivate them and see if the problem with Room Assistant is still occurring - I might want to say it solved it, but didn't troubleshoot it for long time. It might be helpful for you to know though.

For now, I decided to stopped using Room Assistant but hopefully, you'll find what's my problem so I can use it again. Thanks

Room assistant config:

{ "services": [ "mqtt", "ble" ], "room": "default-room", "mqtt": { "url": "mqtt://localhost", "username": "---username---", "password": "---password---", "rejectUnauthorized": true }, "ble": { "channel": "room_presence", "useAddress": false, "whitelist": [ "---mac-address-1---", "---mac-address-2---" ], "maxDistance": 0, "updateFrequency": 0, "processIBeacon": true, "onlyIBeacon": false, "majorMask": "0xFFFF", "minorMask": "0xFFFF" }, "gpio": [], "shell": [] }

My yaml file:

sensor:

  • platform: mqtt_room device_id: "---mac-address-1---" name: "Nut Mini 1" state_topic: 'room_presence' timeout: 300
  • platform: mqtt_room device_id: "---mac-address-2---" name: "Nut Mini 2" state_topic: 'room_presence' timeout: 300
mKeRix commented 5 years ago

Hm, interesting. room-assistant isn't really a CPU intensive application, so this shouldn't happen. I'll put some investigation work on my list regarding this. Still need to learn a bit more about building Hass.io addons.

septeven commented 4 years ago

Hi, I'm digging up this old report. I have re-installed the room-assistant today to give it another try.

Since my initial report, I have moved to another country, set up a whole new home assistant config which is installed on a i5 NUC (under Proxmox) and besides the fact I have got some difficulties to make it working correctly (_for now, my ble nut mini keyfinder reports itself at home for a few minutes after having started the addon, then nothome for hours, I have to reboot the addon, and so on, but that is another problem), I'm encountering a very high CPU usage since I have started the addon, is that normal ?

See the picture, was always around 4% CPU use, now 28/29% ....

high cpu usage
mKeRix commented 4 years ago

Since then the whole codebase of room-assistant also changed, so it's quite interesting that you still see the same behavior. On my Pi Zeros room-assistant sits between 2-4% of CPU usage, except for those with thermopile sensors attached (image generation requires some more power). I don't think that the add-on should take up that much CPU for your use case, especially not on a NUC. I can try to reproduce this on my NUC, although that won't be entirely the same setup.

Do you see the same increase in CPU usage when you run room-assistant without the BLE integration enabled?

septeven commented 4 years ago

Hi @mKeRix Thanks for your quick reply.

The high CPU usage stayed between 25-30% during one all night (11:30pm - 9:30am) then it dropped to something between 5-9% - I don't exactly and precisely remember what I changed around that time but since nothing worked correctly (_as said, after the component start, my NUT mini ble key finder stays about 1 minute at home, then nothome until I restart the component), I remember having added the option timeout: 30 - thus it might be that particular option that fixed the CPU usage ?

So I just tried to remove this option and restart the component, but the CPU usage stays around 5-9%.... Can't tell what went wrong. The only thing I can notice is that the CPU usage seems to slightly and slowly increase but can't say if that's relevant - see the picture:

CPU usage

Since I'm not experiencing the high CPU usage anymore for the moment, I haven't tried to disable the BLE integration.

Since yesterday, I also added another instance on a pi zero in another room of my house since the NUC didn't cover the whole space (I'm using your component for home / not_home only). The pi zero seems to works flawlessly, but it sounds like the NUC instance doesn't .... I mean, right now the beacon is placed 20" / 50cm away from the NUC and this is the Pi Zero instance that detect it, which is placed 19' / 6m away from the NUC.... That doesn't make sense - the NUC seems to not detect anything at all, and I guess I will have to restart the RA instance on the NUC in order to get it back working... (kind of related to my initial problem of having the beacon at home in the first minutes, then not_home until a restart...)

Please let me know if you want me to open a separate issue about it.

Thanks

mKeRix commented 4 years ago

I think it's fine to keep this in here for now, as it was started as combo issue anyway. Are you running anything else that might be using Bluetooth on the NUC atm? What does your <nuc-ip>:6415/entities endpoint say about the NUT (note: on Hass.io you need to manually map the port for the API in the add-on options)? And, if you have access to the host OS of the VM, could you check if it also stops detecting the NUT if you run hcitool lescan --duplicates? Do the last one with room-assistant turned off, otherwise it will likely throw some errors.

septeven commented 4 years ago

I'm starting to think about using another pi zero to replace the Room Assistant NUC instance... as the CPU usage is increasing the CPU temperature as well of my NUC.

As for your questions, the only thing that is using bluetooth in my setup is the custom component mitemp_bt (https://github.com/custom-components/sensor.mitemp_bt) - Could that be the cause of everything ?

Unfortunately, I had no chance to use hcitool in Proxmox, I tried with the console of the NUC proxmox node, and directly in the home assistant VM one too, none worked, command is not found.

I don't know exactly what you want me to tell you about the <nuc-ip>:6415/entities so here is the whole response :


[
   {
      "attributes":{
         "nodes":[
            "office",
            "livingroom"
         ]
      },
      "id":"status-cluster-size",
      "name":"livingroom Cluster Size",
      "distributed":false,
      "state":2
   },
   {
      "attributes":{
         "quorumReached":true
      },
      "id":"status-cluster-leader",
      "name":"livingroom Cluster Leader",
      "distributed":false,
      "state":"none"
   },
   {
      "attributes":{

      },
      "id":"ble-123456789-tracker",
      "name":"Nut Tag 01",
      "distributed":true,
      "state":true
   },
   {
      "attributes":{
         "distance":1.5,
         "lastUpdatedAt":"2020-09-19T09:33:03.131Z"
      },
      "id":"ble-123456789",
      "name":"Nut Tag 01 Room Presence",
      "distributed":true,
      "distances":{
         "office":{
            "lastUpdatedAt":"2020-09-19T09:33:03.131Z",
            "distance":1.5,
            "outOfRange":false
         },
         "livingroom":{
            "lastUpdatedAt":"2020-09-19T08:25:34.195Z",
            "distance":5.8,
            "outOfRange":false
         }
      },
      "timeout":30,
      "measuredValues":{
         "office":{
            "rssi":-71.09400164499904,
            "measuredPower":-67
         },
         "livingroom":{
            "rssi":-100.29639817258816,
            "measuredPower":-79
         }
      },
      "state":"office"
   },
   {
      "attributes":{

      },
      "id":"ble-987654321-tracker",
      "name":"Nut Tag 02",
      "distributed":true,
      "state":true
   },
   {
      "attributes":{
         "distance":12.8,
         "lastUpdatedAt":"2020-09-19T09:32:57.824Z"
      },
      "id":"ble-987654321",
      "name":"Nut Tag 02 Room Presence",
      "distributed":true,
      "distances":{
         "office":{
            "lastUpdatedAt":"2020-09-19T09:32:57.824Z",
            "distance":12.8,
            "outOfRange":false
         },
         "livingroom":{
            "lastUpdatedAt":"2020-09-19T09:32:38.498Z",
            "distance":43.7,
            "outOfRange":false
         }
      },
      "timeout":30,
      "measuredValues":{
         "office":{
            "rssi":-83.1434116082862,
            "measuredPower":-59
         },
         "livingroom":{
            "rssi":-97.59532054303253,
            "measuredPower":-59
         }
      },
      "state":"office"
   }
]
mKeRix commented 3 years ago

Thanks for providing this. Indeed, having another application retrieve data from the same Bluetooth adapter might cause some issues, as it may meddle with the internal states and so on. That said, for BLE I'm not sure if this is always the case. It could very well be that running both is not causing this issue, but disabling the custom component could at least be worth a shot.

Also thanks for providing the API response, I just wanted to check if the received data is the issue or the calculation that room-assistant does on top of it. The internal logic for determining the state seems correct to me based on your example.

github-actions[bot] commented 3 years ago

There hasn't been any activity on this issue recently. In an effort to provide a better overview of current issues we automatically clean some of the old ones. Many of them may already be resolved in newer versions of room-assistant. This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.