openhab / openhab-ios

The repository of the iOS client
Eclipse Public License 2.0
194 stars 128 forks source link

[Idea] Send device data back to openHAB #488

Open bredmich opened 5 years ago

bredmich commented 5 years ago

Hi there

I´m currently using the oH iCloud binding to get some device data from my iOS devices. Such as the battery level/status and the location. Apple applies changes to the iCloud environment once in a year and that leads to problems with the iCloud binding.

It´s possible for apps to get device data like the current battery level/status and location, so why don´t we use it for openHAB? The iOS app could update items with the data directly or through myopenhab. _=The battery status describes if the battery is charging, notcharging or chargerd._

Example: Having three items configured in openHAB.

// iCloud.items
String iPhone_Michael_BatteryStatus "Ladestatus [MAP(charging.map):%s]" <battery> (iPhones)
Number iPhone_Michael_BatteryLevel "Akku [%d %%]" <battery> (iPhones, gPersist)
Location iPMichael_Location "Ort" <map> (iPhones, gPersist)

And if necessary exposed to myopenhab

// openhabcloud.cfg
expose=iPhone_Michael_BatteryStatus,iPhone_Michael_BatteryLevel,iPhone_Michael_Location

Now for the iOS openHAB app. There could be an extension of the settings for iOS device data with predefined fields for each type you would like to send to your oH instance. iPhone Battery Status: <Input Item for iPhone Battery Status> iPhone Battery Level: <Input Item for iPhone Battery Level> iPhone Location: <Input Item for iPhone Location>

I already tried to find another way to get the device data to my oH instance but could find any that´s working better than the iCloud binding.

Thanks and kind regards Michael

weakfl commented 5 years ago

Apple applies changes to the iCloud environment once in a year and that leads to problems with the iCloud binding.

@bredmich I think you're referring to the certificates issue. Afaik this could be resolved in the binding by not using a hardcoded certificate or making it configurable.

See #52 for a somewhat similar request.

Personally I wouldn't use such a feature. It will have a bigger impact on battery life than using iCloud and it will be inevitably unreliable. Keeping background tasks going is a major pita.

bredmich commented 5 years ago

Afaik this could be resolved in the binding by not using a hardcoded certificate or making it configurable.

But no one does it. It´s an issue for two years now and every year there´s another way to fix it. First it was just downloading the certificate, now you needed to install gson with the latest iCloud binding. I wonder what´s next, to keep it alive. Or maybe we´ll loose the iCloud binding completely, when Apple decides to close it.

It will have a bigger impact on battery life than using iCloud

It shouldn´t have a bigger impact than iCloud. Pulling from iCloud results in an update for EVERY iCloud device and not just the one you want to update. So using the iCloud binding forces every of your iCloud devices (and in the same family) to update the status. When the device itself or the app uses the correct methode from Apple there shouldn´t be any impact on the battery life. The solution with OwnTracks is just another workaround for things that could be achieved without any Third Party involved.

kind regards Michael

weakfl commented 5 years ago

It shouldn´t have a bigger impact than iCloud.

When the device itself or the app uses the correct method from Apple there shouldn´t be any impact on the battery life.

Apple has bare metal access and can use the hardware far more efficiently than an app. There's always overhead, even when using the significant change location service (which is the only way to keep updates going anyway).

Pulling from iCloud results in an update for EVERY iCloud device and not just the one you want to update. So using the iCloud binding forces every of your iCloud devices (and in the same family) to update the status.

You're pulling data from iCloud and not from the device. Sending a request to the iCloud service does not query the device, the device updates its status when it deems it appropriate. Just try to update the location of one of your family members a couple of times while they're moving and you'll see that the location doesn't change that frequently.

And as I've said it will be unreliable:

bredmich commented 5 years ago

Just try to update the location of one of your family members a couple of times while they're moving and you'll see that the location doesn't change that frequently.

I´m getting location updates everytime i send an refresh. Even when my phone is on my desk and not moving at all. So there´s some kind of communication between iCloud and the device when sending the refresh to the channel.

bredmich commented 5 years ago

And as I've said it will be unreliable:

I just checked some apps that i use for background tasks. tado: It uses an geofence to control my heating unit and it works even after a restart without starting the app. Geofency: This app can monitor geofences and iBeacons. The app works even after a restart and controls an dummy over REST. So there are possibilities to make an app working after the device was restartet.

kind regards Michael

weakfl commented 5 years ago

That's good to know, it's been a while since I last tested something like this.

I'm still not convinced, but if this is something people want I can look into it. Can't hurt to have more options after all.

ajbastien commented 3 years ago

I have an app that does geo fencing. I could work on this. I still think for geo fencing use the Shortcuts app to trigger switches/contacts in OH. The battery level is easy to get the issue is doing it in the background.

pinki commented 3 years ago

I have an app that does geo fencing. I could work on this. I still think for geo fencing use the Shortcuts app to trigger switches/contacts in OH.

That would be great. The Shortcuts app's geo fencing triggers need confirmation and are therefore useless.

ajbastien commented 2 years ago

Sorry, I no longer have time to work on this.

hmerk commented 2 years ago

As we have the iCloud binding working, not many change recently, I don‘t see a need for this enhancement and rather would suggest to close this isue as a „won’t fix“