Get iPhone Battery status into openhab

Anyone know of a way? It probably needs some sort of app on the phone to report the battery state…I had an idea for charging the phone to the 100% at the last possible time before I get up in the morning - on the theory that lithium batteries prefer to be between 20 and 80% for the most time.

Check out this tutorial. I have a modified version pulling in battery level and charging state. Also does location.

Awesome. To that uses code in a rule to pull off icloud? I found that there’s a pyiCloud library which allows similar.

How does your handle 2fa in icloud?

I might look at yours and produce it as a script that I can push into mqtt (only as I like that as a transport).

Then I might get some sort of wifi controlled switch, and I can keep the batter at 80% over night, and then charge the final 100% so that it’s at 100% right before I get up in the morning.

Your script will help point me into the right direction.

I didn’t actually write the script, I’m just a happy user. If you have detailed questions about it, I suggest you post in the thread I linked. However, I can say that I also have 2FA enabled, and it doesn’t seem to be an issue when openHAB queries the iCloud server. Actually, I’m not sure why it’s not.

I like your idea on keeping from overcharging your devices. I might need to implement something similar myself!

The Owntracks module will also report most of those metrics of your mobile device (iOS/Android) if you didn’t want to be connected to Apple for that sort of thing.

That is no longer true for more recent phones.

However, modern devices are way smarter with managing power. Leaving your device plugged in all the time is just fine. The only reason this should be a concern, as hinted above, is if you have a poorly designed case that doesn’t allow for heat dissipation.

And if you prefer an Apple source

The Best Practice, however, is to charge the phone overnight, every night. As it stops automatically at 100% you can’t overcharge it doing this.

To summarize, you will likely accomplish nothing and potentially damage your phone’s battery more than just leaving it plugged in over night.

I would recommend owntracks. I use own tracks already for location/presence and it passes battery info in as it’s passing in location. So you can easily capture it off mqtt.