-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting from picow-projects
ha_temperature_discovery
- Loading branch information
Showing
13 changed files
with
1,368 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.