On a Helper Sensor: Entities no longer have a state class
The problem
Splitted issue from #127363 on request
After upgrading to 2024.10.1 I get "Entities no longer have a state class" messages. To be precise I've 8 of those messages and those 8 sensors are made by hand as helpers.
The messages
The helpers
Four sensors get their data pushed from a small python script on a raspberry pi's. The other four from two pi zero's with a little script.
What I observed is that after a reboot, before a RPi pushed a new value, there are no errors. After a push the error apears.
If I open the settings of such a sensor I see a State class "meting" (Measure in dutch). Resending/updating doesn't make any difference.
What version of Home Assistant Core has the issue?
2024.10.1
What was the last working version of Home Assistant Core?
2024.9.3
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Helper template sensors
Link to integration documentation on our website
https://www.home-assistant.io/integrations/template/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of template can trigger bot actions by commenting:
@home-assistant closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign templateRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.
(message by CodeOwnersMention)
template documentation template source (message by IssueLinks)
How does your device push new state?
headers = {"Authorization": f"Bearer {bearertoken}", "content-type": "application/json"}
url = f"http://{ip}:{port}/api/states/{tempsensor}"
data = {"state": dhttemp, "attributes": {"unit_of_measurement": "C", "icon": "mdi:thermometer"}}
response = post(url, headers=headers, json=data)
url = f"http://{ip}:{port}/api/states/{vochtsensor}"
data = {"state": dhtvocht, "attributes":
{"unit_of_measurement": "%", "icon": "mdi:water-percent"}}
response = post(url, headers=headers, json=data)
I think that one of the attributes you have to send is the state class as well, can you maybe give that a shot to add as well?
I have this same issue as of 2024.10.1 (I had skipped 2024.10). The error is reported on a sensor group that I created through the Helper UI earlier this year. It consists of a set of battery level sensors.
I have not tried to delete it although it appears I could delete it (assuming 127363 doesn't interfere) and recreate it with YAML and explicitly specify a state class but as this is being tracked as an issue I'm inclined to watch this thread to see what its resolution will be.
That sounds like the bug with the group integration, I think there is an issue open for that one as well which is more interesting to follow
I think that one of the attributes you have to send is the state class as well, can you maybe give that a shot to add as well?
Thank you for your swift respons! Could you give me another pointer on how to do that, as I implemented the exact example in the API Docs here https://developers.home-assistant.io/docs/api/rest/ (See post api/states)
I have no clue how the rest API works. But my current suspicion is that the measurement you post makes the state class dissapear
The data needs to include the state class also as you have created template sensors with a state_class but since you're updating it's state from "outside" you also need to include that in the data you send in.
data = {"state": dhttemp, "attributes": {"unit_of_measurement": "C", "icon": "mdi:thermometer", "device_class": "temperature", "state_class": "measurement"}}
I think we should close this issue as it's not an issue with the repairs (as they are actually correct).
Thank you, it's indeed working with that change! I agree to close this ticket.
(maybe the API documentation should be updated...)