I have created a helper group called “HelperGroupSensorBatteryDriven” which contains all of my battery driven devices.
For testing purposes, based on that group, I’m trying to create a template to be used for later telegram notifications. The notification should include the battery state of all battery driven devices inside that group which have a battery state below 20%. In addition the notification should also include the “area_alias” (which is mapped within the “tools.jinja” file) for every according battery driven device.
This is the code I have for the template currently:
The following devices/areas have devices on low battery state: {{" \n "}} {% from
'tools.jinja' import area_alias %} {% set batterydrivendevices =
expand('sensor.helpergroupsensorbatterydriven') |
selectattr('state', 'lt', '20') | list %} {%- for batterydrivendevice in
batterydrivendevices %} {{-" \n -"}} {{ (batterydrivendevice.name) }}: {{
area_alias(area_name(batterydrivendevice.entity_id)) }} {%- endfor %}
This almost works, it does list the devices from the helper goup with the correct “area_alias” per device but the problem is that there are also devices being listed that are obove the 20% battery state. It seems that the “lowerthan” operation cannot handle string values the way I want it to be with this code:
selectattr('state', 'lt', '20')
How would the correct code look like to map the ‘state’ string value into a float value so that the “lowerthan” operation works as intended?
Thanks for any help in advance!