Your frame may already do this
picframe3 does this by itself, so on a Raspberry Pi 4 or 5 you no longer need anything below. The article stays here for frames still running the older software.
Tested with
Raspberry Pi OS March 2021 version, Raspberry Pi 2, 3, and 4. Not re-tested since; the Home Assistant YAML and the paho-mqtt line below have been corrected for current versions, but the script itself has not been run on Bookworm or Trixie.
If you run picframe3, skip this. The frame reports its own health to Home Assistant over MQTT auto-discovery: CPU temperature, CPU load, memory used, free space on the disk your photographs are on, and the Pi's undervoltage flag — the last of which is the one that actually matters, because undervoltage is what corrupts SD cards. They arrive as diagnostic entities on the frame's device, with no script and no YAML. picframe3 doctor prints the same figures at the command line. The rest of this article is the hand-rolled version for the old pi3d PictureFrame.
Let’s be a bit nerdy here. No, you don’t need to monitor the CPU temperature of your Raspberry picture frame. It’s not getting very hot in the first place.
But wouldn’t it be nice, if you could? Well, if it’s possible, why not do it!
In this article, I will show how you measure the CPU temperature and send the value via MQTT to Home Assistant, where is it is shown in the dashboard.
You could, of course, put together a script that uses the temperature value to shut down the photo frame if it gets too hot and has some real use. Well, let me explain to you the basics, and you take it from here.
The following instructions assume that you are running Home Assistant and that you have installed an MQTT broker like Mosquitto on your Raspberry Pi.
If you are not familiar with this technology, please read my article “Control your digital picture frame with Home Assistant’s wifi presence detection and MQTT” first.
The Python script to measure the temperature
So, the first step is to add the following Python script to the home directory of your Raspberry Pi digital picture frame.
This script is triggered every five minutes by systemd. More on this below.
Open your file editor. Copy & paste the content below it and save it as send_cpu_temp.py.
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
import subprocess
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
#client.username_pw_set( "your_username" , "your_password" )
client.connect("localhost", 1883, 60)
# Announce that the frame is available
client.publish("frame/cpu_temp/available", "online", qos=0, retain=True)
# CPU temperature
cpu_temp = subprocess.run(['vcgencmd', 'measure_temp'], stdout=subprocess.PIPE).stdout.decode('utf-8') # measure CPU temperature
cpu_temp_value = cpu_temp[5:9] # cut temperature from result
cpu_temp_value_int = int(round(float(cpu_temp_value), 0)) # convert string into number, round and make integer
print(cpu_temp_value_int)
client.publish("frame/cpu_temp", cpu_temp_value_int, qos=0, retain=True)
The cpu temperature is published via MQTT in the topic “frame/cpu_temp”.
That first line used to read mqtt.Client(). paho-mqtt 2.x — which is what you get on Bookworm and Trixie — refuses the bare constructor and the script raises before it ever connects. mqtt.Client(mqtt.CallbackAPIVersion.VERSION1) works on both 1.x and 2.x.
Launching the script every five minutes
To activate this script, we’ll use systemd. We want to measure the temperature every five minutes.
Enter
sudo nano /etc/systemd/system/send_cpu_temp.service
Paste the following text into the editor window.
[Unit]
Description=Send CPU Temp
After=multi-user.target
[Service]
Type=idle
User=root
ExecStart=/home/pi/venv_picframe/bin/python /home/pi/send_cpu_temp.py
Restart=always
RestartSec=300
[Install]
WantedBy=multi-user.target
Check that ExecStart line against your own machine. venv_picframe is the pi3d PictureFrame virtual environment, and there is no default pi user on a recently set up Raspberry Pi OS, so both halves of that path may well be different for you. Point it at whatever Python has paho-mqtt installed.
The value in “RestartSec=300” determines the wait period in seconds until the CPU temperature is measured again.
Save and close.
Now change the file permissions with
sudo chmod 644 /etc/systemd/system/send_cpu_temp.service
and update the services with
sudo systemctl daemon-reload
sudo systemctl enable send_cpu_temp.service
Reboot.
Now we have to tell Home Assistant to pick up this sensor and display it on the frontend.
Setting up the temperature sensor in Home Assistant
Add this paragraph in configuration.yaml:
#MQTT Sensor
mqtt:
sensor:
- name: "cpu_temp_frame"
unique_id: cpu_temp_frame
state_topic: "frame/cpu_temp"
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
availability_topic: "frame/cpu_temp/available"
payload_available: "online"
payload_not_available: "offline"
That block used to read sensor: / - platform: mqtt. Home Assistant removed the MQTT platform from under sensor: in 2022; MQTT entities live under the top-level mqtt: key now, and the old form stops Home Assistant from starting. If your configuration.yaml already has an mqtt: section, add the sensor: list to the one you have rather than writing a second mqtt: key.
Restart Home Assistant.
In the front end of Home Assistant, define the entity like in this example:
entities:
- entity: sensor.cpu_temp_frame
icon: 'thermometer'
name: CPU Digital Picture Frame
Voilà, you should see the temperature on your dashboard.

Conclusion
This is another example of how you can connect your digital picture frame and your Home Automation system with simple MQTT messages.
Let me know what you think!
Was this article helpful?
Thank you for your support and motivation.