Set "area" for template entities?

Is there a way to set the area of template generated entities (switch/binary_sensor/sensor)?

2 Likes

No. Areas are for integrations only.

That’s unfortunate. With areas being more prominent in 0.93, this makes template entities less useful.

Is it possible that template becomes an integration, and can be configured to use areas like the other integrations (zwave, deconz, mqtt, etc.)?

1 Like

So that’s still the case?

Really unfortunate … I have 2 lamps/bulbs that are joined together via template, and I can’t assign this template/light to an area … so the hole area concept is rather unusable.

1 Like

I might require this feature also. With a bit of help (at least pointing me some github URLs), I could help to work on it.

Debug / Infos

I’m trying to build cards auto-entities per area, using this kind of filter :

type: 'custom:auto-entities'
card:
  title: Lumières Salon
  type: entities
filter:
  include:
    - domain: light
      area: Salon
sort:
  method: name

I have a smart plug (switch) where a dumb light is plugged. I would like to make this switch considered like a light, that’s where light.template becomes useful.

Using a randomized unique_id I was able to set Salon area to my entity from the Web UI.

light:
  - platform: template
    lights:
      lampe_salon:
        friendly_name: "Lampe Télévision"
        unique_id: 0e564a2b1013f7e3a77f74038077127c
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.05253636bcddc253c7b5 
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.05253636bcddc253c7b5

Then, I’m reaching the issue mentioned here, where templated entities aren’t listed inside area, even if its set.

Over 2 years later, and it is frustrating that these entities STILL cannot be assigned an Area.
I have an assortment of devices, helpers and other entities to control a heater. I can group everything together as “Heater - Dining Room” except for my templated binary sensor, which sits in it’s own card.

The UI even specifically states that I cannot set the Area because I don’t have a unique ID, yet adding the unique ID doesn’t fix it.

-template
  - binary_sensor:

    #setting either of these settings removes the sensor from the UI !
    #- device_class: heat

    - unique_id: "dining_heater_on_off_binary"  #even with an assigned uniqueid, cannot be edited in the ui: https://www.home-assistant.io/integrations/template/
    - name: "Dining Heater On/Off Binary"

      state: >
        {% set heater_on = as_datetime(states("input_datetime.dining_heater_on_time")).astimezone() %}
        {% set heater_off = as_datetime(states("input_datetime.economy_7_local_end_time")).astimezone() %}
        {{ heater_on < now() < heater_off }}

Greg - Did you make sure to restart HA? That’s all it took for me. Also your example has a hyphen before unique_id and name which seems odd.

Otherwise, I definitely agree it would be nice to just specify “area” in the template YAML :frowning:

It didn’t fix it because unique_id wasn’t added correctly.

The first line shown in your example is incorrect. Not like this:

-template

Like this:

template:

To add unique_id to a Template Sensor’s configuration, ensure it’s actually part of the sensor’s configuration. The way you did it above makes unique_id a part of nothing.

Correct format:

template:
  - binary_sensor:
      - name: "Dining Heater On/Off Binary"
        unique_id: "dining_heater_on_off_binary"  
        state: >
          {% set heater_on = as_datetime(states("input_datetime.dining_heater_on_time")).astimezone() %}
          {% set heater_off = as_datetime(states("input_datetime.economy_7_local_end_time")).astimezone() %}
          {{ heater_on < now() < heater_off }}

I can confirm that when a Template entity has a unique_id it can be assigned to an Area.

1 Like