Giter VIP home page Giter VIP logo

wyze-mqtt's Introduction

Wyze sense Mqtt wrapper

A wrapper for the excellent Kevin Vincent (https://github.com/kevinvincent/ha-wyzesense) wyze sense library.Kevins library needs the wyze sense hub to be plugged into a USB port where Home Assistant is running. All my USB ports were taken so I wrote this little wrapper that allows me to run the wyze hub on another machine and communicate with Home Assistant via MQTT.

Setup

I have included a simple unit file so that the wrapper can be setup to run as a systemd service. Edit the files as required.

  • sudo cp wyze-mqtt.service /etc/systemd/system/
  • Edit the service file to suit your requirements
  • sudo systemctl daemon-reload
  • sudo systemctl start wyze-mqtt
  • sudo systemctl status wyze-mqtt

Config file

The wrapper relies on a config file to be present in the same directory. The config file has to be called config.json. A sample is included below:

{
    "mqtt":{
        "host": "Mqtt host",
        "port": "Mqtt port",
        "user": "Mqtt username",
        "password": "Mqtt password",
        "client": "Mqtt client name"
    },
    "publishTopic":"/wyze/",
    "publishScanResult":"home/wyze/newdevice",
    "subscribeScanTopic":"/wyze/scan",
    "subscribeRemoveTopic": "/wyze/remove",
    "usb":"/dev/hidraw0"
}

Home Assistant

To add sensors to the wyze hub, you need to publish a message from Home Assistant that will trigger the scan on the wyze-mqtt wrapper. This is done by publishing to topic defined under subscribeScanTopic. If successful the wrapper will respond with the newly added sensors MAC address. Add the following automation in home assisant to receive the newly added MAC addresses

- alias: Listen for new wyze sense sensors added to hub.
  initial_state: true
  trigger:
    - platform: mqtt
      topic: 'home/wyze/newdevice'
  action:
    - service: persistent_notification.create
      data_template:
        title: Wyze Sense Sensors Discovery
        message: "{{ trigger.payload}}"

Some sample configurations in Home Assistant. One is for a door / window sensor and the other is for a motion sensor.

binary_sensor:
  - platform: mqtt
    name: A Window
    state_topic: "home/wyze/123456789"
    device_class: "window"
    value_template: "{{ value_json.state }}" 
    payload_on: 1
    payload_off: 0

sensor:
  - platform: mqtt
    name: A Motion
    state_topic: "home/wyze/987654321"
    value_template: "{{ value_json.state }}"  
    force_update: true  

Todo

  • Add support for removing sensors.
  • Proper logging
  • Mqtt sometimes gets a connection timeout and does not reconnect.

Tested

Tested on Windows 10 running Ubuntu in a virtual machine.

wyze-mqtt's People

Contributors

ozczecho avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.