Automation based on list entries of a sensor

Hi all,

sorry for the bad title. I try to automate something with the new Minecraft integration.
There is a sensor called sensor.minecraftserver_players_online which contains an array of the currently players. You can view it with the following template:

{{states.sensor.gruebelgrotte_players_online.attributes.players_list}}’

If someone is online you get a list of the usernames like this:

‘[‘PlayerA’, ‘PlayerB’, ‘PlayerC’]’

I want to make some automations based on users which are going online or offline.
So I need a trigger when a username is in the list and when a username is going out of the list.
Can someone help me with this?

Is it just one username?

If so, here’s the idea:

  1. create a binary template sensor player_xxx_online
  2. in its value_template check if xxx is in players_list and return the result of the check.
  3. create an automation that reacts to state of your sensor from p.1

that’s it

Hi,

there are multiple usernames inside the attribute.
Your idea sounds good but how do I check if there is a username inside the list when there a more then one in it?

by writing some code? have you tried? something like

{{ 'PlayerB' in states.sensor.gruebelgrotte_players_online.attributes.players_list }}

Or to prevent errors if the entity isn’t ready during start up use this format:

{{ 'PlayerB' in state_attr('sensor.gruebelgrotte_players_online', 'players_list') }}
1 Like

sure. I just didn’t want to confuse the TS based on his previous responses :wink:

1 Like