Dont know why it give me an error message

So i tried making a sensor that says when my phone battery is high, medium or low.
This is the Code.

Battery:

        friendly_name: Battery Status

        value_template:

          '{% if state_attr("sensor.hannes_iphone_battery_state_2", "battery") >= 70 %} Battery is high

          {% elif state_attr("sensor.hannes_iphone_battery_state_2", "battery") <= 30 %} Battery is low

          {% else %} Battery is medium

          {% endif %}'

In the template editor it just worked fine.

You are using a multi-line template but are using quotes outside of the template.

Add a > after “value_template:” and the remove the outside single quotes from around the entire template.

It still gives me an error message:

Invalid config for [sensor.template]: invalid slug Battery (try battery) for dictionary value @ data[‘sensors’]. Got OrderedDict([(‘nextsunrise’, OrderedDict([(‘friendly_name’, ‘Next Sunrise’), (‘value_template’, “{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(’%d %B %H:%M’) }}”)])), (‘nextsunset’, OrderedDict([(‘friendly_name’, ‘Next Sunset’), (‘value_template’, “{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(’%d %B %H:%M’) }}”)])), (‘dayofyear’, OrderedDict([(‘friendly_name’, ‘Day Number’), (‘value_template’, “{{ now().strftime(’%j’) }}”)])), ('weekof… (See ?, line ?).

yes, the error tells you that you can’t use capital letters in the sensor name. It’s telling you to use “battery” instead.

Also you might need to convert the attribute to a number to do the compare so I put that in too.

I rewrote the entire section and I am not getting any errors:

sensor:
  - platform: template
    sensors:
      battery:
        friendly_name: Battery Status
        value_template: >
          {% if state_attr("sensor.hannes_iphone_battery_state_2", "battery") | int >= 70 %} Battery is high
          {% elif state_attr("sensor.hannes_iphone_battery_state_2", "battery") | int <= 30 %} Battery is low
          {% else %} Battery is medium
          {% endif %}

Ah ok. Thank you for your help.