Force entity ID

Hey!

I’m building a custom platform, and I was wondering if there was any way to override the default entity_id. Currently, it defaults to a slugged version of the initial name, but my name changes (it’s based on where the cheapest fuel is, so it’s constant changing).

This ends up with an entity ID that has the first/initial cheapest location as the ID :frowning:

Any ideas?

First of all, if you derive your entities from the Entity class, then there is a property entity_id that you should be able to set when initialising your entity.

The other thing I would like to point out that I find it rather unusual that your entity’s name changes. State changes, attribute values change, but the name normally doesn’t change; even worse, a user can easily override the name in the UI. Are you sure you want to constantly change the name? From what you are describing, it sounds as if you may want to consider storing whatever you change the name to in an attribute instead.

Thanks for the reply. I figured out a hacky way to do it (checking if it was registered yet, and basing the name on that).

Here’s the code if you’d like to take a look:

The goal was to be able to quick get a panel at a glance that provides all the info you need (the postcode is important and changes constanly)

image

1 Like