The CPU temp will continue to update every 30 seconds as long as the host and the VM are both running. Now we have a way to push system monitoring info from the host system to Home Assistant running in a VM. This is actually done by creating two cron tasks, one that runs every minute, and one that runs every minute but with a 30 second delay (* * * * * means run every minute). * * * * * (sleep 30 /root/my_script.py) Crontab Edit the crontab with crontab -e and add two lines: * * * * * /root/my_script.py Add a new cron task to run the job every 30 seconds. The last step is to automate the script so that it runs periodically. If the value did not update correctly, you can troubleshoot by adding print statements to the script to double check the values of the variables. If it worked, you will see that the value of the input_number.cpu_temp entity has been updated in Home Assistant. Save the file and use chmod to make it executable, then test the script: > chmod x+a my_script.py Response = post(url, headers=headers, data=data, verify=False) # Replace ABCDEFG with your Long-lived access token # Make sure to use the correct protocol, http or https # Replace hostname and port with your HA instance Temp=subprocess.check_output("cat /sys/class/thermal/thermal_zone3/temp", shell=True) # Get temperature from system using the command from step 6 Use vim or nano to create a new python script using the template below, and make the necessary replacements for your thermal zone, HA hostname/port, and bearer token. you need to divide it by 1000 to get the temperature. Note that the value returned will be in thousanths of a degree-Celcius, i.e. Here is the command to get the temperature once you know the zone number: cat /sys/class/thermal/thermal_zone3/temp This one is 4th in the list, which is 0-based, so my CPU's thermal zone number is 3. In my case, the correct CPU temp is called x86_pkg_temp. This script will return the names of the different available temperatures. cat /sys/class/thermal/thermal_zone*/type While you are rooted into Proxmox, run the following command to get a list of all temperature files. Verify the install by running the following command: > pip3 -version 6. Run the following commands to install Python. Root into Proxmox using the web interface or SSH terminal. Value_template: '' Add to configuration.yaml. Create entities to monitor the temperature input_number: You will be given a long string of characters, so make sure you copy paste it somewhere to use in the script later. This token will be used by the host system when calling the API, so give it a meaningful name. Go to the Profile screen in Home Assistant, scroll to the bottom and create a new Long-lived Access Token. Enable the Rest API api: Add to configuration.yaml. Note: MQTT may be preferred over the REST API if you already have MQTT set up. The rest of this post is a guide for setting everything up in Proxmox. What I came up with was a python script that runs as a cron job – every 30 seconds it grabs the CPU temp using the command above, and it updates an entity in Home Assistant using the REST API. This problem just becomes a matter of sending the results from the host system down to the VM. However, if you run the same script in the host system, you will get the expected results. If you run the command above in the virtualized Home Assistant node, you will get an error because the path does not exist. The problem with running HA in a VM is that the virtualized hardware does not have the concept of temperature. Most information online assumes you are running HA on dedicated hardware like a Pi or a Debian box, where you can easily look up the CPU temp using a simple shell command: > cat /sys/class/thermal/thermal_zone*/temp Most of the monitoring is trivial to set up using the SystemMonitor component, but I ran into a wall when I tried to set up the CPU temperature. I decided to set up some monitoring on the new hardware so I can see if resources should be allocated/deallocated from the VM, and so I can send myself alerts if usage or temperature gets too high. Last week, I finally migrated my Home Assistant setup from my Raspberry Pi onto a Linux server. Virtualized hardware does not report temperatures, so I used a python script running on the host system to periodically send the CPU temp to Home Assistant. This post will show how I set up CPU Temperature monitoring for Home Assistant running on a virtual machine in Proxmox.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |