All Projects → raetha → wyzesense2mqtt

raetha / wyzesense2mqtt

Licence: MIT License
Configurable WyzeSense to MQTT Gateway intended for use with Home Assistant or other platforms that use MQTT discovery mechanisms.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to wyzesense2mqtt

node-deepstackai-trigger
Detects motion using Deepstack AI and calls registered triggers based on trigger rules.
Stars: ✭ 154 (+180%)
Mutual labels:  mqtt, mqtt-client, homeassistant, mqtt-smarthome
Awesome Home Assistant
A curated list of amazingly awesome Home Assistant resources.
Stars: ✭ 3,487 (+6240%)
Mutual labels:  mqtt, home-assistant, homeassistant
Kmansonoff
Firmware for ESP8266 based itead Sonoff switches for use with HomeAssistant / mqtt
Stars: ✭ 282 (+412.73%)
Mutual labels:  mqtt, home-assistant, mqtt-client
Homeassistant
Home Assistant Configuration Files and Documentation
Stars: ✭ 395 (+618.18%)
Mutual labels:  mqtt, home-assistant, homeassistant
Smarthome
SmartHome: firmware per ESP8266 - Casa domotica
Stars: ✭ 28 (-49.09%)
Mutual labels:  mqtt, home-assistant, homeassistant
ha-illuminance
Home Assistant Illuminance Sensor
Stars: ✭ 53 (-3.64%)
Mutual labels:  home-assistant, homeassistant-sensor, homeassistant-integration
Addon Zwave2mqtt
Z-Wave to MQTT - Home Assistant Community Add-ons
Stars: ✭ 58 (+5.45%)
Mutual labels:  mqtt, home-assistant, homeassistant
amshan-homeassistant
Home Assistant integrasjon for strømmålere (AMS/HAN/P1). Integrasjonen støter både streaming (serieport/TCP-IP) og MQTT (Tibber Pulse, energyintelligence.se etc)
Stars: ✭ 39 (-29.09%)
Mutual labels:  mqtt, home-assistant, homeassistant
Home Assistant Configuration
My Home Assistant Config. For more Information visit ->
Stars: ✭ 102 (+85.45%)
Mutual labels:  mqtt, home-assistant, homeassistant
thermal
Thermal Vision Sensor and Camera for Home Assistant
Stars: ✭ 43 (-21.82%)
Mutual labels:  homeassistant, homeassistant-sensor, homeassistant-integration
eufy security
Home Assistant integration to manage Eufy Security devices as cameras, home base stations, doorbells, motion and contact sensors.
Stars: ✭ 242 (+340%)
Mutual labels:  home-assistant, homeassistant, homeassistant-integration
homeassistant-lightwave2
Lightwave RF custom component for Home Assistant. Requires generation 2 ("Link Plus") hub, but will control both generation 1 ("Connect Series") and generation 2 ("Smart Series") devices.
Stars: ✭ 31 (-43.64%)
Mutual labels:  home-assistant, homeassistant
mqtt-mock
mqtt压测工具。支持subscribe、publish压测方式,支持模拟客户端连接数。
Stars: ✭ 78 (+41.82%)
Mutual labels:  mqtt, mqtt-client
addon-example
Example - Home Assistant Community Add-ons
Stars: ✭ 73 (+32.73%)
Mutual labels:  home-assistant, homeassistant
custom-component-store
📦 Manage your custom_components for Home Assistant
Stars: ✭ 12 (-78.18%)
Mutual labels:  home-assistant, homeassistant
better-thermostat-ui-card
a custom card for a better thermostat in home assistant based on ai_thermostat intigration
Stars: ✭ 37 (-32.73%)
Mutual labels:  home-assistant, homeassistant
hhnl.HomeAssistantNet
No description or website provided.
Stars: ✭ 31 (-43.64%)
Mutual labels:  home-assistant, homeassistant
iocage-homeassistant
Home Assistant Core - TrueNAS CORE Community Plugin
Stars: ✭ 61 (+10.91%)
Mutual labels:  home-assistant, homeassistant
soma-ctrl
Node util for controlling SOMA smart shade via MQTT or HTTP
Stars: ✭ 19 (-65.45%)
Mutual labels:  mqtt, home-assistant
addon-matrix
Matrix - Home Assistant Community Add-ons
Stars: ✭ 39 (-29.09%)
Mutual labels:  home-assistant, homeassistant

WyzeSense to MQTT Gateway

PRs Welcome GitHub License GitHub Issues GitHub PRs GitHub Release Python Validation

dockeri.co

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.

Special Thanks

  • HcLX for WyzeSensePy, the core library this project uses.
  • 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.
  • rmoriz for multiarch-test, this allowed the Docker Hub Autobuilder to work for multiple architectures including ARM32v7 (Raspberry Pi) and AMD64 (Linux).

Table of Contents

Installation

Docker

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.

  1. Plug Wyze Sense Bridge into USB port on Docker host. Confirm that it shows up as /dev/hidraw0, if not, update devices entry in Docker Compose file with correct path.
  2. Create a Docker Compose file similar to the following. See Docker Compose Docs for more details on the file format and options. If you would like to help test in development feaures, please change the image to "devel" instead of "latest".
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"
  1. Create your local volume mounts. Use the same folders as selected in the Docker Compose file created above.
mkdir /docker/wyzesense2mqtt/config
mkdir /docker/wyzesense2mqtt/logs
  1. Create or copy a config.yaml file into the config folder (see sample 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 your MQTT details before things will work.
  2. Copy a logging.yaml file into the config folder (see sample below or copy from repository). The script will automatically create a default logging.yaml if one does not exist. You only need to modify this if more complex logging is required.
  3. If desired, 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 sample below or copy from repository)
  4. Start the Docker container
docker-compose up -d
  1. 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, but the sensor version will be unknown.

Linux Systemd

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.

  1. Plug Wyze Sense Bridge into USB port on Linux host.
  2. Pull down a copy of the repository
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
  1. Create local application folders (Select a location that works for you, example uses /wyzesense2mqtt)
mv /tmp/wyzesense2mqtt/wyzesense2mqtt /wyzesense2mqtt
rm -rf /tmp/wyzesense2mqtt
cd /wyzesense2mqtt
mkdir config
mkdir logs
  1. Prepare config.yaml file. You must set MQTT host parameters! Username and password can be blank if unused. (see sample below)
cp samples/config.yaml config/config.yaml
vim config/config.yaml
  1. Modify logging.yaml file if desired (optional)
cp samples/logging.yaml config/logging.yaml
vim config/logging.yaml
  1. If desired, pre-populate a sensors.yaml file with your existing sensors. This file will automatically be created if it doesn't exist. (see sample below) (optional)
cp samples/sensors.yaml config/sensors.yaml
vim config/sensors.yaml
  1. Install dependencies
sudo pip3 install -r requirements.txt
  1. Configure the service
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
  1. 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, but the sensor version will be unknown.

Config Files

The gateway uses three config files located in the config directory. Samples 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.

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.

'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

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.

  1. 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.
  2. 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.

Removing a Sensor

  1. 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.

Reload Sensors

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.

  1. 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.

Command Line Tool

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

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.

Tested On

  • Debian Buster (Docker)
  • Raspbian Buster (RPi 4)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].