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\"]'"