Sent CPU temperature from Proxmox to Domoticz Topic is solved

Python and python framework

Moderator: leecollings

Post Reply
SunHopper
Posts: 6
Joined: Thursday 25 February 2021 19:22
Target OS: Windows
Domoticz version:
Contact:

Sent CPU temperature from Proxmox to Domoticz

Post by SunHopper »

With help of google I made a Python scrip for sending my server CPU temperature running PROXMOX VM to a virtual sensor
The temperature is updated in the file : /sys/class/thermal/thermal_zone0/temp
Only reading the first 2 digits on the first line.
Send this value to a virtual sensor in Domoticz every 5 minutes.

Note: This script has to run on the Proxmox server itself !! Not on the OS Domoticz runs on !!!!!

Code: Select all

import os
import re
import requests
import time
import sys

while True:

    file = open('/sys/class/thermal/thermal_zone0/temp', 'r')

    first_line = file.readline(2).strip()

# Close the file
    file.close()

    domoticzserver = "192.168.178.37:8080"
    idx_temp = "373"  # Put youre own IDX here of the virtual sensor

    val_temp = first_line


    res = requests.get(
        "http://"
        + domoticzserver
        + "/json.htm?type=command&param=udevice&idx="
        + idx_temp
        + "&nvalue=0&svalue="
        + val_temp
    )
    time.sleep(300)  # send every 5 minutes

Last edited by SunHopper on Saturday 11 January 2025 10:44, edited 2 times in total.
User avatar
waltervl
Posts: 5293
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Sent CPU temperature from Proxmox to Domoticz

Post by waltervl »

Normal Domoticz motherboard sensor gateway is not working in Proxmox environment?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
SunHopper
Posts: 6
Joined: Thursday 25 February 2021 19:22
Target OS: Windows
Domoticz version:
Contact:

Re: Sent CPU temperature from Proxmox to Domoticz

Post by SunHopper »

Thats right. Domoticz runs on Ubuntu in a Proxmox VM.
Domoticz can't access the server sensors.
With this script running on the proxmox server itself it sends the CPU temperature to the IP address od Domoticz.
This way I'm able to monitor and get an alarm on Telegram when my CPU temperature is getting to high (summer time).
sloeber70
Posts: 12
Joined: Wednesday 08 July 2020 10:59
Target OS: Linux
Domoticz version: latest
Location: Bruges
Contact:

Re: Sent CPU temperature from Proxmox to Domoticz

Post by sloeber70 »

Hi.

Works fine!!
Do I need to create a crontab for this python file?
How can I check that this process is running and restart it if that would be necessary?

Kind regards.
Attachments
2025-01-11_13-07-20.jpg
2025-01-11_13-07-20.jpg (14.06 KiB) Viewed 146 times
Kind regards,
Sloeber70

Linux 12 Bookworm standard edition
Domoticz latest beta
sloeber70
Posts: 12
Joined: Wednesday 08 July 2020 10:59
Target OS: Linux
Domoticz version: latest
Location: Bruges
Contact:

Re: Sent CPU temperature from Proxmox to Domoticz

Post by sloeber70 »

Hi.

The script runs once and then it stops.. The delay for restarting the query is not working.

So I've altered the script and just remarked the timer and added "quit()". So that the script stops and the process is deleted.

I've added a crontab line so that the script runs every xx minutes (choice).
Crontab:
*/5 * * * * python3 /root/temp2domoticz.py

Script:
## start script ##
import os
import re
import requests
import time
import sys

while True:

file = open('/sys/class/thermal/thermal_zone1/temp', 'r')

first_line = file.readline(2).strip()

# Close the file
file.close()

domoticzserver = "10.10.3.2:9080"
idx_temp = "4856" # Put youre own IDX here of the virtual sensor

val_temp = first_line


res = requests.get(
"http://"
+ domoticzserver
+ "/json.htm?type=command&param=udevice&idx="
+ idx_temp
+ "&nvalue=0&svalue="
+ val_temp
)
#time.sleep(5) # wait 5 seconds
quit()
## end script ##

See the result in attachment
Kind regards,
Sloeber70

Linux 12 Bookworm standard edition
Domoticz latest beta
sloeber70
Posts: 12
Joined: Wednesday 08 July 2020 10:59
Target OS: Linux
Domoticz version: latest
Location: Bruges
Contact:

Re: Sent CPU temperature from Proxmox to Domoticz

Post by sloeber70 »

attachment
Attachments
2025-01-11_18-11-37.jpg
2025-01-11_18-11-37.jpg (128.5 KiB) Viewed 132 times
Kind regards,
Sloeber70

Linux 12 Bookworm standard edition
Domoticz latest beta
SunHopper
Posts: 6
Joined: Thursday 25 February 2021 19:22
Target OS: Windows
Domoticz version:
Contact:

Re: Sent CPU temperature from Proxmox to Domoticz

Post by SunHopper »

@sloeber my script keeps running I started the script ending with & like: python3 /home/domoticz/domoticzCPU.py &
Added this to contrab for auto startup.

Nice to see it works for you :D
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest