Wyzesense2mqtt
Configurable WyzeSense to MQTT Gateway intended for use with Home Assistant or other platforms that use MQTT discovery mechanisms.
Install / Use
/learn @raetha/Wyzesense2mqttREADME
WyzeSense to MQTT Gateway
Configurable WyzeSense to MQTT Gateway intended for use with Home Assistant or other platforms that use the same MQTT discovery mechanisms. The gateway allows direct local access to Wyze Sense products without the need for a Wyze Cam or cloud services. This project and its dependencies have no relation to Wyze Labs Inc.
Please submit pull requests against the devel branch.
Special Thanks
- HcLX for WyzeSensePy, the core library this project forked.
- Kevin Vincent for HA-WyzeSense, the reference code I used to get things working right with the calls to WyzeSensePy.
- ozczecho for wyze-mqtt, the inspiration for this project.
Table of Contents
Installation
Docker
This is the most tested method of running the gateway. It allows for persistance and easy migration assuming the hardware dongle moves along with the configuration. All steps are performed from the Docker host, not the container. Images are published to GHCR and Docker Hub.
- Plug the Wyze Sense Bridge into a USB port on the Docker host. Confirm that it shows up as /dev/hidraw0, if not, update the devices entry in the Docker Compose file with the correct device path.
- Create a Docker Compose file and a .env file similar to the following. See Docker Compose Docs for more details on the file format and options. Example files for docker-compose.yml and .env are also included in the repository for easy copying.
### Example docker-compose.yml ###
services:
wyzesense2mqtt:
container_name: wyzesense2mqtt
hostname: wyzesense2mqtt
image: ghcr.io/raetha/wyzesense2mqtt:${IMAGE_TAG:-latest}
network_mode: bridge
restart: unless-stopped
tty: true
stop_signal: SIGINT
environment:
TZ: "${TZ:-UTC}"
MQTT_HOST: "${MQTT_HOST}"
MQTT_PORT: "${MQTT_PORT:-1883}"
MQTT_USERNAME: "${MQTT_USERNAME}"
MQTT_PASSWORD: "${MQTT_PASSWORD}"
MQTT_CLIENT_ID: "${MQTT_CLIENT_ID:-wyzesense2mqtt}"
MQTT_CLEAN_SESSION: "${MQTT_CLEAN_SESSION:-false}"
MQTT_KEEPALIVE: "${MQTT_KEEPALIVE:-60}"
MQTT_QOS: "${MQTT_QOS:-0}"
MQTT_RETAIN: "${MQTT_RETAIN:-true}"
SELF_TOPIC_ROOT: "${SELF_TOPIC_ROOT:-wyzesense2mqtt}"
HASS_TOPIC_ROOT: "${HASS_TOPIC_ROOT:-homeassistant}"
HASS_DISCOVERY: "${HASS_DISCOVERY:-true}"
PUBLISH_SENSOR_NAME: "${PUBLISH_SENSOR_NAME:-true}"
USB_DONGLE: "${USB_DONGLE:-auto}"
devices:
- "${DEV_WYZESENSE:-/dev/hidraw0}:/dev/hidraw0"
volumes:
- "${VOL_CONFIG}:/app/config"
- "${VOL_LOGS}:/app/logs"
### Example .env ###
IMAGE_TAG=latest
TZ=America/New_York
MQTT_HOST=
MQTT_PORT=1883
MQTT_USERNAME=
MQTT_PASSWORD=
MQTT_CLIENT_ID=wyzesense2mqtt
MQTT_CLEAN_SESSION=false
MQTT_KEEPALIVE=60
MQTT_QOS=0
MQTT_RETAIN=true
SELF_TOPIC_ROOT=wyzesense2mqtt
HASS_TOPIC_ROOT=homeassistant
HASS_DISCOVERY=true
PUBLISH_SENSOR_NAME=true
USB_DONGLE=auto
DEV_WYZESENSE=/dev/hidraw0
VOL_CONFIG=/docker/wyzesense2mqtt/config
VOL_LOGS=/docker/wyzesense2mqtt/logs
- Create your local volume mounts. Use the same folders you entered in the Docker Compose files created above.
mkdir /docker/wyzesense2mqtt/config
mkdir /docker/wyzesense2mqtt/logs
- (Optional, when using Docker environment variables) Create or copy a config.yaml file into the config folder (see example below or copy from repository). The script will automatically create a default config.yaml if one is not found, but it will need to be modified with the correct MQTT details before things will work.
- (Optional) Copy a logging.yaml file into the config folder (see example below or copy from repository). The script will automatically use the default logging.yaml if one does not exist. You only need to modify this if more complex logging is required.
- (Optional) Pre-populate a sensors.yaml file into the config folder with your existing sensors. This file will automatically be created if it doesn't exist. (see example below or copy from repository)
- Start the Docker container
docker-compose up -d
- Pair sensors following instructions below. You do NOT need to re-pair sensors that were already paired, they should be found automatically on start and added to the config file with default values, though the sensor version will be unknown and the class will default to opening, i.e. a contact sensor. You should manually update these entries.
Linux Systemd
If you would like to use this project outside of docker, please follow the instructions at Linux Systemd Installation. This method is not actively tested and may require more knowledge to succesfully implement.
Configuration Files
The gateway uses three config files located in the config directory. Examples of each are below and in the repository.
config.yaml
This is the main configuration file. Aside from MQTT host, username, and password, the defaults should work for most people. A working configuration will be created automatically if ENV values are available for at least mqtt_host, mqtt_username, and mqtt_password. So it does not need to be created in advance.
mqtt_host: <host>
mqtt_port: 1883
mqtt_username: <user>
mqtt_password: <password>
mqtt_client_id: wyzesense2mqtt
mqtt_clean_session: false
mqtt_keepalive: 60
mqtt_qos: 2
mqtt_retain: true
self_topic_root: wyzesense2mqtt
hass_topic_root: homeassistant
hass_discovery: true
publish_sensor_name: true
usb_dongle: auto
logging.yaml
This file contains a yaml dictionary for the logging.config module. Python docs at logging configuration
version: 1
formatters:
simple:
format: '%(message)s'
verbose:
datefmt: '%Y-%m-%d %H:%M:%S'
format: '%(asctime)s %(levelname)-8s %(name)-15s %(message)s'
handlers:
console:
class: logging.StreamHandler
formatter: simple
level: DEBUG
file:
backupCount: 7
class: logging.handlers.TimedRotatingFileHandler
encoding: utf-8
filename: logs/wyzesense2mqtt.log
formatter: verbose
level: INFO
when: midnight
root:
handlers:
- file
- console
level: DEBUG
sensors.yaml
This file will store basic information about each sensor paired to the Wyse Sense Bridge. The entries can be modified to set the class type and sensor name as it will show in Home Assistant. Class types can be automatically filled for opening, motion, and moisture, depending on the type of sensor. Since this file can be automatically generated, Python may automatically quote the MACs or not depending on if they are fully numeric. Sensors that were previously linked and automatically added will default to class opening and will not have a "sw_version" set. For the original version 1 devices, the sw_version should be 19. For the newer version 2 devices, the sw_version should be 23. This will be automatically have the correct settings for devices added via a scan. A custom timeout for device availability can also be added per device by setting the "timeout" setting, in seconds. For version 1 devices, the default timeout is 8 hours and for version 2 device, the default timeout is 4 hours.
'AAAAAAAA':
class: door
name: Entry Door
invert_state: false
sw_version: 19
'BBBBBBBB':
class: window
name: Office Window
invert_state: false
sw_version: 23
timeout: 7200
'CCCCCCCC':
class: opening
name: Kitchen Fridge
invert_state: false
sw_version: 19
'DDDDDDDD':
class: motion
name: Hallway Motion
invert_state: false
sw_version: 19
'EEEEEEEE':
class: moisture
name: Basement Moisture
invert_state: true
sw_version: 19
Usage
Pairing a Sensor
At this time only a single sensor can be properly paired at once. So please repeat steps below for each sensor.
- Publish a blank message to the MQTT topic "self_topic_root/scan" where self_topic_root is the value from the configuration file. The default MQTT topic would be "wyzesense2mqtt/scan" if you haven't changed the configuration. This can be performed via Home Assistant or any MQTT client.
- Use the pin tool that came with your Wyze Sens
