travisghansen / hass-opnsense

OPNsense integration with Home Assistant
186 stars 25 forks source link

Feature request: Thermal Sensor Data #79

Open roadbikemike opened 1 year ago

roadbikemike commented 1 year ago

I see someone had asked about gathering thermal data in Discussions but do not see an open Issue. Would be great to have CPU thermal data sent to Home Assistant. Would like to do some automation around this metric and disappointed to not see it there.

syberx commented 1 year ago

yes very cool !!

travisghansen commented 1 year ago

I’ll get to it at some point. If you want to find out where the data is available in the api that would help preempt my research when I get a little time.

roadbikemike commented 1 year ago

I poked around some of the documented Core API functions and unfortunately could not find much regarding thermal data. However, I may have missed something. Looking at the OPNsense dashboard, the thermal data is populated using this URL:

https://opnsense.localdomain/widgets/api/get.php?load=temperature

Which returns:

{"system":"OPNsense","plugins":["interfaces","system","temperature"],"data":{"temperature":[{"device":"dev.cpu.0.temperature","device_seq":"0","temperature":"48.7","type":"core","type_translated":"Core"},{"device":"dev.cpu.1.temperature","device_seq":"1","temperature":"48.7","type":"core","type_translated":"Core"},{"device":"hw.acpi.thermal.tz0.temperature","device_seq":"0","temperature":"47.6","type":"zone","type_translated":"Zone"}]}}

Perhaps this is enough?

travisghansen commented 1 year ago

Perhaps. I’ll look deeper at some point. Just don’t have much time to put to the project currently :(

roadbikemike commented 1 year ago

Totally understand and thanks for getting back on this! Much appreciated. I will keep poking to see if there is something I am missing for thermal data in the documented API. Although, that URL does seem to be part of the API, but under widgets (which is not documented).

travisghansen commented 1 year ago

There is an underlying ‘api’ in php land that they are almost certainly using. The way the integration is designed it gives complete access to all the underlying php libs/code as well. In this particular case it’s probably a better option to figure out what the endpoint is using and use that vs using the endpoint directly.

roadbikemike commented 1 year ago

From what I can tell, this is the only way to gather thermal data programmatically at this time:

https://github.com/opnsense/core/blob/5d5e9579415c70d62e31876e4c649467f0db22b2/src/www/widgets/api/get.php

Which then references:

https://github.com/opnsense/core/blob/5d5e9579415c70d62e31876e4c649467f0db22b2/src/www/widgets/api/plugins/temperature.inc

Looks like temperature.inc executes the actual command via configd_run which returns the thermal metrics.

There is a comment in get.php which states:

Simple wrapper to retrieve data for widgets using legacy code.

Perhaps they have not moved the thermal data into the mainstream/underlying API yet.

travisghansen commented 1 year ago

Right, but the way the integration works you can just tap into the latter directly.

larhedse commented 1 year ago

Any chance this might happen?

3dRikal commented 9 months ago

Any chance this might happen?

Yep, that would be a useful feature as monitoring the SBC that runs OPNsense (at least in my case) is something I need to keep an eye on. There is no fans on that SBC and the room is shared with other warm stuff. I do it indirectly at the moment via my NAS temp but would be a nice quality of life implementation.

PilaScat commented 3 months ago

up