Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 102852

Templated sensor keeps returning string instead of number

$
0
0

I’m using a template sensor for battery level of my iphone. Reason for this is that the icloud3 sensors regularly report 0 for battery. This will trigger my charger automation. So i created a templated sensor which only changes value when the battery actually changes (using a textlabel from info sensor):

- platform: template
  sensors:
    frans_battery_iphone:
      friendly_name: "Frans iPhone Batterystate"
      value_template: >-
        {% set battext = states('sensor.frans_iphone_info') %}
        {% set pattern = '-(.*)%' %}
        {% set batperc = (battext | regex_findall_index(pattern)) if battext is search(pattern) else states('sensor.frans_battery_iphone') %}
        {{ batperc | int(0) }}
      unit_of_measurement: "%"

The value is consistent but my automation is not triggered. Also when i test the sensor for numeric value using template editor:

{{states.sensor.frans_battery_iphone.state > 0}} i get TypeError: ‘>’ not supported between instances of ‘str’ and ‘int’

What am i doing wrong?

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 102852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>