iPhone battery state not updating anymore - other ways to trigger bedtime automations?

I have a couple automations that are meant to trigger an Alexa Actionable Notification and put the house in “night mode” when my phone is plugged in between 12pm-6am. For about 4 days, it worked flawlessly. It didn’t matter if I’d touched my phone in hours, if I plugged it in my automations would run immediately. If anyone’s curious here is the config:

- id: '1614470588834'
  alias: Trigger night mode with battery state
  description: If iphone begins to charge after midnight, trigger night mode actionable notification 
  trigger:
  - platform: state
    entity_id: sensor.merediths_iphone_battery_state
    to: Charging
  condition:
  - condition: and
    conditions:
    - condition: time
      before: 0:06:00
  action:
  - service: script.activate_alexa_actionable_notification
    data:
      text: Meredith, would you like me to put the house in night mode?
      event_id: actionable_notification_meredith_bed
      alexa_device: media_player.echo_dot_2
  mode: single

Then depending on whether I tell Alexa yes or no, it will run a script that turns everything off and arms alarms and such.

Yesterday the first automation just stopped triggering when I plugged in my phone. It works fine if executed manually.

I deduced that it’s the sensor.iphone_battery_state entity, it’s not updating at all anymore unless I’ve had the app open in the last 10 seconds. I’ve double checked that 20 second periodic updating is turned on and the HA app has permission to run in the background. I’m quite frustrated because I was really stoked about getting actionable notifications up and running and using it for this. But it doesn’t serve much of a purpose if I have to remember to open the app every night when I lay down for bed :weary:

Does anyone know a work around or maybe a suggestion for another way to trigger stuff like this? Maybe another app that will report state changes faster?

I’d love to rig up a bed occupancy sensor eventually but it’ll be a while before I can do that.

The periodic timer only applies if the app is open and in the foreground; for example, if it’s a wall tablet that’s always on. That setting will likely go away as more sensors move to updating instantly for that case.

What you’re relying on right now is background fetch triggering updates, and that’s entirely up to the system for scheduling. It’s less likely to occur if you don’t use the app regularly. There’s nothing the app can do to make this happen more often or more reliably.

If you want the battery state to update instantly when the app isn’t running, create a Personal Automation in Shortcuts.app for when Charging State changes and call the Home Assistant shortcut action “Update Sensors.”

5 Likes

Unfortunately I can’t use battery states within ios shortcuts or automations :confused: My phone quit updating before that was implemented in iOS 14, idk if my phone is just too old or what but I’m stuck on iOS 13 and I just get Failed to update errors every time I try. Sigh Nothing’s ever easy.

I guess I’m just going to have to wait until I can make a bed occupancy sensor or switch back to using an android which I’ve been wanting to do anyway.

@shieldmaiden95 did you ever get this issue solved? I have a iPhone XR with the latest iOS version and app. The charge state worked once and then not again.

You should read my previous post in this thread as your device supports iOS 14.

Yeah, did that, but of course, then I might as well just have a button. The point was for me to just put my phone on the wireless charger and the automation happens. Now it is, put my phone on the wireless charger and click on the shortcut. Oh well, the joys of using iOS I guess.

1 Like

The personal automation firing as a result of charging state changing does not require tapping anything.

Ah!!! Now I get it!!! Sorry, still a noob here. Created the automation in shortcuts. Thanks a lot!

No I didn’t. I ended up getting a Samsung galaxy recently anyway, works like a charm now

Ah, so you went to the dark side :grinning:

I just set up the shortcut as mentioned above. Works like a charm.

Haha I’ve always been an android person anyway, I only had an iPhone because my last job provided it.
Although I’m sort of back in the same boat again because my boyfriend now has an iPhone his work gave him and I’m having to figure out how to get his to work with home assistant. Luckily his should be on a current version of the iOS so I might be able to set up a shortcut for him.

@zacwest not sure where you mean to make the shortcut and automation, is this on the my iphone or in HA, could you please give a few more steps so I can try to get this working.

On your iPhone.

I tried to make this much harder than it is - it’s literally just selecting Update Sensors and stopping there in the building of the automation in Shortcuts. Thanks for this.

I’m seeing an error in iOS 16 but it seems like the automation is triggering so… I may pare it down to just trigger on the docking vs docking and undocking. I really don’t NEED to trigger on the undocking.