richibrics / IoTuring

Your Windows, Linux, macOS computer as MQTT and HomeAssistant integration

Home Page:https://pypi.org/project/IoTuring/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

implement CPU-Temperature (linux)

Baxxy13 opened this issue · comments

I found your nice Project und used it to push the system data of an proxmox-server into an Homeassistant.
Works without problems since on week.

The only sensor i miss is cpu-temperature.
Is it possible to implement such sensor?

Hi, could you please run this short script in python and send me the output ? Thank you

import psutil

if __name__ == "__main__":
    print(psutil.sensors_temperatures())

You need psutil to run this, but you should already have it since you're currently using IoTuring

Hi, sorry for late reply.
I'm not very familiar with python but i got output.

my Proxmox-Server (4 Core - Celeron J4125):
{'acpitz': [shwtemp(label='', current=47.0, high=95.0, critical=95.0)], 'coretemp': [shwtemp(label='Package id 0', current=48.0, high=105.0, critical=105.0), shwtemp(label='Core 0', current=47.0, high=105.0, critical=105.0), shwtemp(label='Core 1', current=47.0, high=105.0, critical=105.0), shwtemp(label='Core 2', current=47.0, high=105.0, critical=105.0), shwtemp(label='Core 3', current=47.0, high=105.0, critical=105.0)]}

and testet on RaspberryPi 3B+:
{'cpu_thermal': [shwtemp(label='', current=44.546, high=None, critical=None)]}

To keep it simple i think you can use the "shwtemp - current" rounded to 1 decimal place after the comma (e.g. 44.5 for the Pi).
I don't need the temperatures for every core.

Greetings, Baxxy

Thank you so much.
I'd say to add a Temperature sensor for each dict entry, for example if your system had had both "acpitz" and "cpu_thermal" you would have seen two sensors: "acpitz temperature" and "cpu_thermal temperature".

Then for each sensor I see that there are a lot of temperatures. I'd say to consider them all and to send the maximum one, but let me know if the average would be more interesting in your opinion.

What do you think @infeeeee @Baxxy13 ?

Let me know.

Otherwise also all temperatures may be sent as single entities. Let me know.

On a healthy system usually per core temperatures are not too different, so sending the first, average or maximum will be really close, so shouldn't matter too much.

It would be nice to send all sensors of a device as extra attributes, they are accessible for automations in HA. I mean, for this MQTT light, I can see these in HA, we can add there other sensors:
kép
(Sorry, my HA is in Hungarian)

A possible problem for this, on my server psutil can't read the label of some sensors:

'it8792': [
    shwtemp(label='', current=29.0, high=127.0, critical=127.0), 
    shwtemp(label='', current=34.0, high=127.0, critical=127.0), 
    shwtemp(label='', current=34.0, high=127.0, critical=127.0)], 

On sensors command they look like this:

it8792-isa-0a60
Adapter: ISA adapter
temp1:        +29.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermistor
temp2:        +34.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermistor
temp3:        +34.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermistor

so expect 'label' can be empty


Also psutil can't report temperatures on windows, but it can be achieved with wmi and LibreHardwareMonitor as answered here: https://stackoverflow.com/questions/3262603/accessing-cpu-temperature-in-python (LibreHardwareMonitor (LHM) is a maintained fork of OpenHardwareMonitor)

This works on my windows box, when LHM is running:

import wmi
w = wmi.WMI(namespace="root\LibreHardwareMonitor")
temperature_infos = w.Sensor()
for sensor in temperature_infos:
    if sensor.SensorType==u'Temperature':
        print(sensor.Name)
        print(sensor.Value)

On a healthy system usually per core temperatures are not too different, so sending the first, average or maximum will be really close, so shouldn't matter too much.

I also think one temperature-sensor for the whole system should be enough.
I would prefer the highest, but average or the first one are also fine.

Hi, could you try the TemperatureSensor branch latest commit (#12) ?
I've also added the extra attributes, so if you can send me a picture of the sensor with the extra attributes in HomeAssistant would be nice to check the status of the implementation.

Keep in mind that currently this works only under Linux, so don't try the update in macOS/Windows.

Thanks !

Updated it again, don't test the previous commit but the current one please

Hi,
i'm sorry to say, but i don't know how to install / test these "TemperatureSensor - Branch".
Can you give me some help?

Sure,
you need to open the terminal and clone the repo with this command (to clone directly with the correct branch)
git clone -b TemperatureSensor git@github.com:richibrics/IoTuring.git

Then you enter in the cloned repo with
cd IoTuring

and install IoTuring using pip:
python3 -m pip install .[linux]

To run it you only need to type
python3 -m IoTuring

and to configure it
python3 -m IoTuring -c

Let me know if you need any other step or if there's any error/suggestion for the script

Thank you

Thanks.
But unfortunately there's errors at the first command (git clone):

root@Herobox-PVE:~# git clone -b TemperatureSensor git@github.com:richibrics/IoTuring.git
Cloning into 'IoTuring'...
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,140.82.121.4' (ECDSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Ok, i've managed to install and testing.

It looks good, is see 2 temperatures via the console warehouse...

[ 2022-12-06 18:40:50 | Message  |       Warehouse.Console       ]  Entity.Os.operating_system: Linux
[ 2022-12-06 18:40:50 | Message  |       Warehouse.Console       ]  Entity.Temperature.acpitz: 44.0
[ 2022-12-06 18:40:50 | Message  |       Warehouse.Console       ]  Entity.Temperature.coretemp: 43.0

... and in Homeassistant:
ioturing_Test_2

Looks very good for me. :-)

While testing i see another little issue... i'll open a new ticke for that.

That's strange; have you added the HomeAssistant Warehouse in the configurations ?

That's strange; have you added the HomeAssistant Warehouse in the configurations ?

It was my fault. I used MQTT warehause instead of Homeassistant warehouse.
(i edited my previous post after finding my mistake)
After correcting this everything works fine now.

Perfect, now I'll look at methods to get temperature on Windows and macOS.
Thank you for your support, I'm always here for every suggestion/problem.