Hacking the XiaomiFang Wifi camera

Hi,

Could you keep the rtsp server and have a still image? This latter is required for creating a camera. Note that I’d like to use the stream integration to be able to stream to a Lovelace card.

You can have a still image and the rtsp stream. Mine is

camera:
  - platform: generic
    still_image_url: https://user:[email protected]/cgi-bin/currentpic.cgi
    name: foyer
    verify_ssl: false
    authentication: digest
    stream_source: rtsp://dafang.lan:8554/unicast

Thanks @nickrout.
Mine does not have the currentpic.cgi.
I used ffmpeg and it’s working.

I’ve noticed the mqtt entities show unavailable after a HA reboot. Is there a group topic I can send to them to get them to update again? Only way I can get them to show in HA again is by rebooting the cameras.

Do your discovery messages have the retain flag set?

1 Like

I haven’t set this myself. I can see an option in mqtt.conf for MOSQUITTOPUBOPTS="" but this is for all messages, not sure if I want to do that?

Also I’d like HA to trigger a custom script on the camera, is this possible? I might put it in as a feature request if not.

Sure, use a commandline switch

I added “-r” in mqtt.conf but I’m still getting occasions after rebooting they go back to unavailable.

Hi i don’t have sounf in my home assistant

I used have sound in vlc.

Do you gave idea?

Hello guys.

I am running into some troubles configuring mqtt integration.
But there is no sensors discovered by mqtt integration :frowning:

I can see the moquitto logs:

1590581586: New connection from 192.168.1.126 on port 1883.
1590581586: New client connected from 192.168.1.126 as mosqpub|9227-DAFANG (p1, c1, k60, u'mqtt').
1590581586: Client mosqpub|9227-DAFANG disconnected.

Occasionally the this line is logged to:

[WARN] Not found homeassistant on local database

Looking into these treads i realize I shouldn’t use homeassistant as LOCATION. So I change it and restart the services. But it keeps being logged.

In config.yaml I have:

mqtt:
  broker: localhost
  discovery: true
  discovery_prefix: homeassistant

and my mqtt.conf is:

> ############################################################
> # edit this file and move it to /system/sdcard/config/mqtt.conf #
> ############################################################
> 
> export LD_LIBRARY_PATH='/thirdlib:/system/lib:/system/sdcard/lib'
> 
> # Options for mosquitto_sub & mosquitto_pub
> USER=<home assistant dedicated user>
> PASS=<home assistant dedicated user's password>
> HOST=192.168.1.187
> PORT=1883
> 
> # Define a location
> LOCATION="garage"
> 
> # Define device name
> DEVICE_NAME="dafang"
> 
> # Define the base topic used by the camera
> # send a message to myhome/dafang/set with the payload help for help.
> # Results will be placed in myhome/dafang/${command} or topic/dafang/error - so please subscribe topic/dafang/# for testing purposes
> TOPIC="$LOCATION/$DEVICE_NAME"
> 
> # Define an autodiscovery prefix, if autodiscovery is desired:
> AUTODISCOVERY_PREFIX="homeassistant"
> 
> # Define additional options for Mosquitto here.
> # For example --cafile /system/sdcard/config/DST_Root_CA_X3.pem --tls-version tlsv1
> # or use a special id to connect to brokers like azure
> MOSQUITTOOPTS=""
> 
> # Add options for mosquitto_pub like -r for retaining messages
> MOSQUITTOPUBOPTS=""
> 
> # Send a mqtt statusupdate every n seconds
> STATUSINTERVAL=30
> 
> # Define whether you would like to have light level exposed (by hardware sensor og virtual calcuations).
> # If the device doesn't come with a hardware sensor, your only option is to use 'virtual'.
> #
> #  Options:
> #     hw = Use 'hw' if the device has build in hardware light sensor. For more details, see . See issue eg. #1120 for more details...
> #     virtual = Use 'virtual' calculations, based on the lightlevel on the image, also known as ISP exposure (from /proc/jz/isp/isp_info)
> #     false = Use 'false' (default) to DISABLE the topic (It will not publishing details about light level)
> LIGHT_SENSOR="false"

I am quite new using mqtt so it is possible I was missing something!
Any idea?

thanks a lot

only difference is I have username/password in configuration.yaml:

mqtt:
  broker: 192.168.1.128
  port: 1883
  username: homeassist
  password: password
  discovery: true
  discovery_prefix: homeassistant

When I following the mosquito installation documentation it asks to create an HA user. Is that user that I was configured in mqtt.conf file.

Is this the user you put in your configuration.yaml? Because I am trying it with same result :frowning:

when you installed mosquito (or rather, configured it), you would have set up a user account.

you need to let both the camera AND HASS know what it is.

Yes - homeassist is the account I set up mosquito with, and have told HA to use, and the dafang to use:

walaj@JonLabNUC:/$ cat /etc/mosquitto/passwd
homeassist:passwordystuffhashedandsalted

Yap. That’s what I did. no success :frowning:
However the camera behavior itself does not seems good to me.
I will try do star all over again from the begging.

is anyone having issues with stream_source not working

camera:
  - platform: generic
    name: garage
    username: root
    password: ismart12
    authentication: basic
    still_image_url: https://192.168.30.41/cgi-bin/currentpic.cgi
    stream_source: rtsp://192.168.30.41:8554/unicast
    verify_ssl: false
    scan_interval: 5

The still image works fine but stream never loads (i do have “stream:” specified above in my config)

whereas

camera:
  - platform: ffmpeg
    name: garage
    input: rtsp://192.168.30.41:8554/unicast

Works fine

Yep, seeying the same and cant figure out what is going on. No errors and I think I have it all setup correctly (using Home Assistant through Docker).

[edit]
My bad. Got it working with this setup. So explicitly set the username and password for the rtsp stream as this is different than the root user in my case.

- platform: generic
    name: Xiaomi Dafang
    verify_ssl: false
    username: root
    password: !secret xiaomi_camera
    authentication: basic
    still_image_url: https://192.168.0.145/cgi-bin/currentpic.cgi
    stream_source: rtsp://streamuser:[email protected]:8554/unicast
1 Like

Is it possible to turn off/on the cam via the action.cgi or some command inside the ssh of the cam?
This to avoid unplugging it from the power to turn it off and have instead that control through HA.
thanks !

Great post, very useful and thanks everyone.

I am having a hard time finding how to invert the stream and the image url. My camera in mounted upside-down…

How do I go about to do this in the camera Dafang page or in HA config? is there a switch to enable?

Here is my config:

  • platform: generic
    name: C777B_Wyze
    username: !secret wyzecamera_user
    password: !secret wyzecamera_pw
    authentication: basic
    still_image_url: https://xxx.xxx.x.xxx/cgi-bin/currentpic.cgi
    stream_source: rtsp://xxx.xxx.x.xxx:xxxx/unicast
    framerate: 5
    verify_ssl: false
    scan_interval: 5

Cheers

Found my own answer after a good night sleep!..

Under configuration>video>RTSP…Image Flip

Cheers