[SOLVED] Data type error, I guess

Hi,
I use Heos players around the house.
I created a nice little dashboard and some cards visibility are linked to Helpers value.

My goal is to identify if a player is in a group but NOT the group leader. In this case, I hide its card as it is linked to a group leader and I don’t need to change anything to it.

For instance, for “kitchen”, here are the different possibilities for “group_members” value

  • group_members: media_player.kitchen, media_player.office, media_player.workshop
    => result should be FALSE as it is leader of the group (first in the list)
  • group_members: media_player.office, media_player.kitchen, media_player.workshop
    => result should be TRUE as it is member of a group BUT not the leader.
  • group_members: null
    => Result should be FALSE as it is not member of a group.

To do so, I tried this :

{% set m = ‘media_player.kitchen’ %}
{% set g = state_attr(m, ‘group_members’) | list %}
{{ m in g and g|first|default(‘’) != m }}

It nearly works :slight_smile:

It gives me the correct answer BUT, if the device is not a group member at all, “group_members” is null and my test fails.

I might have some kind of variable declaration issue where the test can not evaluate the content of a null list. If it set g as a string, it works when the string is null (but fails if the string is actually a list).

Any suggestion ?

Thanks a lot !

How about just getting the first member of the list and checking that:

{% set m = ‘media_player.kitchen’ %}
{% set f = (state_attr(m, ‘group_members’) | list)[0] %}
{{ f != m }}

It make the code easier to read I will keep that ! :slight_smile:

But I still have the same error. If the group_members is NULL, it still gives me an error.

{% set m = ‘media_player.kitchen’ %}
{% set g = state_attr(m, ‘group_members’) %}
{{ g is not none and m in g and g | first != m }}

Does |first work on strings that look like lists?

No idea, but in this case doesn’t matter either way. The group_members attribute for a media player doesn’t look like a list, it is a list (assuming it exists at all of course).

Yeah sorry, forgot attributes could be other types.

Thanks a lot guys !!

It works perfectly as expected :smiley:

Have a great weekend !