Phone charger on/off by battery level

I have tried this automation and it works quite ok. Android seems easy, iPhone does not communicated enough, but solvable.
I have one issue I am not sure of. The automation itself gets turned of sometimes. The tracing says "Stopped because of unknown reason at July 12, 2025 at 7:57:23 PM (runtime: 0.01 seconds). After the the automation is disabled in the HA UI. What could be going on? Would be happy to get some help or insights here.
/Thanks, Ulf

You’re switching off the automation itself instead of the switch that controls your charger. Double check your blueprint selectors for !input 'phone_charger' and make sure you have selected the correct device.

Side note: @apollo1220 you might want to change service: homeassistant.turn_off to service: switch.turn_off to avoid this situation occurring, given you’re expressly targeting a switch domain in your inputs. Using the homeassistant domain allows you to switch off practically anything, with unexpected results like this one.

Thanks for your suggestion. I can only see the phone itself and the smart plug in the automation. I see no reference to the automation itself as being turned on or off in the automation. The automation does work, but from time to time the error “Stopped because of unknown reason…” appears and then I find (maybe unrelated) that the automation is off. Below part of the code with the aphone and the switch. Do you still think I am switching off the automation?
/Thanks, Ulf

actions:

  • choose:
    • conditions:
      • condition: numeric_state
        entity_id: sensor.aphone_battery_level
        above: 80
        sequence:
      • target:
        area_id: alvaro_s_bedroom
        device_id: fd93583a66943b551717bbf28952bca1
        entity_id: switch.charging_nightstand
        action: homeassistant.turn_off

Please post the full automation and make sure it’s properly formatted.

Your previous trace screenshot shows automation.aphone_charge_control was turned off, so something must have told it to switch off the automation.