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

Added GPU sensors to output #20

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

neuralyze
Copy link
Contributor

add the necessary GPU sensor parsing for the Glances component in Home Assistant.

Copy link

@fhoekstra fhoekstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I noticed your PR just as I happened to start working on this myself.
Thanks for putting in the work! Please feel free to ignore my suggestion if you already have working code for the Home Assistant component ready.

Comment on lines +167 to +173
sensor_data["gpu"][f"GPU_{sensor['gpu_id']}__{sensor['name']}"] = {
"name": sensor["name"],
"temperature": sensor["temperature"],
"mem": sensor["mem"],
"proc": sensor["proc"],
"fan_speed": sensor["fan_speed"] if "fan_speed" in sensor else 0,
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using more descriptive names here in the glances-api package already instead of doing the translation in Home Assistant?

Suggested change
sensor_data["gpu"][f"GPU_{sensor['gpu_id']}__{sensor['name']}"] = {
"name": sensor["name"],
"temperature": sensor["temperature"],
"mem": sensor["mem"],
"proc": sensor["proc"],
"fan_speed": sensor["fan_speed"] if "fan_speed" in sensor else 0,
}
unique_name = f"GPU_{sensor['gpu_id']}__{sensor['name']}"
sensor_data["gpu"][unique_name] = {
"name": sensor["name"],
"memory_use_percent": round(sensor["mem"], 1),
"processor_use_percent": sensor["proc"],
"temperature_celsius": sensor["temperature"],
"fan_speed_percent": sensor.get("fan_speed", 0),
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that adding the unit of measurement to a sensor name could be problematic as I'm frankly not sure if the return value could depend on the system's settings (Celsius vs. Fahrenheit, etc.).

Copy link

@fhoekstra fhoekstra Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Home Assistant interface will need to display a unit anyways so I figured the closer to the source we resolve the ambiguity, the better.

I based myself on the comments in this part of the glances codebase to be sure about the units:
https://github.com/nicolargo/glances/blob/develop/glances/plugins/gpu/model.py#L278

A bit further up in that same file, I see a mention of Fahrenheit conversion but that seems to be only for the GUI, not the API

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API HOST 61208/api/3/gpu
[{"key":"gpu_id","gpu_id":0,"name":"Tesla P4","mem":26.248677571614582,"proc":0,"temperature":42,"fan_speed":null}]

@cohenchris
Copy link

cohenchris commented Oct 4, 2023

@fabaff Any update on this? Would love to have GPU support integrated.

Copy link
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@fabaff fabaff merged commit a01ad9d into home-assistant-ecosystem:master Oct 20, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

None yet

5 participants