Battery State Automation

Hi

I want to turn off a light when I place my phone on charge but the automation below won’t work.

The battery state definitely changes when I place the phone on charge so I’m not sure what I’ve gone wrong.

Can anyone please help with where I’m going wrong with this?


- id: office_lamp_off
  alias: Office Lamp Off
  trigger:
    - platform: state
      entity_id: sensor.iphone_battery_state
      to: “charging”
  action:
    - service: light.turn_off
      entity_id: light.play_bar_3

Ok, I’ve actually worked it out by trial and error. It was as simple as changing the ‘c’ in charging from lower to uppercase.

I’m surprised that was the only mistake. Your original example also uses curly quotes:

      to: “charging”

when it ought to use standard quotes (either double or single):

      to: "charging"

I think that must have been more to do with the copy and paste, for some reason, because I’ve checked the code and it shows standard quotes in HA.

This is quite probably the most common mistake made, although improper quote usage may tie it.