Group tracker state

Hello!
I am wondering if it is possible to use group in badges and see the state of device tracker.

Here is the issue

Last two are groups and state is written inside the circle. I can not figure out how to make this work.
What am i doing wrong?

It looks like you have it working for group.family . Are all of the entities in the group.apro_r device_trackers ?

Actually, family is not working too. I mean I need the state to be under the circle like it is in first 3 device trackers.
And yes, group.argo_r consists only of device trackers. I just changed the icon

Have you tried adding the unit_of_measurement attribute and setting it to the current state? You can try it from the States page. If that works, then I think the only way to do this is to write a python_script to set that attribute, and have an automation call it whenever the state changes.

Did not find how to do that from States page, But I added unit_of_measurement in Customization

On the States page, you click on the entity, and it populates the area at the top of the page. Then you edit it to add the attribute and click SET STATE. That’s only a test and it’s temporary. The next time the entity updates itself it will overwrite what you just wrote to the state machine.

So, if you want to use this technique, here’s a python_script you can use:

if 'entity_id' not in data:
    logger.warning("===== entity_id is required if you want to set something.")
else:
    data = data.copy()
    inputEntity = data.pop('entity_id')
    inputStateObject = hass.states.get(inputEntity)
    if inputStateObject:
        inputState = inputStateObject.state
        inputAttributesObject = inputStateObject.attributes.copy()
    else:
        inputState = 'unknown'
        inputAttributesObject = {}
    if 'state' in data:
        inputState = data.pop('state')
    logger.debug("===== new attrs: {}".format(data))
    inputAttributesObject.update(data)

    hass.states.set(inputEntity, inputState, inputAttributesObject)

You would use it something like this:

- alias: Update group
  trigger:
    - platform: state
      entity_id: group.argo_r
      to: 'home'
    - platform: state
      entity_id: group.argo_r
      from: 'home'
  action:
    service: python_script.set_state
    data_template:
      entity_id: group.argo_r
      unit_of_measurement: "{{ trigger.to_state.state.title() }}"

Interesting. I had not really looked at this before. But as @pnbruckner suggests, adding a unit_of_measurement to the group, changes the display. In the first example I just have badges for device_tracker.doug and group.people (which contains several device trackers). In the second, I adde the lines below into customize.yaml. Although, it doesn’t let me assign an icon.

55%20AM

47%20AM !

group.people:
  friendly_name: 'Family'
  unit_of_measurement: 'Status'
  icon: 'mdi:people'
1 Like

Thank you a lot, it works!

47
The only thing is - language. It writes in English.

Actually I was surprised that it is not built in HA. Maybe I should open an issue on github or something else?

By the way, using your script HA writes “not home” instead of “away”. Again, it si not critical, but it should be nice and smooth in future by default

10

1 Like

True. Try something like this:

    data_template:
      entity_id: group.argo_r
      unit_of_measurement: >
        {% set s = trigger.to_state.state %}
        {% if s == 'home' %} Home
        {% elif s == 'not_home' %} Away
        {% else %}
          {{ s }}
        {% endif %}

Obviously change Home and Away to your language. And you can add other elif’s if you want to change other states, too.

1 Like

Thank you again. Now everything is like I wanted to see :slight_smile:

1 Like