core icon indicating copy to clipboard operation
core copied to clipboard

On a Helper Sensor: Entities no longer have a state class

Open M4RCCR4FT opened this issue 1 year ago • 9 comments

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 image

The helpers image

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.

image

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

M4RCCR4FT avatar Oct 05 '24 19:10 M4RCCR4FT

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 close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign template Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove 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)

home-assistant[bot] avatar Oct 05 '24 19:10 home-assistant[bot]

How does your device push new state?

joostlek avatar Oct 05 '24 19:10 joostlek

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)

M4RCCR4FT avatar Oct 05 '24 19:10 M4RCCR4FT

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?

joostlek avatar Oct 05 '24 19:10 joostlek

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.

NateEaton avatar Oct 05 '24 20:10 NateEaton

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

joostlek avatar Oct 05 '24 20:10 joostlek

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)

M4RCCR4FT avatar Oct 06 '24 07:10 M4RCCR4FT

I have no clue how the rest API works. But my current suspicion is that the measurement you post makes the state class dissapear

joostlek avatar Oct 06 '24 07:10 joostlek

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).

gjohansson-ST avatar Oct 15 '24 20:10 gjohansson-ST

Thank you, it's indeed working with that change! I agree to close this ticket.

M4RCCR4FT avatar Oct 16 '24 10:10 M4RCCR4FT

(maybe the API documentation should be updated...)

M4RCCR4FT avatar Oct 16 '24 10:10 M4RCCR4FT