Need miio (any flavour - php-miio, python-miio, etc.) and available gateway token and IP (token you can look in mihome, at page where you switch on developer's mode).
1. Convert the source mp3 into aac for gateway:
Code: Select all
ffmpeg -i 18Track.mp3 -b:a 64k tr18a.aac
2. Place converted file into place available from gateway by http (m.b. other proto works also; didn't check).
I used webserver on my router; but it is also possible to make it available via dz (however it doesn't return correct mimetype for aac, but downloading via it still works).
3. Via miio with correct ip/token send the command:
Code: Select all
{"id":1,"method":"download_user_music","params":["5001","http://192.168.1.150/media/music/tr18.aac"]}
Here first param is musicID, must be >=1000. Second is url where gateway will take the music.
4. Periodically check the progress (since donwload command is async):
Code: Select all
{"id":1,"method":"get_download_progress","params":[]}
It will return progress for each music ID in %. Finally you'll take:
5. Play the music. There are two possible ways: by MusicID (which is string), or by index (which is numeric). In first case you can also set the volume
Code: Select all
{"id":1,"method":"play_music","params":[5001]}
Code: Select all
{"id":1,"method":"play_music_new","params":["5001",10]}
Now you can set MusicID as the custom variable and play/stop it via existing xiaomi gateway buttons. In MiHome this record will be nameless.
Other useful commands are
Code: Select all
{"id":1,"method":"get_music_info","params":[0]}
- get list of available music (params m.b. 0,1,2 for 'system' banks, >2 will return list of user music).
Code: Select all
{"id":1,"method":"delete_user_music","params":["5001"]}
Code: Select all
{"id":1,"method":"get_music_free_space","params":[]}
- returns available bytes. On 'fresh' gw it is about 11Mb available.