REST API and unique id

Home Assistant’s REST API documentation shows that you can create an entity and update the state of the entity with just one HTTP POST request to URL POST /api/states/<entity_id>. This works to mostly, but the entities created are lacking “unique id”, which prevents e.g. renaming them from the UI.

I suppose I would need to register the entity somehow, but the REST API documentation does not seem to contain any information on that topic. I would be happy if someone could point me to right direction. Basically, I’m looking a way to create an entity by using the REST API, so that it would be a fully fledged entity. Is that even possible with just REST API?

2 Likes

Did you manage to figure this out at all please? I’m having the same issue. I can’t find out how to delete the “test” entities I made whilst poking around in the API :confused: thanks

Hello,
this thread is getting old, but I’m facing the same thing right now.
Can anyone help on that?

@asgrim, you can delete such entities via an http delete.

thanks
martin

1 Like

Also interested in doing this. I am able to create an entity via the REST API, but it doesn’t have a unique ID and is deleted upon a HA restart.

How are you creating it? As an example, here’s one of my sensors:

- platform: rest
  resource: https://api.carbonintensity.org.uk/regional/regionid/8
  name: "West Midlands carbon intensity"
  unit_of_measurement: 'g/kWh'
  value_template: '{{ value_json.data.0.data.0.intensity.forecast }}'
  scan_interval: 600

No unique ID, but HA queries the resource at startup and the sensor is “live” by the time the system has fully come up.

From the rest API directly: /api/states/<entity_id>. I’m trying to create a new entity in HA from another application via the REST API.

I see. Options are to use the HA restart to trigger this application to re-send the state; configure the entity manually in HA YAML and just update via the API; or “mirror” it via an automation into an input_number (or whatever helper type is appropriate) which will survive a reboot.

Hello,

Same question here. I read Troon’s solution, but … I don’t understand it.
And i Have the same problem with entities created from appDaemon.

Thx for your help

See:-

Thanks this also helped me!

We should see rest API as update only.

Just create your sensor via a template first, you can even do this via the UI now:
Settings → devices&services → helpers → template

The next api call will update that sensor:
/api/states/sensor.shared_energy