room-assistant icon indicating copy to clipboard operation
room-assistant copied to clipboard

iOS Room Assistant App is not keeping the BLE alive for detection

Open JohnTranQUT opened this issue 2 years ago • 35 comments

Describe the bug I believe that the Room-Assistant companion app does not remain running correctly in the background of iOS devices.

To reproduce Download the iOS Room-Assistant companion App. Allow it to run and watch the detection fall off and become unavailable after about 10mins of no usage. Watch the HomeAssistant and MQTT have nothing reporting to the device.

Relevant logs This is not related to the Room-Assistant running the Bluetooth scans, only the Companion app.

Relevant configuration The Room-Assistant was allowed to run in the background and has the option "Always running" with BLE on the iPhone.

Expected behavior It's expected that the BLE off of the iPhone does not drop off when the Room-Assistant Companion app is left running in the background.

Environment

  • room-assistant version: [e.g. 2.0.0]
  • installation type: NodeJS
  • hardware: Raspberry Pi Zero W and NUC
  • OS: Raspberry Pi and Ubuntu

Additional context I think this may be related to the latest iOS update/changes. I haven't investigated that though. Retoggling brings the BLE alive to be detected on the Room-Assistant, therefore making entries into MQTT again however this destroys the "Automacy" that is expected from using the App. I have the HA Companion on Android Phones and they are not having any issues at all.

JohnTranQUT avatar Apr 12 '22 11:04 JohnTranQUT

Describe the bug I believe that the Room-Assistant companion app does not remain running correctly in the background of iOS devices.

To reproduce Download the iOS Room-Assistant companion App. Allow it to run and watch the detection fall off and become unavailable after about 10mins of no usage. Watch the HomeAssistant and MQTT have nothing reporting to the device.

Relevant logs This is not related to the Room-Assistant running the Bluetooth scans, only the Companion app.

Relevant configuration The Room-Assistant was allowed to run in the background and has the option "Always running" with BLE on the iPhone.

Expected behavior It's expected that the BLE off of the iPhone does not drop off when the Room-Assistant Companion app is left running in the background.

Environment

  • room-assistant version: [e.g. 2.0.0]
  • installation type: NodeJS
  • hardware: Raspberry Pi Zero W and NUC
  • OS: Raspberry Pi and Ubuntu

Additional context I think this may be related to the latest iOS update/changes. I haven't investigated that though. Retoggling brings the BLE alive to be detected on the Room-Assistant, therefore making entries into MQTT again however this destroys the "Automacy" that is expected from using the App. I have the HA Companion on Android Phones and they are not having any issues at all.

What are your BLE settings on your HA companion app does your android device?

I am having a terrible time setting it up with the correct distance for detecting my android phone.

bachoo786 avatar Apr 15 '22 00:04 bachoo786

What are your BLE settings on your HA companion app does your android device?

Maxed Frequency, Medium Strength. Works fine on Android phones so it's not the issue I am having here.

I am having a terrible time setting it up with the correct distance for detecting my android phone.

Not sure if the distance is of the utmost importance however I do know there is a setting in to set the ratio for each device. Because I am using the same ESP32 or Raspberry PIs, I'd assumed they all would detect at the same distance ratios and hence would know which node the phone/device is closest to.

JohnTranQUT avatar Apr 25 '22 22:04 JohnTranQUT

I have the same issue, after some period of time room assistant app on latest iOS is no longer running. As soon as I open the app, it starts working again.

adam-palmer1 avatar May 30 '22 15:05 adam-palmer1

Same here for 4 iPhones all running the latest iOS and an iPad also running latest iPadOS

townsmcp avatar Jun 11 '22 11:06 townsmcp

I running into the same issue with 2 iPhones as well. Did you already try to disable "auto toggle visibility"?

vistalba avatar Jun 19 '22 09:06 vistalba

Im not an iOS dev but as far as I know this can’t and won’t work in modern iOS versions. The device can not continue to beacon in the background and the app needs to stay running non the foreground for it to function which renders it redundant.

I’m currently using a spigen credit card holder phone case with a slim tile for tracking and so far it’s working effectively.

