Sensor not up-to-date?

Hello,

I have a group of booleans. Each boolean gives the status if a person is at home. Now I want to count the people in my house, so I created this template :

    - name: number_of_people_home
      unit_of_measurement: "pers"
      state: "{{ states|selectattr('entity_id','in',state_attr('group.group_my_people','entity_id'))|selectattr('state','eq','on')|list|count }}"
 

This works fine, but it is not updated when a one person leaves or comes home.

How can I resolve this ?

I think you need to:

  • add a numeric helper
  • update the helper with an automation when someone comes home (or leaves)

Found a solution :

- trigger:
    - platform: event
      event_type: event_template_reloaded
    - platform: homeassistant
      event: start
    - platform: state
      entity_id:
        - input_boolean.toggle_xxx_is_thuis
        - input_boolean.toggle_yyyy_is_thuis
        - input_boolean.toggle_zzz_is_thuis
  sensor:
    - name: number_of_people_home
      unit_of_measurement: "pers"
      state: "{{ states|selectattr('entity_id','in',state_attr('group.group_my_people','entity_id'))|selectattr('state','eq','on')|list|count }}"

Yup, something like that.
(please mark as solved)

Not sure if that’s exactly what you’re looking for, but as of 2022.4, zones like “home” have the number of persons in it as their states.

1 Like