Entities in Area and Area State

I’ve created a number of Areas, 1 for the main rooms of the house.
I’ve also a number of entities created from templates that represent the lights in the rooms.
Is there a way of associating the light entities with the Areas?
Can only associate devices with Areas from the UI?

Similarly can areas have a state (occupied / unoccupied)… so that light control is linked to area state & light level or sun etc?

Cannot see this in the UI or the Docs, presence only refers to Zones rather than rooms.

I’ve seen there is a wasp-in-a-box integration in HACS but just want the simple case to start with, as wasp-box seems to require a binary sensor for room occupancy, but I’d like to use the state or an attribute on Area … if possible.

TIA

Done some more reading and seems like customize should be able to change the default entity settings
Added this, but after a restart entity still doesn’t have an area…any ideas?

homeassistant:
  customize:
    light.kitchen_main_light:
      area: kitchen

Why don’t you want set the area thru the UI?

I don’t think so. You probably will need a template binary sensor or a helper for each area to track this (and some logic to toggle this entity properly).

I’ve added all the entities via API to a 3rd party gateway using Templating , as they don’t have a Device and weren’t added via the UI, I cannot edit them that way

OK thanks … I better find more about what a Helper is and why to use them!

Can’t you add a unique_id for those entities? Entities with unique_id are available to edit in the UI.

All the entities are unique within my installation eg light.kitchen_main_light so I don’t understand why the UI isn’t working.
I haven’t found anything that says they must be a certain length or constructed in a certain way … so they look fit for purpose to me!

OK so reading more carefully, I have a unique entity_id and now a unique_id as well added via customization.
Still no joy, but thanks for the pointer, a step further on the journey :slight_smile:

homeassistant:
  customize:
    light.kitchen_main_light:
      area: kitchen
      unique_id: kitchen_main_light
      

Could you please share the template you used to create it?
On the templates you can use unique_id, no?

1 Like

I’ve beeen learning bit by bit trial and error (lots of that!) and kind help, so I may not have used the template right but here is the kitchen light template. Thanks

#
    kitchen_main_light:
      friendly_name: Kitchen Main Light
      turn_on:
        service: rest_command.cortex_light_on
        data:
          cortex_light_name: Kitchen Main Light
      turn_off:
        service: rest_command.cortex_light_off
        data:
          cortex_light_name: Kitchen Main Light
    #

updated…and now editable in the UI :smiley: Thankyou!

#
    kitchen_main_light:
      friendly_name: Kitchen Main Light
      unique_id: kitchen_main_light
      turn_on:
1 Like

I’m glad to hear that.
Well done!

1 Like

By the way, for unique_id usually I like to use real unique id, so you don’t get in trouble when you decide to rename your entity. That id is not visible anywhere, so you probably will be fine with something really unique.

I mean something like this:

unique_id: a4122571-52ef-4c49-a331-75fe6bee4580

But I see many people using just like you… It’s not really a problem.

If you are using Studio Code Server to edit your files you can right click and select the option to generate a unique id in the pop-up menu.

Thanks! Interesting that Studio Code will create a unique ID. Have to say I prefer something human readable if possible.

I think my confusion was that I saw comments on unique entity ids (and the Studio code editor complains of duplicate keys)… and hadn’t appreciated there was a separate attribute of unique_id
Out of curiosity do you know why there are 2 unique identifiers for a entity? Bit like IP and MAC addresses, operating at different levels of the inner workings of home assistant?

I don’t know exactly the reason, but probably to have one (unique_id) to be used internally by the system, which should never change, and another one (entity_id) to be more “human readable”, which can be changed.
I’m not sure about this, but I believe you can change the entity_id without major consequences, but probably you will lose historic data if you change the unique_id (the system will see as a new entity).

Thanks. One day I may experiment around!