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.
- 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.
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.
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.
The gateway uses three config files located in the config directory. Examples of each are below and in the repository.
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
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
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
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 Sense sensors to press the reset switch on the side of the sensor to pair. Hold in until the red led blinks.
- Publish a message containing the MAC to be removed to the MQTT topic "self_topic_root/remove" where self_topic_root is the value from the configuration file. The default MQTT topic would be "wyzesense2mqtt/remove" if you haven't changed the configuration. The payload should look like "AABBCCDD". This can be performed via Home Assistant or any MQTT client.
If you've changed your sensors.yaml file while the gateway is running, you can trigger a reload of the sensors.yaml file without restarting the gateway or Docker container.
- Publish a blank message to the MQTT topic "self_topic_root/reload" where self_topic_root is the value from the configuration file. The default MQTT topic would be "wyzesense2mqtt/reload" if you haven't changed the configuration. This can be performed via Home Assistant or any MQTT client.
The bridge_tool_cli.py script can be used to interact with your bridge to perform a few simple functions. Make sure to specify the correct device for your environment.
python3 bridge_tool_cli.py --device /dev/hidraw0
Once run it will present a menu of its functions:
- L - List paired sensors
- P - Pair new sensors
- U - Unpair sensor (e.g. "U AABBCCDD")
- F - Fix invalid sensors (Removes sensors with invalid MACs, common problem with broken sensors or low batteries)
Home Assistant simply needs to be configured with the MQTT broker that the gateway publishes topics to. Once configured, the MQTT integration will automatically add devices for each sensor along with entites for the state, battery_level, and signal_strength. By default these entities will have a device_class of "opening" for contact sensors, "motion" for motion sensors, and "moisture" for leak sensors. They will be named for the sensor type and MAC, e.g. Wyze Sense Contact Sensor AABBCCDD. To adjust the device_class to "door" or "window", and set a custom name, update the sensors.yaml configuration file and replace the defaults, then restart WyzeSense2MQTT. For a comprehensive list of device classes that Home Assistant recognizes, see the binary_sensor documentation.
- Wyze Sense Bridge (WHSB1)
- Neos Smart Bridge (N-LSP-US1) - Untested, but theoretically compatible
- Wyze Sense Bridge Sensors
- Contact Sensor v1
- Motion Sensor v1
- Neos Smart Sensors - Untested, but theoretically compatible
- Contact Sensor
- Leak Sensor
- Motion Sensor
- Wyze Sense Hub Sensors - Requires installing the Wyze Sense Hub firmware onto a Wyze Sense Bridge (unsupported and untested)
- Entry Sensor v2 (WSES2)
- Motion Sensor v2 (WSMS2)
- Climate Sensor (WSCS1) - Coming Soon Hopefully
- Keypad (WSKP1) - Coming Soon Hopefully
- Leak Sensor (WSLS1) - Coming Soon Hopefully