The one wire system, which the Pi can certainly join, is technically a 2 wire system, because there is a ground wire too. But the data and power can run down the same wire.
Our 1 wire system is actually running on Ethernet cable, because it spans 2 buildings. We could have used a Pi with a USB 1wire adaptor, but this was before things like that because popular. So we used an Embedded Systems One Wire Ethernet Server ( 3 channel ) it looks like this https://www.amazon.com/Embedded-Data-Systems-OW-SERVER-Ethernet/dp/B00S8SADV2
And then we have Temperature sensors across the Theatre on the 3 channels. One channel is all the theatre, one channel is the cafe and the foyer. The last channel is for the house - but really only has an 8 channel relay board, and a few temperature sensors on it. One of the temperature sensors is taped to the outgoing heating pipe from the boiler so that we can have a template sensor that turns on when the temperature of the pipe goes above a level, and then I have an alert if the heating switch has been turned on for 5 minutes, but the temperature of the water pipe has not gone above the threshold. Because it means either the boiler pressure is too low, or there is some other problem with the boiler.
The even cheaper way of doing temperature sensing - and we have 3 of them -
get ESP8266 boards ( commonly called NodeMCU ) Wire a DS18b20 to them. ESP Home built in to Home Assistant, will take you the rest of the way.
Here is an example I use, because of where it is situated, I also added a reed sensor so that we have a door contact sensor too.
substitutions:
device_name: livingroom_thermo
room_name: living_room
light_level: '8.5'
door_room_name: store_room
thermo_light_switch: switch.store_room
light_id: 'light.smart_led_light_bulb_level_7'
dev_ip: '192.168.2.60'
esphome:
name: ${device_name}
platform: ESP8266
board: nodemcuv2
wifi:
ssid: 'DH-JM'
password: !secret wifi_password
domain: '.nptohc.co.uk'
manual_ip:
static_ip: ${dev_ip}
gateway: 192.168.2.254
subnet: 255.255.255.0
api:
password: !secret api_password
reboot_timeout: 15min
# Enable logging
logger:
level: WARN
time:
- platform: homeassistant
id: homeassistant_time
timezone: 'Europe/London'
on_time:
- cron: '0 0 * * * *'
then:
- script.execute: status_update
ota:
password: !secret ota_password
sun:
latitude: 55.70636
longitude: -2.46281
dallas:
- pin: D1
update_interval: 15s
binary_sensor:
- platform: template
name: "${room_name} daytime"
id: ${room_name}_thermo_daytime
lambda: |-
if (id(sun_elevation).state < ${light_level}) {
return false;
} else {
return true;
}
- platform: gpio
pin:
number: D2
mode: INPUT_PULLUP
inverted: True
name: "${door_room_name} door"
id: "${device_name}_door"
device_class: door
on_multi_click:
- timing:
- ON for at most 3s
- OFF for at most 3s
- ON for at least 0.2s
then:
- script.execute: door_override_update
- homeassistant.service:
service: light.turn_on
data:
entity_id: ${light_id}
- timing:
- ON for at least 3.1s
then:
- script.execute: door_update
- if:
condition:
- binary_sensor.is_off: ${room_name}_thermo_daytime
- binary_sensor.is_on: ${device_name}_door
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: ${light_id}
- timing:
- OFF for at least 3.1s
then:
- script.execute: door_update
switch:
- platform: gpio
pin:
number: D6
mode: OUTPUT
inverted: True
name: "thermo_status_led"
id: ${device_name}_thermo_status_led
- platform: gpio
pin:
number: D7
mode: OUTPUT
inverted: True
name: "boiler_status_led"
id: ${device_name}_boiler_status_led
- platform: gpio
pin:
number: D4
mode: OUTPUT
inverted: True
id: status_led
name: "status_led"
internal: true
script:
- id: status_update
then:
- switch.turn_on: status_led
- delay: 300ms
- switch.turn_off: status_led
- id: door_update
then:
- switch.toggle: ${device_name}_thermo_status_led
- delay: 150ms
- switch.toggle: ${device_name}_thermo_status_led
- delay: 150ms
- switch.toggle: ${device_name}_thermo_status_led
- delay: 150ms
- switch.toggle: ${device_name}_thermo_status_led
- id: door_override_update
then:
- switch.toggle: ${device_name}_boiler_status_led
- delay: 150ms
- switch.toggle: ${device_name}_boiler_status_led
- delay: 150ms
- switch.toggle: ${device_name}_boiler_status_led
- delay: 150ms
- switch.toggle: ${device_name}_boiler_status_led
sensor:
- platform: dallas
index: 0
name: "${room_name} temperature uncalibrated"
filters:
- filter_out: nan
- sliding_window_moving_average:
window_size: 6
send_every: 4
send_first_at: 4
- delta: 0.1
on_value:
then:
- script.execute: status_update
on_raw_value:
then:
- sensor.template.publish:
id: template_temperature
state: !lambda 'return x;'
- platform: template
name: "${room_name} temperature"
id: "template_temperature"
filters:
- filter_out: nan
- sliding_window_moving_average:
window_size: 6
send_every: 4
send_first_at: 4
- delta: 0.1
- calibrate_linear:
- 0.0 -> 0.0
- 20.3 -> 18.9
- 20.4 -> 19.04
- 20.5 -> 19.185
- 20.6 -> 19.33
- 20.7 -> 19.41
- 20.8 -> 19.59
- 20.9 -> 19.755
- 21.0 -> 19.8625
unit_of_measurement: "°C"
icon: mdi:thermometer
- platform: wifi_signal
name: "${room_name} wifi"
update_interval: 5s
filters:
- sliding_window_moving_average:
window_size: 12
send_every: 12
send_first_at: 6
- platform: uptime
name: "${room_name} uptime"
- platform: sun
name: "sun_elevation"
internal: true
type: elevation
id: sun_elevation
Now I have extra stuff going on in there than you would need - mostly flashing an LED to confirm that it registered the door being opened or closed or that a period of time has passed since the door was closed, and now the light in the room will be turned off. Additionally there is some detection of the door opening and closing quickly, which enables me to open, close, open within a few seconds to force the room light to turn on when it is dark outside but it’s not night time.
The important bits are:
dallas:
- pin: D1
update_interval: 15s
sensor:
- platform: dallas
index: 0
name: "${room_name} temperature uncalibrated"
filters:
- filter_out: nan
- sliding_window_moving_average:
window_size: 6
send_every: 4
send_first_at: 4
- delta: 0.1
So I filter out values that are nan
which means not a number.
I then have a sliding window so that instead of the temperature going up and down in spikes, we get a temperature that is averaged across 6 samples - which at 15sec intervals is 1min 30secs. There is also a delta of 0.1 which means that we only update when the temperature we are going to send to home assistant, has changed since at least 0.1 since we last sent it.
Now in the longer code above you will notice there is calibrate_linear, which enables me to provide Home Assistant with a temperature that is closer to accurate - by providing ESPHome with known temperature values, versus what the Dallas sensor is reporting. ESPHome will then try and scale it’s output based on what temperature values it knows are correct.
Hope this helps a bit.
EDIT:
The 2 LEDs that are connected are red and green. The board has an inbuilt blue LED - which I flash when an update is sent to Home Assistant. The green LED is turned on when the heating switch in Home Assistant is turned on by the climate thermostat. And then the Red LED is turned on when the template sensor in Home assistant which tells us the boiler is working, because the water pipe has gone above 45C. This was the 3 of these that we have around the house, are reporting the heating and boiler status visually.