Entity VS Device

After more than a year of using Homeassistant I haven't understood very well how to use "entities" or "Devices".

I'll give you an example:

I need to close my shutter into the bedroom...
I select the action "Close Cover".
I have the option to select two option for the same for the same thing:

  • ENTITY: Bedroom Cover
target:
  entity_id: cover.vimar_serranda_letto_copertura
  • DEVICES: VIMAR Bedroom Cover
    (where VIMAR is the Brand)
target:
  device_id: a782f7898c74908d9a1e2e100f5356f9

In both cases... I get the same result. But which of the two would be more correct or better and why?

When they yield the same result, neither is more correct.

If you are specifically asking about Device Actions, the main issue that comes into play is when the device has multiple entities in the domain of the action and they both are acted upon. This is mainly an issue with light and switch entities. This same type of issue can happen with Area/Floor targets too.

There is a Community Guide that goes over some of the issues with using Device components in general:

Most of the examples you see on these forums are going to be entity actions for a few reasons:

  • The people who answer most of the questions have been using HA for a while and are just used to using Entity actions.
  • They are less verbose, so we don't have to type as much and they are easier to read.
  • Sometimes they can do things Device actions can't.

A device is a collection of entities and one of those entities is set as the default one, so if you target the device or that entity then the outcome is the same.
In that case it really does not matter what you choose.

There is a pitfall with devices though and that is when you replace a device.
Device IDs are unique to a device and and can not be changed so if you have automations with device IDs and replace the device, then the device IDs in all automations have to be changed.
If you used an entity ID instead, then you could just change the entity ID of the new device to what the old one used and everything would be working again.

2 Likes