Convert String Template to number

Need some help and its probably simple but i’m missing something. This is my first real forray into templating even though iv’e been using HASS for years.

I have a template sensor that counts the number of active motion sensors. However it outputs it as a string.

"{{ expand('binary_sensor.internal_motion') | selectattr('state', 'eq', 'on') | list | count }}"

I am trying to convert it to a number, so that when the number increases i can trigger a counter.

Probably better ways to do it, but this is very simple :slight_smile:

{{(expand('binary_sensor.bedroom_heating_calibrated') | selectattr('state', 'eq', 'on') | list | count) | float}}

But count should already give you an int to my understanding and not a string. Any chance that your wrapping in quotes is causing the conversion to string?

Show the rest of your template sensor config.

Do you have a unit_of_measurement defined?

State values are always strings. However entities with a unit are treated as numeric.

Dimitri Solved it.

Heres the template:

{{(expand('binary_sensor.internal_motion') | selectattr('state', 'eq', 'on') | list | count) | int}}