Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add device_class to published sensors #470

Closed
paulhomes opened this issue Feb 23, 2025 · 6 comments
Closed

Feature request: add device_class to published sensors #470

paulhomes opened this issue Feb 23, 2025 · 6 comments

Comments

@paulhomes
Copy link
Contributor

I noticed when trying to do Home Assistant charts (the built-in ones) comparing power sensors from emhass with other power sensors that they end up on different charts and so are harder to compare as a result. I believe this is because the emhass power sensors don't include the device_class attribute whereas the other power sensors I have in HA do. I tested this by building a custom emhass docker image adding in device_class and publishing the sensors with a different prefix. Those sensors do end up on the same chart as the other non-emhass power sensors.

Here is an image to demonstrate:

Image

The top chart shows the PV power forecast from emhass and the bottom chart shows the other power sensors and the PV power forecast from my custom emhass build that includes device_class.

What are your thoughts on adding the device_class attribute to the emhass published sensors? I'd be happy to submit a pull request if you think it would be a useful addition.

@davidusb-geek
Copy link
Owner

Hi Paul, yes that would be an improvement.
Happy to accept a PR for this.

@purcell-lab
Copy link
Contributor

@paulhomes Great work on the PR.

Can this approach to updating the sensors in the registry also be used to supply the unique_id field in the registry as well?
davidusb-geek/emhass-add-on#91

@paulhomes
Copy link
Contributor Author

paulhomes commented Feb 25, 2025

I had a similar experience to that mentioned in issue 91. Last week I tried to use the HA REST API to post unique_id on something else I was working on and didn't have any success. It seems like you need to running inside HA using the native API to be able create a sensor with unique_id, or publish via something like MQTT.

There is a suggestion to pre-define the sensors in yaml so the post is just updating existing sensors. I tried that and found I had to provide a state value in the yaml. That state value was updated when I posted but on HA restart went back to the yaml specified state (until the next post). I ended up using an input_number to post to and a template sensor overlayed on top - it was messy and I wouldn't recommend it.

@purcell-lab
Copy link
Contributor

Thanks @paulhomes

@davidusb-geek
Copy link
Owner

Let's close this as completed ;-)

@paulhomes
Copy link
Contributor Author

Thanks @davidusb-geek for your help in getting this added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants