Days counting problem

Hello all,

I have a problem counting days.
It’s kind of hard to explain but I’ll try.

i have the following code:

states.sensor.limburg_net_eerst_volgende.state.split()[0]|int - now().strftime("%d")|int == 1

This code works unless today is the last day of the month. If it is the last day of the month, of course I get a negative result.
In the above case:

states.sensor.limburg_net_first_next.state.split()[0]|int

equals 1 and

now().strftime("%d")|int

equals 30.

How do I solve this.

I’ve been working on HA for a while but I really don’t know how to solve this. Find working with the time and date very complicated.

Thanks for any help.

What do you actually want?

The number of days between your sensor and the end of the month?

Thank you for your reaction.

No, the sensor is a string that I receive in the form of "01 jun: gft " I take the 01 from that and if the difference between today and the sensor is 1, there should be a certain message!

I am not at a computer at the moment, so cannot make a PoC, but I’d suggest you try to convert the sting to an actual date and then just make the sum.

See for some inspiration in converting the string: (solved) Template to convert string to date or time, with timezone conversion? - #2 by pnbruckner