adam-palmer1 avatar Jun 19 '22 09:06 adam-palmer1

I have found the same behaviour, pretty sure it is an IOS thing, hence switched back to BluetoothClassic which still works all the time for my IOS devices, and Android. Not as fast or accurate as BLE but still works effectively for room presence.

alastaid avatar Jul 11 '22 06:07 alastaid

I have found the same behaviour, pretty sure it is an IOS thing, hence switched back to BluetoothClassic which still works all the time for my IOS devices, and Android. Not as fast or accurate as BLE but still works effectively for room presence.

For me also room-assistant iOS works with BLE as long as I do not enable "auto-toggle visibility" AND don't kill the app when it runs in the background.

For me BluetoothClassic results in a higher power consumption and is much less accurate (e.g. shows living room while I'm far away but because of some wired RF stuff the signal is best to that room-assistant node).

vistalba avatar Jul 11 '22 07:07 vistalba

I have the same problem, it stops sending about 5 min after the app is sent to background on ios.

cis2131 avatar Jul 24 '22 09:07 cis2131

Try iOS 16 beta. It seems to have fixed these problems for me. I have companion app toggled off for visibility. Even after rebooting the phone I don’t need to go into companion app anymore - it just works and reports all the time as needed

townsmcp avatar Jul 24 '22 09:07 townsmcp

Try iOS 16 beta. It seems to have fixed these problems for me. I have companion app toggled off for visibility. Even after rebooting the phone I don’t need to go into companion app anymore - it just works and reports all the time as needed

If you talk about the companion app, which app do you mean? Room-Assistant app?

vistalba avatar Jul 24 '22 10:07 vistalba

@vistalba Room Assistant companion app stays the same. But install iOS 16 beta on your phone and the restart/random stop working of Room Assistant companion app goes away. I have been running io16 for a week now and all good. Since installing ios16 I no longer need to kill and restart Room Assistant companion app or even Home Assistant companion app after a phone reboot - BLE detection just works as it should even with it running in the background

townsmcp avatar Jul 24 '22 10:07 townsmcp

@townsmcp How can you use Homeassistant app for BLE advertising? Didn't saw such an option so far so I've installed room-assistant. Would like to test with the Homeassistant App as well.

I do not have an issue that BLE advertisement stops working as long as I've set the location servcie for the app to "always" AND I do not force close the app. After phone restart I have to open room-assistant app once. Otherwise its working fine all day long. (also with iOS 15.6).

vistalba avatar Jul 24 '22 10:07 vistalba

@vistalba i think you are missing my point. On iOS 15, after a reboot of the device (phone or iPad) I had to reopen both Room Assistant and Home Assistant apps so they could talk with their respective systems (I use Home Assistant app for location tracking - there is no BLE access for Apple devices).

I did have an issue with iOS 15, even with location service set to always and the in app toggle turned off. At random, the app would stop talking to all my RPIs with Room Assistant installed. The only way round that was to terminate the background running Room Assistant app and reload. Wasn’t an issue for me but getting everyone in the house to do similar when their device stopped reporting was a complete pain - it should just work all the time, but it just didn’t for me.

With iOS 16 you no longer need to start Room Assistant again after a phone reboot. For example, my son turned his phone off each day when at school. When he is on the way home he would need to open both Room Assistant and Home Assistant apps before getting home after turning his phone on. If he didn’t, when he gets home the front door smart lock would not unlock for him to let him in the house.

To summarise, iOS 16 beta now facilitates Room Assistant, and Home Assistant apps to work as they should, even after a reboot of the phone

townsmcp avatar Jul 24 '22 10:07 townsmcp

@townsmcp Got it. Thanks. For me it was a problem as my wife kills the background apps all the time. Since she is aware of the issue never saw it not working. So was pretty stable with iPhone 12/ 12 Pro Max.

One more thing… how does HA App and Room-Assistant app talk to each other? I‘ve installed them both. But I thought tha room-assistant does work standalone. As the RPi‘s are reporting the devices and room informations.

May you can test if room-assistant now also works with the „auto-toggle visibility“ feature as it would improve privacy. As at the moment I can‘t update to the iOS16 beta because my banking apps won‘t work anymore.

vistalba avatar Jul 24 '22 11:07 vistalba

@vistalba as far as I’m aware HA and RA apps don’t talk to each other. It’s a shame that Apple lock down the Bluetooth entities so something like HA app can’t use them. Although, if RA app manages to get to Bluetooth stack, I guess HA app could to with modifications?

Sure, for the auto toggle, I’m happy to give it a test by turning that back on.

Regarding banking apps on iOS 16, all my ones seem to work perfectly (Lloyds, Barclays, Virgin, Halifax, Mettle etc) - being as it is an official Apple release and not some jailbreak going on they should all work fine

townsmcp avatar Jul 24 '22 12:07 townsmcp

@townsmcp I‘m not a developer. But as far as I know it Apple has another approach. No App does have access directly to the bluetooth. The iOS does all the BLE advertisements and so on. But Apps are able to set a BLE advertisement which iOS should do.

I guess this has some power efficiency reasons. So only the OS does BLE stuff and all Apps have to use an API to control, what OS sends out or to get nearby deviced.

From my point of view, I do not see any reason why Homeassistant Devs should not be able to integrate room-assistant functionality as well.

vistalba avatar Jul 24 '22 13:07 vistalba

I have just installed ios 16 Beta, but the announcements still stops after a while. It even stops while the phone screen is on. Reopening the app, makes it resume for a while. I must admit that I am trying to use this without the room assistant server, but instead I use an ESP32 to detect the UUID. I want to use it for unlocking my car, when I get near it. Can that be the reason. Does room assistant server send some packet back, that keeps it alive?.

cis2131 avatar Jul 24 '22 18:07 cis2131

I have just installed ios 16 Beta, but the announcements still stops after a while. It even stops while the phone screen is on. Reopening the app, makes it resume for a while. I must admit that I am trying to use this without the room assistant server, but instead I use an ESP32 to detect the UUID. I want to use it for unlocking my car, when I get near it. Can that be the reason. Does room assistant server send some packet back, that keeps it alive?.

I've got the same issue with the same setup. ESP32 for the BLE tracking hubs and using the RA app on iOS to get a static MAC, but the advertisement stops after 5-10 minutes or so.

nathanroyss avatar Jul 24 '22 23:07 nathanroyss

The app needs to be updated. I confirmed it is not setup for background by going into the iOS settings (General->Background App Refresh). I assume this means it will time out in the background. Base on my testing, it only sends a beacon when I open the app each time.

wdbrady avatar Jul 25 '22 03:07 wdbrady

@wdbrady as confirmed above, it is nothing to do with the app needing to be updated. Your issue is to do with your iOS install. Try iOS beta 16 and your problems will go away; full background refreshing, resume on phone reboot etc etc

townsmcp avatar Jul 25 '22 06:07 townsmcp

@wdbrady as confirmed above, it is nothing to do with the app needing to be updated. Your issue is to do with your iOS install. Try iOS beta 16 and your problems will go away; full background refreshing, resume on phone reboot etc etc

Not sure if iOS 16 does fix it.. I'm on the latest beta of iOS 16 and seeing the same issue as others.

nmr94 avatar Jul 25 '22 13:07 nmr94

@nmr94 ate you using Room Assistant or ESPresence/ESPHome? I’m using the Room Assistant software on RPIs and so far have no issues at all on latest iOS 16 beta. I am however out at the moment so will see if Auto Toggle Visibility turned off now works as requested by @vistalba

townsmcp avatar Jul 25 '22 14:07 townsmcp

@nmr94 ate you using Room Assistant or ESPresence/ESPHome? I’m using the Room Assistant software on RPIs and so far have no issues at all on latest iOS 16 beta. I am however out at the moment so will see if Auto Toggle Visibility turned off now works as requested by @vistalba

I'm using ESPresence, so this could be the root of the issue. I've got a Pi laying around so will try and see if the issue is repeatable there too.

nmr94 avatar Jul 25 '22 15:07 nmr94

@nmr94 yeah that could be it. With Room Assistant it now works well. @vistalba just got back home with the Auto Toggle Visibility turned off (did a phone reboot before I got home as well) - working perfectly when I got back.

@nmr94 if you do install RA onto an RPI, something I noticed a couple of days ago when updating the RPI was that BLE would no longer run if the RA service is running as the user ‘pi’. Bluetooth Classic worked fine, just not BLE. The service needs to be run as root. I haven’t installed ESPresence, but based on the rip update, can you choose which user to run the service as? Maybe an update occurred recently and you now need to run as root?

townsmcp avatar Jul 25 '22 15:07 townsmcp

@vistalba just got back home with the Auto Toggle Visibility turned off (did a phone reboot before I got home as well) - working perfectly when I got back.

@townsmcp No I thought when the feature „auto toggle visibility“ is „enabled“. In this case iOS should stop advertising BLE beacon when it doesn‘t receive beacons from room-assistant. So disable it is more stable (on iOS 15 at least) as it does broadcast the BLE beacon all the time. Also when you are far away from room-assistant nodes. So this allows others like supermarkets to tack your phone too. When you enable it, room-assistant app stops BLE beacon when it does not see you room-assistant BLE sent from the RPi‘s. So is my understanding so far.

vistalba avatar Jul 25 '22 17:07 vistalba

Just to clear up some confusion:

  • The "Background Refresh" is just a way of executing specific tasks in the background, such as downloading data from the Internet or calculating something. It does not affect BLE advertising in any way.
  • Key for BLE advertisements to always run is that the app needs to have "Always" location permissions (it will never pull your GPS or do anything else to locate you - it's just to access the BLE stack).
  • iOS does not allow toggling or changing BLE state in the background refresh in recent versions, the app always needs to be in the foreground for this.
  • The app is configured to have its BLE advertisements constantly running and restored by iOS. This should technically work just like that, but in some cases iOS seems to misbehave... it's not really clear to me why. Maybe iOS 16 really improved here, I haven't tried it yet. On my personal phone (iOS 15) I haven't had issues running it in the background at least, I just need to open the app once after a reboot.
  • If you force kill the app from the task switcher it will not be able to advertise until you open it again (as remarked above).
  • Current implementation of auto-toggle visibility needs the non-beta version of room-assistant and is/was planned to be removed due to stability issues. Another option that is a bit more privacy conscious was planned to be added to the app if possible.
  • I don't know the ESPresence implementation, but room-assistant does not send constant packets. It will just connect to the phone at least once every ~15 minutes, as this is roughly the cycle in which the advertised address changes.

The code of the app is fully open source at mKeRix/room-assistant-companion-ios if you want to take a look.

mKeRix avatar Jul 25 '22 18:07 mKeRix

Thanks for clarifying this.

Just to understand it correctly, does room-assistant app needs to get some reply from room-assistant server to be able to keep sending out advertisements?.

cis2131 avatar Jul 25 '22 19:07 cis2131

Same question here: Is it possible to use the app just to keep BLE packets from the same MAC address (ie to use for the ESPHome BLE tracker app) or does it only work with RA?

TheDK avatar Aug 03 '22 17:08 TheDK

I was struggling with the issue of room assistant only working when in the foreground. This was with a fresh install of the room assistant companion app in iOS 15. I was able to get it to start working with the following:

  • I tried to follow the suggestion above about setting the location settings to always but was confused because the room-assistant app didn't even show up
  • By default the "auto toggle visibility" is disabled so I never had touched it
  • Enable "auto toggle visibility" this will cause the phone to prompt you if you want to allow it to view your location, select "when using"
  • Disable "auto toggle visibility" again
  • Now go into the location settings and the room-assistant app will show up, set it to "always" as suggested above
  • Restart the app

By watching mqtt I was able to recreate the issue of the roomAssistant beacons going away after the app is moved to the background. After going through the above procedure it seems to be solid. YMMV

cengel74 avatar Aug 06 '22 23:08 cengel74