EliasKotlyar / Xiaomi-Dafang-Hacks

4.16k stars 1k forks source link

MQTT Control issues with newer Home Assistant #1881

Closed ambarusa closed 7 months ago

ambarusa commented 7 months ago

Description

My Xiaomi Dafang camera doesn't react to Home Assistant commands, with version 2023.11.

What did you do to debug the issue

I used MQTT Explorer to see the traffic from the HA, where everything seemed normal, it publishes ON command to /motion/detection/set topic. On the camera, I was trying to run mqtt_control.sh script manually, which throws this error:

/system/sdcard/bin/setconf: option requires an argument -- v
Invalid Argument ?
Usage /system/sdcard/bin/setconf -g -k KEY -v VALUE
Where k to set value, g to get the value
        'f' flip mode set to
                '1' -> flip on
                '0' -> flip off
        'n' night mode set to
                '1' -> night mode on
                '0' -> night mode off
        'b' set bitrate to VALUE
        'o' OSD text set to VALUE
        'c' OSD color set VALUE to
                '0' for White
                '1' for Black
                '2' for Red
                '3' for Green
                '4' for Blue
                '5' for Cyan
                '6' for Yellow
                '7' for Purple
                '0xAABBCCDD' for RBGA format
                'AA,BB,CC,DD' for RBGA format
                '0xAA,0xBB,0xCC,0xDD' for RBGA format
        'x' OSD position Y pos is set to VALUE
        's' OSD size
        'e' OSD font name (ttf)
        'p' OSD space between char is set to VALUE (can be negative)
        'w' fixed text width (0 variable, 1 fixed)
        'm' motion sensitivity (0 to 4) -1 to deactivate motion
        'z' display a circle when motion detected (-1 deactivated, use the OSD color numbers)
        'r' set detection region (shall be: X0n,Y0n,X1n,Y1n,X0n+1,Y0n+1,X1n+1,Y1n+1, ...) the server need to be restarted to take into account the new value
                 it is possible to determine up to 52 regions
        't' set tracking on/off (detection region is not taken into account anymore)
        'u' set time before launching script after no motion (to restore camera position) -1 to deactivate
        'h' set hardware volume (from mic)
        'i' set software volume percentage (X will add X44 the data, from 0 to xxx, -1 to do nothing)
        'q' set set filter number (1 or 2, 0 no filter)
        'l' set set highpass filter on/off
        'a' set set aec filter on/off
        'd' set frame rate (shall be FrmRateNum,FrmRateDen (example: 25,1 to get 25 images per second)
Example: to set osd text: /system/sdcard/bin/setconf -k o -v OSDTEXT
         to get osd text: /system/sdcard/bin/setconf -g o

Evidence

Please let me know whatever you need.

Contribute Back

If your issue was resolved, please consider contributing back to the project by creating a pull request to improve the code or documentation in order to avoid that this issue arises again for other people.

Thank you very much!

ambarusa commented 7 months ago

After digging into mqtt-control.sh -> common_functions.sh -> motion_detection() and get_config() functions, I realised that motion_sensitivity was not stored in the /system/sdcard/config/motion.conf file, messing up the future function calls in the flow.

This usually happened to me when the SD card got full, by storing too many captures from motion detections. Not just this parameter, but others got disappeared as well, for example the MQTT username. Keep always in mind to maintain the storage space, and double check if the settings are retained.