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 %}'
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 %}