Problem listing all devices in home state (Grouping sensors with same state)

I’m trying to create a group/sensor that will list all the devices that are home and another group/sensor that show all the devices NOT home… then display those two on the dashboard.

The way I decided to do this is to create a sensor that loops through all the states in device_trackers and lists the ones that are home. The problem I get is that the result is more than 255 characters and i get an error because they all do not fit in a sensor. See here:

- platform: template
  sensors:
    devices_home:
      friendly_name: "Devices Home"
      value_template: >-
       {% for state in states.device_tracker -%}
       {% if state.state_with_unit == "home" -%}
       {{state.name}}
       {% endif %}
       {%- endfor %}
    devices_away:
      friendly_name: "Devices Away"
      value_template: >-
       {% for state in states.device_tracker -%}
       {% if state.state_with_unit != "home" -%}
       {{state.name}} ({{state.state_with_unit}})
       {% endif %}
       {%- endfor %}

Is there another way to do this by grouping sensors that belong to a specific state?

-------------------------EDIT-------------------------
Now that I think about it some more, I realize this may not be possible because group items are rendered on restart so you can’t have sensors dynamically jump from one group to another.

I think my only option may be to narrow down the criteria for which devices I watch to track that are home (or not home).

I just created a devices group. Downside is that you see everything at once (including away devices). Upside is that you don’t have to deal with the crap you are dealing with.

For what its worth, I don’t think there is a work around for the 250 characters for a template sensor.

You could abbreviate the names by removing letters too, this example would allow 25 devices:

{%- for s in states.device_tracker | selectattr('state', 'equalto', 'home') -%}
{{ s.name[:10] }}, 
{%- endfor -%}

I haven’t tried it myself but I believe that the awesome custom-ui repo can do that.

Pretty sure you can, I just haven’t dove into that personally.