Convert of sensor string to int

Hi everyone,

I’ve started with developing inside of HA, but I’m a bit confused about the conversion from a string value into an integer.

I created me a helper which is counting values from my “NINA”-Identities. The Helper seems to be working - because a got a string back with a count value “1”.

However, if I now try to convert this into a int-value to use it for example a for-loop I got an error message:

Could someone explain me, what I’m doing wrong here? I’m using HA Version 2023.12.3 (Core) on a raspberry pi 3.

We’d need to see what the sensor actually contains as a value.
Can we see what the states table shows for that sensor.

Change the int to int(0) and let me know what the template reports.

{% set anzahl_aktuelle_warnungen = states('sensor.nina_warnungen_anzahl_straelen') %}
{{ anzahl_aktuelle_warnungen | int(0) }}

If it reports 0 then it implies the sensor’s state value is not a number and cannot be converted to an integer value.

I tried it with int(0) and indeed I get “0” back as value.

Inside of that states table it shows String with the value 0:

But is it not possible to convert this string into an integer?

HI There,
I solved this now for me on this way, that I created a helper which directly returns an integer value.