Home Assistant Template

Home assistant’s Person entity can be used to show if some one is home or away and room assistant can then show which room someone (or at least someone’s BLE device is).

In order to get a single feedback on where someone is I created a template sensor to show a Room if they are detected in one or Home/Not home based on the the person sensor, which in our case is currently controlled by pinging our phones.

      friendly_name: "Jane Location"
      value_template: >
        {% set id = states('person.jane') %}
        {% if states('sensor.jane_watch_room_presence') != 'not_home' %}
        {% set id = states('sensor.jane_watch_room_presence') %}
        {% endif %}
        {{ id[0]|upper}}{{id[1:]|replace('_',' ') }}
        short_name: "Jane"
        type: "location"
      icon_template: >
        {% set loc = states('sensor.jane_location') %}
        {% if loc == 'Office' %}
        {% elif loc == 'Living Room' %}
        {% elif loc == 'Bedroom' %}
        {% elif loc == 'Kitchen' %}
        {% elif loc == 'Home' %}
        {% else %}
        {% endif %}

The above returns a Room name or Home or Not Home with an appropriate icon for the room we are in. It sets the value from Room Assistant unless it is reporting “not_home” , otherwise it uses the value from the person entity, tidying the result to a nice capitalised field. One of the reasons for this is that we only have 4 RA devices currently so some rooms are not covered.

{{ states('binary_sensor.office_motion') == 'on' or states.sensor|selectattr('state','eq','Office')|selectattr('attributes.type','eq','location')| list| count > 0}}

The above is used in a Room Occupied Binary Sensor, which is then use to detect requirements for lighting or heating. The advantage with this method is the type and state filters mean adding additional people is just a case of adding an additional location type sensor as shown above.