Xiaomi gateway and IP radio

Here there is a project for listen radio with Xiaomi gateway. May openhab change radio station?

1 Like

Yes.
команда для установки своего радио

{"id":1,"method":"play_specify_fm","params":{"id":5217820069,"type":0,"url":"http:\/\/ximiraga.ru\/52778243643c5f1814c15.m3u8"}}

{"id":1,"method":"play_specify_fm","params":{"id":527782833,"type":0,"url":"http:\/\/ximiraga.ru\/52778283343c5f1814c15.m3u8"}}

правила для радио

rule "Radio ON"
 when Item gateway_send_radio changed
 then
    if(gateway_send_radio.state==ON){
    gateway_send_command.sendCommand("play_fm[\"on\"]")
    logInfo("Events", "gateway_send_command "+gateway_send_command.state)
    }
    else {
    gateway_send_command.sendCommand("play_fm[\"off\"]")
    logInfo("Events", "gateway_send_command "+gateway_send_command.state)
}
end

rule "Volume"
 when Item radio_volume changed
 then
    var state = radio_volume.state.toString
    /*var begin = "volume_ctrl_fm[\""
    var en = "\"]"
    gateway_send_command.sendCommand(begin+state+en)*/
    gateway_send_command.sendCommand("volume_ctrl_fm[\""+state+"\"]")
    logInfo("Events", "gateway_send_command "+gateway_send_command.state)
end

итемы для радио

//Радио
String gateway_send_command "gateway_send_command[]" {channel="miio:basic:3ac225ee:actions#commands"}
Switch gateway_send_radio "gateway_send_radioon"    {channel=""}
Number radio_volume "Громкость" {channel=""}
1 Like

I’ll add those commands to the json db, than you no longer need a rule for it.

In the mean time you can also drop this in the conf/misc/miio folder, then the channels are created and send similar commands as your rule
lumi.gateway.json (2.6 KB)

1 Like

thank you!

You may also wanna try to send the below commands, than they can maybe implemented as well (pls let me know the response you receie from the gateway)

get_channels[]
get_channels["start": 1]
get_default_music[]
get_prop_fm[]
get_mute[] if this works, you may also try the set_mute["on"] or similar
get_fm_volume[]

note, do you know the difference between the volume control & the set_fm_volume[] command?

1 Like
get_channels[]
{"result":{"chs":[{"id":5,"type":0,"url":"http:\/\/live.xmcdn.com\/live\/5\/64.m3u8"},{"id":12,"type":0,"url":"http:\/\/live.xmcdn.com\/live\/12\/64.m3u8"}]},"id":65022}

get_channels["start": 1]
{"result":{"chs":[{"id":12,"type":0,"url":"http:\/\/live.xmcdn.com\/live\/12\/64.m3u8"}]},"id":65022}

get_prop_fm[]
{"result":{"current_program":922852773,"current_progress":0,"current_volume":2,"current_status":"pause"},"id":65022}

get_mute[]
{"result":["off"],"id":65022}

this paramets i could get

do you know the difference between the volume control & the set_fm_volume[] command?
no I dont know. Can you explain me?

1 Like

set_fm_volume has a string type. if I want to use setpoint in my sitemap i need a rule to convert it?

{“result”:[“ok”],“id”:65022}

I’m afraid so… I’m not sure if currently the binding allows to send numbers as string.
Maybe it can be tricked in doing so… I’ll do bit of experimenting here.

Are you confident it really needs a string, as the response from the get_prop_fm gives a number for the current_volume.
If it is a number, it can be changed in the db to a “Number” type and you can indeed link it to a slider

in lumi.gateway.json I changed volume_ctrl_fm to NUMBER and type to Number, and it stoped work(