Dynamically create and track users as entities from an online users sensor array?

I have a sensor that returns a list of online users e.g.

sensor.users_online

users:
  - UserA
  - UserB
  - UserC

I’d like to automatically create an entity for each unique user name returned in the sensor array and then update their state as online if present in the sensor list and offline if not present.

Any suggestions?

I think this is only possible with a python script/AppDaemon, because you can not dynamically create entities with native Home Assistant automations.

I suspected as much, understandable. In that case, what direction would I look to accomplish the same effect if I manually added each username as an entity?

Create a template binary sensor for each user and in the template check if the person of this sensor shows in your “user online sensor”.

Can you show an example value of your “user online sensor”?

What creates online users? It seems like this would be easier if you just had whatever creates that make device_trackers instead.

Not certain where to get the raw array, but the dev tools for the entity shows an int state of 1 and the following as state attributes:

users_online:
  - UserA
  - UserB
  - UserD
users_suspended:
  - UserZ
friendly_name: User Status

The sensor is polling an API I have no control over, so unfortunately the best I get is an array of assumed unique strings the system claims are online.

what’s the integration

The binary sensors should look something like this:

binary_sensor:
  - platform: template
    sensors:
      user_A_online:
        friendly_name: "User A is online"
        value_template: >-
          {{ 'UserA' in state_attr('sensor.YOURSENSOR', 'users_online') }}
1 Like

Ah, I didn’t realize “in” will set status On if its in the array and Off if not. Very clean and elegant, thank you.

Its from a REST sensor