Hacking the XiaomiFang Wifi camera

Newbie Question:

I following the link above to setup the MQTT, as embedded MQTT broker has been marked as deprecated , so I install Mosquitto broker addon instead.

On Configuration / Inegrations / MQTT: Mosquitto broker screen,
already turn on “Enable newly added entities”

However, the system show following message:

This integration has no devices.

Did the config is different between Embbed MQTT and Mosquitto MQTT?

Any hints how to enable auto discovery?

Also, how to setup, so I can display the screen like following

:

Is mqtt set up and enabled on the Dafang?

See docs for lovelace.

I’ve two camera set up a Xiaomi Xiaofang 1S and a Xiaomi Dafang. MQTT has been set up and is working for both camera. I want to have an automation, which saves the snapshot on a PI when motion is detected, but for some reason the state of the motions sensors are always off.


I’ve verified, that the motion detection service is running on the cameras, since a red dot is show in the picture, when motion takes place.

These are the services, I got running


I’m looking for help on how to make motion state working.

Next issue.
I realised I’m missing sensors for motion_snapshot. In the log I got this.

Log Details (ERROR)

Sun Oct 20 2019 12:39:00 GMT+0200 (Central European Summer Time)

Exception in async_discover when dispatching 'mqtt_discovery_new_camera_mqtt': ({'name': 'LilleDafang motion snapshot', 'unique_id': '7811dc76ea1e-motion-snapshot', 'device': {'identifiers': '7811dc76ea1e', 'connections': [['mac', '78:11:dc:76:ea:1e']], 'manufacturer': 'Xiaomi', 'model': 'Dafang', 'name': 'Xiaomi Dafang', 'sw_version': 'Dafang Hacks'}, 'topic': 'Kaelder/LilleDafang/motion/snapshot', 'platform': 'mqtt'},)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/camera.py", line 47, in async_discover
    config = PLATFORM_SCHEMA(discovery_payload)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
[u]voluptuous.error.MultipleInvalid: extra keys not allowed @ data['device'[/u]

I guess the last line is the important. Anybody know how to fix this?

Thanks

Upgrading Home Assitant from 0.98 to 0.100 help getting rid of the errors in the log file, but motion dectors are still of in HA

follow the instructions VERY closely and they work. NOTE: if windows just make sure there are no hidden “recovery” directories.

Also, for me the first SD card I used (2GB with 512MB first partition) did not work. I used the exact same steps on a 16Gb card, and it worked just as described. I had the exact same issue with the blue light.

Bottom line, try multiple SD cards until one works.

Is there a way to get the 2-way audio working? Either through HA or an iPhone app? I see that it is possible with Tinycam, but that’s only available on Android and I don’t see an iOS option.
It’s great to be able to see my mailman, but it would be even better if I could talk to him too! I would even be happy with a text-to-speech function so that I can create some preset messages (“please leave the package behind the fence”)

How are you triggering the rest_command? I’ve added this and don’t see it as an entity but I would like to put it on the front end with lovelace.

Sorry only seeing this now.

You can add it to a script, and then it is exposed in lovelace:

  dafang_garden_nightvision_enable:
    alias: Garden Nightvision Enable
    sequence:
      - service: rest_command.dafang_garden_nightvision_enable  
 
  dafang_garden_nightvision_disable:
    alias: Garden Nightvision Disable
    sequence:
      - service: rest_command.dafang_garden_nightvision_disable

There may be a neater way of doing this with a lovelace plugin or button, but I very rarely need to call any rest commands from the UI as they are all handled through automations (sunrise, sunset etc).

Thanks for the reply. My attempts were correct but the password I was using for the camera wasn’t the right one. Once I took the URL of the rest_command and plugged it into a browser that didn’t have the camera’s login and password saved it all clicked.

I just set up two Wyze V2 and one Dafang cam with MQTT. I had previously only been using the RSTP stream. The only reason I even enabled MQTT was so I could grab the light level sensor. With autodiscovery, the only sensor I get is the binary motion sensor. Do I need an extra step to see the light sensor? Has that been disabled since the original post that shows that sensor with a precentage value?

Thanks for any help!

I believe the light sensor is only available on certain variants. My Wyzev2 doesn’t have a working light sensor so they may have disabled that sensor in the dafanghacks fw.

newer dafang cams do not have a hardware light sensor

Hello,

I’m using the last hack (https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks, Version: 2020-03-28T20:47:55Z) for two Dafang Cameras and configured it in HA like Following :

camera:

  • platform: ffmpeg
    name: Cam01
    input: -rtsp_transport tcp -i rtsp://cam01:8554/unicast
  • platform: ffmpeg
    name: Cam02
    input: -rtsp_transport tcp -i rtsp://cam02:8554/unicast

I can see cameras stream, but the MQTT Discovery doesn’t work. When I subscribe the topic myhome/Cam01 ou myhome/Cam02 everything seems ok but the devices are not discovered and I can’t control the camera.

Of course discovery is set to true in MQTT section, prefix ist set to homeassistant and the mqtt.conf file contains the same as documented in homeassistant.md. file of the home assistant integration example.

Has anyone an idea ?

Hello,

I use it without problem.

Have you check under homeassistant/sensor/Cam02 that you have informations?

You can also check in HA int device. If you have nothing you can try to restart mqtt-control service in the camera web interface.

Thanks for reply.
Where do you want me to check that ?
Of course, I’ve restarted mqtt-control several times but it changes nothing. I also tried to configure mqtt in lovelace and in configuration.yaml but it changes nothing.

Is it possible to debug the mqtt Discovery ?

You should check it under HA in Developer Tools and MQTT but I prefet use MQTT Explorer
You connect MQTT Explorer to your MQTT Broker and check it you saw your camera under topic /homeassistant
If this is not the case, you should have a problem on camera side.

Hello Gysmo, thanks for sharing MQTT Explorer tool, great tool.

My cameras are working fine on MQTT side :

image

My main topic is named myhome, I changed it to homeassistant, but it doesn’t change anyting on HA side. So, the hack is working fine, but I think there is a problem with integration on HA side…

For discovering device, HA check /homeassitant.

Have you a main topic homeassistant? If not maybe autodiscover is not well activated in the camera.