Change state of entity from REST API

I have a cloud-based integration, which updates some entities quite irregularly and depending on internet connection, which is not as good as wished for, sometimes also not. Let’s call this entity sensor.cloudbased_temperature.

However, I also have a physical sensor listening on the UART of my actual device, which pushes the measured value to my MQTT. Let’s call this sensor.uart_temperature.

Now I want my MQTT-based sensor state to be “pushed” over the state from the cloud-based integration. There are good reasons to do so, because some feature can only be controlled over the cloud. So, I want sensor.cloudbased_temperature to always have the state of sensor.uart_temperature.

Right now, I am using the REST-API. However, it seems to me that I always have to send the whole entity including all attributes.

So my questions are:

  • Is this how you should do it? or is there a more clever way?
  • If yes (use REST-API), is there a way to just change the state and leaving the attributes untouched?

Many thanks!

Since you’re just speaking in hypotheticals, it’s really hard to know what you’re actually trying to accomplish with this overwrite. Why not just use the local sensor instead of the cloud sensor in automations and display? Maybe you should use a template sensor? If this is a weather entity, perhaps you should build a custom weather entity that includes the local sensor and all the cloud stuff? I’m just guessing based on your names that might be what you’re doing.

Generally you can’t really overwrite a state. States aren’t meant to be changed by anything other than the thing that created them. Maybe if you post a concrete example and tell us exactly which integration you’re using someone could help more.

Kyle, thanks for your feedback. I try to remove all hypotheticals.

I have a heat pump, it is heating our home as well as preparing hot water. The only possible solution to communicate with the heat pump is via a custom component, that utilizes the official cloud api of the manufacturer of the heat pump. I am very happy with the custom integration, it works very well and I can control my domestic hot water as well as floor heating temperatures by the entities of the cloud-based integration via climate / water_heater entities.

However (!!), the cloud api has quite restrictive rate limits, so that new data only arrives in Home Assistant (and also in the manufacturers own iOS App) every 30 minutes or less (at night time even 60 min).

To improve the situation, I have put an ESP to the serial port of the heat pump. I now get more precise temperature values from the physical heat pump, (up to every second). I expose that data to MQTT so that it is available in Home Assistant.

My goal is to “fill in” the missing data from 30 minute gap with cloud data. So: I want sensors.my_own_water_temp_via_uart to “overwrite” sensors.heatpump_cloud_api_water_temp.

My current solution is to have an external programm subscribe to MQTT and use HA REST API to overwrite the integrations entities. I have noticed, that I also need to overwrite the full entity, including attributes.

Now I was wondering, I there might be a simpler way of doing this.

(It will come down to approx. 6 temperatures, 4 of them as entity state, 2 of them as entity attributes).

Last: my heat pump can only send data over serial, not receive. So I still have to rely on the cloud-based custom integration in order to change set-point temperatures or backup heaters).