roleoroleo / sonoff-hack

Custom firmware for Sonoff GK-200MP2B camera
GNU General Public License v3.0
200 stars 45 forks source link

Discovery ha #115

Closed darkxst closed 1 year ago

darkxst commented 1 year ago

I have linked in cJSON library, updated Mosquitto to latest 2.0 release and implemented HA autodiscovery. A few bits and bobs to still be done

roleoroleo commented 1 year ago
* It would be nice to include firmware version in device registry, but should this be son-hack version or camera version?

Probably the hack version would be better.

* I have kept the state topics 100% backwards compatible, however probably they should use the unique id as set in config messages, at least by default. Still allowing people to override as before?

I don't understand, explain me better.

darkxst commented 1 year ago

The config topics are set like this (using device id): homeassistant/binary_sensor/<unique_id>/config for example: homeassistant/binary_sensor/a620000009_motion/config

and currently the state topic will follow whatever is set in the web UI, by default its: sonoffcam/motion_detection

Given the user should not need to know state topic anymore (unless they disable discovery or are using some other platform). Could make the default state topic using the device id also. Which will also work with multiple cameras. Something like: a620000009/motion_detection or sonoffcam/a620000009/motion_detection

Also perhaps the Mosquitto client Id could also just be set to the device id and removed from the WebUI?

darkxst commented 1 year ago

btw, I bumped the Sonoff-hack version to 0.1.4beta in that last commit, with the idea being you can update that before tagging the release and then when further major changes land, can bump again to 0.1.5beta;)

roleoroleo commented 1 year ago

Also perhaps the Mosquitto client Id could also just be set to the device id and removed from the WebUI?

Yes. It could be removed.

darkxst commented 1 year ago

I have remove the mqtt client ID setting, and changed the default topic, however this will only apply to new installs and not existing install.

darkxst commented 1 year ago

@roleoroleo I have stitched together mqtt subscribe/command topics for switching detection on and off, can easily be extended to sensitivity and rotation. However it doesn't take affect in real-time (including my later testing this via the webui. doh!) Do these settings work in real-time on the older firmwares?

Anyways will hold that code off for a future PR as its not fully complete yet!

roleoroleo commented 1 year ago

I started some tests. About cJSON the build process completes successfully, I have a problem with stripping: /usr/bin/strip: Unable to recognise the format of the input file /home/user/sonoff/sonoff-hack/src/cJSON/_install/lib/libcjson.so.1.7.15 It's trying to use the strip of the host (I'm not using devcontainer).

EDIT

Sorry, my fault. Strip is ok.

roleoroleo commented 1 year ago

mosquitto patch seems not to work:

Initializing mosquitto...

HEAD is now at b0277869 Update changelog for last minute fix
patching file lib/dummypthread.h
patching file lib/thread_mosq.c
Hunk #1 FAILED at 43.
1 out of 1 hunk FAILED -- saving rejects to file lib/thread_mosq.c.rej
darkxst commented 1 year ago

mosquitto patch seems not to work:

Has the mosquitto git submodule updated? it should be at the v2.0.15 tag.

Edit: Looks like it should have from your reset message, however not sure why it would be failing otherwise. Can you paste the contents of the c.rej file

roleoroleo commented 1 year ago

I updated to b0277869. Is it correct?

EDIT

I downloaded the pr again and the problem disappeared. I don't know why. Unfortunately I didn't save the prevoius content of the folder.

roleoroleo commented 1 year ago

I completed my tests. I tested the build process and the regressions of mqtt-sonoff. I didn't check ha side. If you agree I can merge the pr.

darkxst commented 1 year ago

yes this pr is all good to merge, go ahead. Thanks