#Include Device ID in entity IDs to support future device replacement?

1 messages · Page 1 of 1 (latest)

quaint lion
#

I've read a few different sources that suggest you can replace a lost or broken device with a new one by using the same entity IDs. I'm pretty new to HA and still wrapping my head around the terminology. Let's use an example of 2 contact sensors, 1 each for two garage doors (East and West). When I setup my contact sensor they have default entity IDs like binary_sensor.open_close_xs_sensor_window_door_is_open_in_tilt_position - there is nothing in that entity ID that indicates what device it is, is it the East or the West door. I'm wondering if the best practice is to include some device identifier as a prefix, so using a format like <device_identifier>_<entitiy_identifier>, e.g., west_garage_door_is_open_tilt_position.

I'm not seeing a way to set a device ID in HA so I'm assuming this is mean to be left as-is, is that correct?

While I'm at it: How do you handle easily and consistently identifying real-world devices with their HA representation? Again, using my two door contact example... if I had them removed for some reason and lost track of which went with what door, how would I figure out which is which? without interacting and obersving indicators in HA. Maybe not a great example, let's try another example: I have a bin with 10 of the same smart plugs and I want to grab one that is already setup for an automation. How would I indentify it? The only thing I've come up with is to write some unique ID on the device itself with a sharpie and use that same ID in HA when I name the device. This seems effective, but not terribly clever. How do you all handle this?

I've generally been thinking a lot about these types of policies before I add too many more devices to my setup. I would like to have these policies established and in use so things are consistent and setup correctly.

quaint lion
#

I was just poking around with the File Editor App and opened Automations.yaml and was very surprised to see GUID-like identifiers intead of my entity IDs. If I replace a device and renamed the entities to match the replaced device entities, how will any of that matter of the automation references these auto-created GUID ids? I'm missing something...

#
  alias: Notify if Shop Left Unsecure After Dark
  description: ''
  triggers:
  - trigger: sun
    event: sunset
    offset: 02:00:00
  conditions:
  - condition: or
    conditions:
    - type: is_unsafe
      condition: device
      device_id: c84dd3c8c24839afdb80ee659af68f48
      entity_id: b8a3c4834559fcf7f6d8133deadc930b
      domain: binary_sensor
    - type: is_open
      condition: device
      device_id: d5963e7a2f297e0b92c851f75562aad8
      entity_id: 7ca274bbe0d5c87f1eab48e6ba863fdb
      domain: binary_sensor
  actions:
  - action: notify.mobile_app_steves_phone
    metadata: {}
    data:
      message: shop door is open after dark
      title: Shop is unsecured
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: Shop bay door is unsecure
      title: Shop is unsecure
  mode: single```
heavy cipher
#
quaint lion
#

That's an EXCELLENT article, thank you for sharing it. I'll update my automation to use the entity ID only.

#

In case anyone else comes across this, here's what I had to do:

  1. Delete my Device conditions
  2. Create new Entity conditions
  3. Select State condition and find the Entity
conditions:
  - condition: state
    entity_id: binary_sensor.shop_bay_door_west_intrusion
    state:
      - "on"
  - condition: state
    entity_id: binary_sensor.sw_man_door_door_is_open
    state:
      - "on"```