Raspberry Pi with DS18B20 temperature sensors
From CaveLab
This page is currently a draft. Please check back later for additional changes.
Raspberry Pi driven temperature sensors for fan control of the home lab/office.
Details
- Set up Raspberry Pi; Raspberry Pi IoT setup
- Enable 1-wire communication with
raspi-config
- Install python package
sudo apt install python3-w1thermsensor
List devices:
$ ls /sys/bus/w1/devices/
28-0416a02b0eff 28-0517021db9ff 28-051702869eff w1_bus_master1
Raw read the value:
$ cat /sys/bus/w1/devices/28-0416a02b0eff/w1_slave
8e 01 4b 46 7f ff 0c 10 de : crc=de YES
8e 01 4b 46 7f ff 0c 10 de t=24875
Temperature = 24.875'C
Screencast
Home Assistant configuration
sensor:
- platform: mqtt
state_topic: 'sensor/office/temp/above_rack'
availability_topic: "sensor/office/temp/above_rack/status"
name: 'Office ceiling above rack'
unit_of_measurement: '°C'
- platform: mqtt
state_topic: 'sensor/office/temp/above_desk'
availability_topic: "sensor/office/temp/above_desk/status"
name: 'Office ceiling above desk'
unit_of_measurement: '°C'
- platform: mqtt
state_topic: 'sensor/office/temp/room_center'
availability_topic: "sensor/office/temp/room_center/status"
name: 'Office ceiling center'
unit_of_measurement: '°C'
- platform: mqtt
state_topic: 'sensor/office/temp/average'
name: office_temp_average
unit_of_measurement: '°C'
Fan automation
- alias: Fan on auto
trigger:
platform: numeric_state
entity_id: sensor.office_temp_average
above: 25
action:
service: switch.turn_on
entity_id: switch.office_fan
- alias: Fan off auto
trigger:
platform: numeric_state
entity_id: sensor.office_temp_average
below: 24
for:
minutes: 5
action:
service: switch.turn_off
entity_id: switch.office_fan
Source code
Gallery
- Temperature probes
- Previous probe placement
Schematic diagram
Parts used
Qty. | Part |
---|---|
1 × | microSDHC card, Transcend, 32GB, class 10, 20MB/17MBs |
1 × | PCB, perfboard prototyping, 30x70mm, 21cm2 |
1 × | Raspberry Pi 1 Model B+, 700MHz ARM CPU, 512MB RAM |
1 × | Resistor, carbon film, 0.25W, 10 kΩ, 5% |
1 × | Rubber foot, adhesive, SJ-5012, Ø 12.7x3.5 mm |
10 × | Straight pin header, female, Dual row, 2.54mm |
12 × | Straight pin header, female, Single row, 2.54mm |
15 × | Straight pin header, male, Single row, 2.54mm |
4 × | Temperature sensor DS18B20, probe, Water-proof, 1M cable |
1.5 m | Wire, stranded, 0.22mm2, Black |
1.5 m | Wire, stranded, 0.22mm2, Red |
1.5 m | Wire, stranded, 0.22mm2, Yellow |