How to define sensor updated only with API

Hi,

I would like to define a humidity sensor which will exclusively be updated from an API call from an external machine.

How could I achieve something like that?

Thank you

Mirko

Show use the api call and we can help you. Now we don’t know what kind of api call you make, so we can’t guide you.

I don’t think that you are able to do that using standard HA sensors as they are all update their state when a new reading arrives.
So your option is a custom sensor or a completely different approach.

Could you tel us what’s your ultimate goal?

I have a humidity sensor attached to raspberry pi and I would like to push the reading to HA using the HA API. I could use a Input Text or something like that, but there should be a better option.

I would call the native HA API to update (POST) the sensor state.

I think REST API is exactly what you need.
also, take a look at this.

Yes, I know, but what object do I have to create first to push the values to?

did you read the first link? it reads " POST /api/states/<entity_id> Updates or creates a state. You can create any state that you want, it does not have to be backed by an entity in Home Assistant."

So when you do “POST http://localhost:8123/api/states/sensor.my_rpi_humidity” (see examples for details) HA will create/update sensor.my_rpi_humidity.

I did and misunderstood that part. Thank you for helping me out.