Template returns string instead of number

Hi Guys,.
I want to have the number of days of the current month as a number my template looks like this:

- sensor:
  - name: "Days_in_month"
    state: >
       {% if now().month in [1,3,5,7,8,10,12] %}
        31
       {% elif now().month in [4,6,9,11] %}
        30
       {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
        28
       {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
        29
       {% endif %}

but it seams that the “31” for January is a string, how to get this as a int?

thanks!

All states are strings. Whenever you use that, you have to convert it to an int. Your Template is good as is

ah ok, thanks, so my second template looks like this:

- sensor:
  - name: "test_template"
    state: >
       {% set days_this_month =  states('Days_in_month') | int %}
       {{((days_this_month)  + 100)}}

should return 131 but it returns 100 instead, is this not the way to convert?

states('Days_in_month')

Is that a sensor? Are you sure it has capital letters?

states('sensor.days_in_month') is my guess, but have a look in developer tools

:woozy_face:
that missing “sensor.” was the Problem (and i changed everything to lowercase) now it works. thank you so much!