Configurable WyzeSense to MQTT Gateway for Home Assistant
100K+
Configurable WyzeSense to MQTT Gateway intended for use with Home Assistant or other platforms that use 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.
This is the most highly 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 Docker host, not container.
version: "3.7"
services:
wyzesense2mqtt:
container_name: wyzesense2mqtt
image: raetha/wyzesense2mqtt:latest
hostname: wyzesense2mqtt
restart: always
tty: true
stop_signal: SIGINT
network_mode: bridge
devices:
- "/dev/hidraw0:/dev/hidraw0"
volumes:
- "/docker/wyzesense2mqtt/config:/wyzesense2mqtt/config"
- "/docker/wyzesense2mqtt/logs:/wyzesense2mqtt/logs"
environment:
TZ: "America/New_York"
mkdir /docker/wyzesense2mqtt/config
mkdir /docker/wyzesense2mqtt/logs
docker-compose up -d
The gateway can also be run as a systemd service for those not wanting to use Docker. Requires Python 3.6 or newer. You may need to do all commands as root, depending on filesystem permissions.
cd /tmp
git clone https://github.com/raetha/wyzesense2mqtt.git
# Use the below command instead if you want to help test the devel branch
# git clone -b devel https://github.com/raetha/wyzesense2mqtt.git
mv /tmp/wyzesense2mqtt/wyzesense2mqtt /wyzesense2mqtt
rm -rf /tmp/wyzesense2mqtt
cd /wyzesense2mqtt
mkdir config
mkdir logs
cp samples/config.yaml config/config.yaml
vim config/config.yaml
cp samples/logging.yaml config/logging.yaml
vim config/logging.yaml
cp samples/sensors.yaml config/sensors.yaml
vim config/sensors.yaml
sudo pip3 install -r requirements.txt
vim wyzesense2mqtt.service # Only modify if not using default application path
sudo cp wyzesense2mqtt.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start wyzesense2mqtt
sudo systemctl status wyzesense2mqtt
sudo systemctl enable wyzesense2mqtt # Enable start on reboot
The gateway uses three config files located in the config directory. Samples 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.
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.
'AAAAAAAA':
class: door
name: Entry Door
invert_state: false
'BBBBBBBB':
class: window
name: Office Window
invert_state: false
'CCCCCCCC':
class: opening
name: Kitchen Fridge
invert_state: false
'DDDDDDDD':
class: motion
name: Hallway Motion
invert_state: false
'EEEEEEEE':
class: moisture
name: Basement Moisture
invert_state: true
At this time only a single sensor can be properly paired at once. So please repeat steps below for each sensor.
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.
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:
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 the Home Assistant recognizes, see the binary_sensor documentation.
Content type
Image
Digest
sha256:7ad7085c3…
Size
25.2 MB
Last updated
5 months ago
docker pull raetha/wyzesense2mqtt