Why does Entity Filter Card think 100% < 20%

At the bottom of my Overview page I have an Entity Filter Card which is usually hidden, and serves to show ‘warnings’ for devices which need updating (phone needs charging, motion sensor battery needs replacing, air purifier needs a new filter, etc):

	type: entity-filter
	entities:
	  - sensor.device_1_battery_level
	  - sensor.device_2_battery_level
	  - etc. 
	state_filter:
	  - operator: <
		value: 20%
	show_empty: false
	card:
	  type: entities
	  title: Warnings

Everything works great except that, for some reason, every morning when I wake up to a 100% phone I have a warning that my phone battery is 100%:

image
As soon as I unplug my phone and use it enough for the battery to drop to 99%, the entity disappears and the card disappears (when it’s the only entry) and everything is working as expected. And everything is indeed working as expected, because if I change the value from “20%” to say “70%”, the card is updated with the addition of several entities at between 20% and 70%.

But it seems that 100% is a special case?

Fun discovery after posting this…

If I set it to 10% it disappears, if I set it to 11% it reappears.

Then I set it to 7%, and the 100% battery reappears, as does every entity below 70%?

So maybe it’s not that 100% is a special case, but that something funny is going on with significant figures.

Also, it turns out that “20” instead of “20%” works fine, so I have a workaround. Presumably whatever is going wrong only comes into play when “%” is added to the mix?

Dont include the unit.

	state_filter:
	  - operator: <
		value: 20

By doing so you are comparing strings instead of numbers. And string comparison works on magnitude from left to right. So 9a is greater than 10000000z

1 Like