New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Reply To: Pi 4 shows 52 degrees, which is the CPU. How do I read the room temperature and send it up?

Did the same thing in first year, the probe was fine afterwards but I was lucky. Full checklist:

Wiring: red to 3V3 (pin 1), black to GND (pin 6), yellow to GPIO4 (pin 7), and a 4.7k resistor from yellow to 3V3. Add dtoverlay=w1-gpio to /boot/firmware/config.txt (or /boot/config.txt on older images) and reboot. You should see a 28-xxxxxxxxxxxx folder.

Then the script, on the same paho code you have:

import glob, json, time
import paho.mqtt.client as mqtt

dev = glob.glob('/sys/bus/w1/devices/28-*/w1_slave')[0]
def read_c():
    lines = open(dev).read().splitlines()
    if not lines[0].endswith('YES'):
        return None                      # CRC failed, skip this one
    return int(lines[1].split('t=')[1]) / 1000.0

c = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="basement-pi")
c.username_pw_set("YOUR_ACCESS_TOKEN")    # token as username, no password
c.tls_set()
c.connect("YOUR_BROKER_HOST", 8883, keepalive=60)
c.loop_start()
while True:
    t = read_c()
    if t is not None:
        c.publish("v1/telemetry", json.dumps({"temp_c": round(t, 2)}), qos=1)
    time.sleep(60)

Use a new key name like temp_c so the CPU readings don’t mix into the same chart. Broker host is on the device’s Connection details card.

Timestamps in UTC or it didn't happen.
Accepted solution♥ 8