I want to create an automation that, when I place my phone on charge it triggers some entities on and some others to off.
However, I’m not sure how to get the battery state as, I’m led to believe, that the HA companion app needs to be open in the foreground and the device unlocked for the battery_state to update.
Is there a way to get the state of the battery without having to do this?
If states such as occupancy can be detected via the device without having to open the companion app, can the same be done with battery_state too?
You could have mentioned if you are using Android or Apple Companion app or even tagged your post with “Companion App for Android” or “Companion App for Apple”.
Did you look? The barrier to verify this for yourself is really really low.
On Android - my phone screen has been off for hours now with the app definitely not in the foreground:
Plugged it in, and before I could see the change it read like this:
I’m guessing people skills aren’t your forte or you’ve had a crap day, judging by your condescending response. Or maybe you’ve used a translation app?
I’m using the iOS companion app and I have tested it with screen off and the status doesn’t change, even when leaving it for 10 minutes or so. Definitely within my skill set!!
The only time the status changes is if the screen is unlocked and the app is running in the foreground, as I mentioned in my OP. This could be due to Apple limitations so I was wondering if there’s a way of referencing the state in the background.
This worked, though not contained wholly in HA. I’m not sure if you meant a HA iOS automation or the iOS automation as I’ve done but thank you for the heads up, silvrr.
In the iOS shortcuts app I created an automation to send the phone location to HAvevery time it’s placed on charge or removed and that solves the issue. The battery state is automatically updated in HA, almost instantaneously.
For anyone else who may be in need of this:
iOS Shortcuts app > Automation then select each of the below
“+”
“Create Personal Automation”
“Charger”
Enter ticks in “Is Connected”, “Is Disconnected” or both
“Next”
“Add Action”
Search for “Home Assistant”
“Send Location”
“Location”
Choose home location
This is great but fails when charging in the car as it sends Home and triggers all sorta bad things to happen if you’re working a lot with presence detection.