ozczecho / wyze-mqtt

A simple wrapper for Kevin Vincent `ha-wyzesense`.
16 stars 4 forks source link

Swimming in the deep #2

Open cocoproxy opened 4 years ago

cocoproxy commented 4 years ago

Does anyone have a minute to help me set this up? Having the Wyzesense plugged into Hass.io on RaspberryPi seemed to make it unstable. So I've moved it to a second RaspberryPi and am hoping I found a suitable solution with wyze-mqtt.

I installed the Mosquitto broker on the HA Pi. Configured it with the instructions provided and it seems to be working.

I'm stuck when it comes to wyze-mqtt. Do I need to do anything with the service.sh file? I'm not running a virtual environment. That file mentions Python3 so I installed that. I'm running this on Raspian 9.8.

As for the config file, here's what I have:

{ "mqtt":{ "host": "hassio.local", "port": 2288, I don't see this anywhere else but it was the default. "user": (user setup in HA), "password": (password setup in HA), "client": "homeassistant" (my best guess) }, "publishTopic":"home/wyze/", "subscribeScanTopic":"ubuntu/wyze/scan", "subscribeRemoveTopic": "ubuntu/wyze/remove", "usb":"/dev/hidraw0" }

Here's what I get back:

● wyze-mqtt.service - Wyzesense via Mqtt Loaded: loaded (/etc/systemd/system/wyze-mqtt.service; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Wed 2020-01-22 05:04:55 UTC; 6s ago Docs: https://www.github.com/ozczecho Process: 8002 ExecStart=/home/mike/wyze/service.sh (code=exited, status=210/CHROOT) Main PID: 8002 (code=exited, status=210/CHROOT)

Jan 22 05:04:55 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Unit entered failed state. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Failed with result 'exit-code'. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Service hold-off time over, scheduling restart. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: Stopped Wyzesense via Mqtt. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Start request repeated too quickly. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: Failed to start Wyzesense via Mqtt. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Unit entered failed state. Jan 22 05:04:55 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Failed with result 'exit-code'.

I'm clearly in over my head here but would love to be able to make efficient use of the Wyze sensors I have.

ozczecho commented 4 years ago

@cocoproxy:

cocoproxy commented 4 years ago

When I try running wyze-mqtt.py directly, I get:

Traceback (most recent call last): File "wyze-mqtt.py", line 1, in import paho.mqtt.client as mqtt ImportError: No module named 'paho'

I installed Paho-mqtt. No change.

When I use your original instructions, I get:

● wyze-mqtt.service - Wyzesense via Mqtt Loaded: loaded (/etc/systemd/system/wyze-mqtt.service; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2020-01-27 06:46:12 UTC; 16s ago Docs: https://www.github.com/ozczecho Process: 881 ExecStart=/home/pi/wyze-mqtt/service.sh (code=exited, status=203/EXEC) Main PID: 881 (code=exited, status=203/EXEC)

Jan 27 06:46:12 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Failed with result 'exit-code'. Jan 27 06:46:12 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Service hold-off time over, scheduling restart. Jan 27 06:46:12 raspberrysquarelinux systemd[1]: Stopped Wyzesense via Mqtt. Jan 27 06:46:12 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Start request repeated too quickly. Jan 27 06:46:12 raspberrysquarelinux systemd[1]: Failed to start Wyzesense via Mqtt. Jan 27 06:46:12 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Unit entered failed state. Jan 27 06:46:12 raspberrysquarelinux systemd[1]: wyze-mqtt.service: Failed with result 'exit-code'.

raetha commented 4 years ago

Hi @cocoproxy, I struggled with some similar things and after getting assistance from a friend on how, managed to get this working nicely in a docker image with all required libraries. Not sure if you are familiar with docker-compose, but if so, feel free to grab my fork update the docker files for you environment and see if it works better for you.

The only issue I've hit so far is that I'm still having things timeout with MQTT. Tweaked that a bit this morning and hoping it will be working still tonight, but won't know until I can trip a sensor or two.

Here's my fork: https://github.com/raetha/wyze-mqtt

Note that I haven't gotten around to updating the documentation at all, so if you aren't sure how to use docker-compose or docker build, let me know and I'll try to toss something together for you.

ozczecho commented 4 years ago

Hi @raetha - Thanks for the PR. I will go through it.

As for the timeout issue, I am currently testing this fix: https://github.com/ozczecho/wyze-mqtt/blob/83b7b6e417cf7a3f8a26041d7fd4e9fce6aae352/wyzesense_custom.py#L115

Also need to increase _CMD_TIMEOUT to more than 5s. For me it has been OK. I am adding more sensors over the weekend so I will test some more.

raetha commented 4 years ago

You are welcome, and feel more than free to pick it apart. I haven't actually written code in around a decade, but got some guidance from a friend who is a heavy HA user and programmer.

On the timeout side, I do seem to be having some luck lowering the MQTT client keepalive to 60. So far things stayed publishing topics over 12 hours yesterday. Don't have an extended use case though as I keep rebuilding the docker container as I've been doing the other changes.

raetha commented 4 years ago

@ozczecho I just wanted to follow up and let you know that whatever I tweaked in the timing and using the original Wyze Sense library seems to have done the trick on timeouts. I've had no issues since. That said, I'm still fleshing out my stuff, so things are rebooting every couple days. But at least over the course of a single day or two it seems stable now to MQTT.

raetha commented 4 years ago

@cocoproxy Not sure if you've worked out another solution or not yet. But if you've got Docker working on your second RPI, I've just finished version 1.0 of a fork I did on this project. It can be found at https://github.com/raetha/wyzesense2mqtt and https://hub.docker.com/r/raetha/wyzesense2mqtt. You can also run it directly in Linux similar to the way this originally worked, but I've got all my smart home stuff running in Docker containers so that I don't have to worry about missing dependencies or anything besides the config files.

Regardless, I'd love some additional testing of things. So if you give it a shot, please leave feedback over there if you need any help.