New Xiaomi aqara camera/gateway

Yes, it should work. Just use different ports. You can even run multiple instances simultaneously with the same camera.

If you have any other Xiaomi camera than the gateway model I will appreciate if you test and report on GitHub issues.

How to we set the output buffer size?

OutPacketBuffer::maxSize

I installed it but no miiocli, shall I report this in github?

It works perfectly with the new aqara camera gateway(lumi.camera.aq1). One thing to note is, if the camera is in sleep mode there won’t be a video to play obviously :slight_smile:
Great work, thank you.

I’ve also tested this with dafang 1080p(isa.camera.df3) and xiaomi mijia 1080p(mijia.camera.v1) and it doesn’t work, at least for me.

Hi @sendorm,
may I have a step by step tasks? i’m stuck since a will
cheers

To get the keys, I used the nox android emulator. Then you have to use this version of mi home app.

Then you have to install the dependencies:

sudo apt-get install build-essential git python3 python3-dev autoconf automake libtool liblivemedia-dev libjson-c-dev

I also needed this one.
sudo pip install netifaces
Finally you can install the miio package with:
sudo pip3 install python-miio

You will also need ffmpeg for this to work. Install it with:
sudo apt-get install ffmpeg

Use this command to see that it works:
sudo mirobo discover --handshake 1
It’ll show the devices but with false keys.

In order to get the keys:
In your nox emulator after syncing the mihome app go to this folder with a root enabled explorer (it comes preinstalled)
/data/data/com.xiaomi.smarthome/databases/
From that folder grab the miio2.db file.
Move that file to your raspberry pi. And then use this command on the folder you put the file:
miio-extract-tokens miio2.db

It’will show all the available tokens for every device.
You need to use this one:

Camera Hub
        Model: lumi.camera.aq1
        IP address: 192.168.xx.xx ->This is the camera
        Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        MAC: xx:xx:xx:xx:xx:xx

After this install the videoP2Proxy program by:

git clone https://github.com/miguelangel-nubla/videoP2Proxy.git
cd videoP2Proxy
./autogen.sh
make
sudo make install

If everything went fine. Use this command to start the feed:

videop2proxy --ip 192.168.xx.xx --token xxxxxxxxxxxxxxxxxxxxx --rtsp 8554

192.168.xx.xx is the camera ip and the command starts a rtsp stream on your rpi with ip 192.168.yy.yy.
Check the feed with VLC from address rtsp://192.168.yy.yy:8554 Make sure the camera is not in sleep mode.

For the homeassistant part. Make a shell command in your configuration.yaml file:

shell_command: 
  camera_on: 'videop2proxy --ip 192.168.xx.xx --token xxxxxxxxxxxxxxxxxxxxxx --rtsp 8554'

Call this command when homeassistant starts:

- id: autoXX
  alias: Start Scripts
  hide_entity: false
  trigger:
    platform: homeassistant
    event: start
  action:
  - service: shell_command.camera_on

And finally use this as a new camera entity:

camera:
  - platform: ffmpeg
    input: -rtsp_transport tcp -i rtsp://192.168.yy.yy:8554/

In order to stop the feed, I’ve opened an issue on videop2proxy github page. But from miio issues page I’ve found these commands and they work. This makes the camera sleep
miiocli device --ip 192.168.xx.xx --token xxxxxxxxxxxxxxxxxxxxxxxx raw_command set_video '["off"]'
This makes the sleep off
miiocli device --ip 192.168.xx.xx --token xxxxxxxxxxxxxxxxxxxxxxxx raw_command set_video '["on"]'

Use them like this:

shell_command: 
  camera_on: 'videop2proxy --ip 192.168.xx.xx --token 473055577175774b4369774835553044 --rtsp 8554'
  camera_video_on: "miiocli device --ip 192.168.xx.xx --token 473055577175774b4369774835553044 raw_command set_video '[\"on\"]'"
  camera_video_off: "miiocli device --ip 192.168.xx.xx --token 473055577175774b4369774835553044 raw_command set_video '[\"off\"]'"
2 Likes

thanks a lot, will test this night :slight_smile:

Thanks for the info. Tried the procedure on my Macbook & RPi3-with-HA. I think i get all the steps up to finding the miio2.db (including a successful mirobo discover test and seeing my devices in the emulated Xiaomi app), but Nox on my Macbook does not give me the mentioned path/folder. I do find a “com.xiaomi.smarthome/” in /sdcard/Andriod/data/com.xiaomi.smarthome, but don’t find a databases, only a “cache” and “files”.

you have to enable “root” access mode in the file manager. go to settings, then change the access mode there. Then you’ll see all the items.

You mean start “ES File Explorer”, hamburger menu top left, scroll down, toggle option “Root Explorer”? I get a “Sorry, test failed. This feature cannot run on your device.”

No, you should use the built in “File Manager” app. I’ve also tried the es file explorer app at first, but as you mentioned couldn’t get it to work either.

I can’t find how to use the root option in that file manager :confused:

Open up the file manager app. Press the three dots on right bottom. That’s the settings. Choose general settings. Press the “Access mode”. Choose “Root access mode”. You should be able to see the files at that moment.

Access Mode is greyed out, stating “Safe mode - the app is running without priveleges ”. Clicking it does nothing for me, i’m not offered any choice to change it.

Just found a tiny grey-on-black ‘settings’ icon in the top right corner of Nox … having an option ‘Root’ in Off mode … switched it to On, Clicked Save, emulator rebooted > have the option now. Sorry, and thank you for the help… Will try to find time to proceed your procedure…

You beat me to the answer :slight_smile: Good luck.

1 Like

Sorry, i missed your message. Frankly spoken, I’m a complete zero in MIIO, sorry :pensive:

How can I install this on hass.io? I have no ssh access to my Pi3 so cannot sudo install. I can install ffmpeg by creating a line in the configuation.yaml. How can I install Netifaces, python-miio (or are both allready installed with hass.io?) and how can I install videoP2Proxy?

Hope you can help and I can test it :slight_smile:

1 Like

I have no information about hass.io. Never used it. Sorry.

Is there anybody who could put together a guide to set this up in hass.io? Ideally both as a camera and a gateway, seems like lots of people could do with the implementation. Thanks!

2 Likes