I have looked around but I’m not seeing anything “official” so I figured that I’d ask here before attempting to try something hacky…
I have a cloud_polling
integration which polls the API for a time-tracking service. This service allows editing of a recorded span while it’s in progress.
As the name/description is the most meaningful aspect, that is what I use for the sensor’s state.
This means that there’s always the chance that the user will change the state of the entity externally in between poll/refreshes which will result in the sensor/entity’s state being recorded “incorrectly” in HA.
Example:
- t0: User clicks button / uses external source to start the timeline. User forgets to apply a
description
. The ID for this particular event is1234
. - t1: HA polls API, gets back
id:1234, description: ''
- t2: User realizes their mistake, changes description to
someExampleString
- t3: HA polls API again, gets back
id:1234, description: someExampleString
- t4: HA polls API again, gets back
id:1234, description: someExampleString
- t5: HA polls API again, gets back
id:1234, description: someExampleString
N
sample intervals elaps- tN: HA polls API again, gets back “No event in progress”
When the user checks with the canonical source of truth / the API that I am polling, they will only see that an event titled someExampleString
was happening between t1
and tN
.
Since this sensor does not have a unit_of_measurement
, the history graph card in HA will show TWO distinct states: between t1
and t2
there will be a color block for the ‘empty’ string and then finally from t3
until tN
the history display will show a single block of color for the someExampleString
state.
Since the API that I am polling uses the same UUID for the entire event duration, i can detect that the same event is still in progress but the user has changed the description/name of the event.
Is there a way to “backdate” the state of an entity so the recorded history in home assistant matches the canonical source?
Question
Is there a way that I can update the state retroactively? Can I communicate with the recorder
platform to change/merge/edit the state(s) for a sensor between some time span? E.G.: “from $now to -700 seconds ago, please eliminate all recorded state changes and just record someExampleString
”?
Other alternative
The other alternative is to not use the user-provided description for the actual entity/sensor state and instead record just the UUID for the timeline as the state but put the name/description that belongs to the UUID in the attributes. This would give me the consistent history graph but would be very user unfriendly since they’ll have to consult the entity attributes for the last known name/description and the primary sensor state would just be some UUID.
I’d like to avoid this since it just feels wrong / like an anti-pattern to have sensor.my_cloud_poll_sensor_name
with a state of 1234
but an attribute of name: someExampleStringHere
instead of the state of someExampleStringHere
with an attribute of id: 1234
.