Skip to content

Commit

Permalink
Starting from picow-projects ha_temperature_discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
idcrook committed Feb 8, 2025
1 parent 88fe24b commit 094565f
Show file tree
Hide file tree
Showing 13 changed files with 1,368 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,12 @@ cython_debug/

# PyPI configuration file
.pypirc

secrets.py
.vscode
.micropico
mqtt_local.py
# per-device files
config-*.py
device-*.py
/RCS
74 changes: 73 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
# yaha_temperature_monitor
Yet Another Home Assistant Temperature monitor, using micropython and Pico W

Yet Another Home Assistant Temperature monitor.

Uses micropython, Raspberry Pi Pico W, and DS18B20 1-wire temperature probes.

## Features

- Uses micropython and `asyncio`/`mqtt_as` for reliability and performance.
- Can handle network downtimes and flakiness
- Has hardware watchdog timer (WDT) support
- Integrates into local `MQTT` and supports MQTT Discovery for sensors in Home Assistant

## Requirements

- Pico W microcontroller board, connecting to WiFi.
- Up to three DS18B20 1-wire temperature probes connected
- (Optional) OLED matrix (using I2C) for displaying info
- (Optional) BM[EP] sensor (using I2C) for ambient condiditions
- Home Assistant with MQTT integration


### micropython target setup

Assumes [`mpremote`](https://docs.micropython.org/en/latest/reference/mpremote.html) is installed in macOS (host) and recent version of micropython (target).

I use macOS or Linux, and am targetting Raspberry Pi Pico W.

```shell
❯ mpremote connect /dev/tty.usbmodem33101
python-repl
Connected to MicroPython at /dev/cu.usbmodem33101
Use Ctrl-] or Ctrl-x to exit this shell

>>>
```

### mip

like `pip` for micropython

```shell
# set up for your wi-fi, and then copy over
mpremote fs cp secrets.py :
mpremote run mip_install.py
```

## Putting on Pico W

```shell
# customize these before copying
mpremote fs cp secrets.py :
mpremote fs cp config-picow1.py :config.py
mpremote fs cp device-picow1.py :device.py

# testing
mpremote run test_ds18b20.py
mpremote run test_bme.py
mpremote run test_1306disp.py
mpremote run test_ha_mqtt.py

# This is the main show
mpremote run main.py
```

To have it launch on "boot up", copy `main.py` to Pico W storage. `micropython` will run it after reset.

```shell
mpremote fs cp main.py :
```

# Other

Spun out from <https://github.com/idcrook/picow-projects/tree/main/ha_temperature_discovery>
42 changes: 42 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# import re

from device import ONEWIRE_CONFIG, I2C_CONFIG, APP_CONFIG

def unique_device_identifier(mac_addr_hexlified):
"""Use MAC address to generate a unique string for this device."""
# Let's start with last three nibbles of MAC address
trailing_nibbles = mac_addr_hexlified.replace(":", "")[-3:]
return trailing_nibbles

#TOP_TOPIC= 'sandbox'
TOP_TOPIC= 'homeassistant'

SWVER = "0.1"
HWVER = "0.1"
MDL = "Pico temp"
MDL_ID = "picow_ds_bme280"
MNF = "idcrook-labs"
brand = "seedomatic"
NAME = f"{brand} {MDL}"

CFG_DEV = {
"sw": SWVER,
"hw": HWVER,
"mdl": MDL,
"mdl_id": MDL_ID,
"mf": MNF,
"name": NAME,
"ids": [],
}

def set_mqtt_disc_dev_id(identifiers):
if isinstance(identifiers, list):
CFG_DEV['ids'] = identifiers
elif isinstance(identifiers, tuple):
CFG_DEV['ids'] = list(*identifiers)
else:
CFG_DEV['ids'] = [identifiers]

def get_top_topic():
"""Top topic to use for Home Assistant MQTT."""
return TOP_TOPIC
8 changes: 8 additions & 0 deletions def_secrets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

WIFI_SSID = "wifi name"
WIFI_PASSWORD = "mypass!"

MQTT_SERVER = "YOUR MQTT BROKER IP"
MQTT_PORT = 1883
MQTT_USER = None
MQTT_PASSWORD = None
49 changes: 49 additions & 0 deletions device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# per-device numbers and names

ONEWIRE_CONFIG = {
"data_pin": 22,
"sensors": {
"288f8746b1220767": {"name": "bed1"},
"28ffdb8483160410": {"name": "bed3"},
"288d85b8b022061b": {"name": "bed4"},
"288b8562b1220746": {"name": "bed5"},
"2834e359b1220734": {"name": "bed2"},
},
}

I2C_CONFIG = {
"bus": {
"bus_number": 0,
"sda_pin": 4,
"scl_pin": 5
},
"sensors" : [
{ "bme280":
{ "address": 119,
}
}
],
"displays" : [
{ "ssd1306" :
{
"address": 60,
"width": 128,
"height": 32,
# value of 8 useful in split color displays
"second_line_padding": 8,
}
}
]
}


APP_CONFIG = {
"sensor_read_interval_seconds": 30,
"mqtt_client_debug": False,
"blink_onboard_led": True,
"heartbeat_onboard_led": True,
"enable_hardware_watchdog": True,
"device_name": "picow0",
"display_temperature_readings": True,
# "unique_id"
}
Loading

0 comments on commit 094565f

Please sign in to comment.