return {
on = {
--timer = {'every minute'},
devices = {'miGateway FM', 'miGateway FM - Source'}
},
logging = {
level = domoticz.LOG_ERROR
},
execute = function(dz, item)
local Path = "/home/pi/php-miio/" -- php-miio path
local IP = '192.168.1.50' -- Xiaomi Gateway IP
local Token = 'x1x1x1x1x1x1x1x1x1x1x1x1x1x1x1x1' -- Xiaomi Gateway Token
local FM = dz.devices('miGateway FM')
local Source = dz.devices('miGateway FM - Source')
-- Channel ID, Channel Name
ch1ID, ch1Name = '527782024', 'Европа Плюс'
ch2ID, ch2Name = '527782027', 'Top 100 Rap'
ch3ID, ch3Name = '527782029', 'Energy FM'
ch4ID, ch4Name = '527782034', 'Sound Park Deep'
ch5ID, ch5Name = '527782069', 'Аплюс Relax BY'
chID = {}
chID[#chID+1] = {ch1ID, ch1Name}
chID[#chID+1] = {ch2ID, ch2Name}
chID[#chID+1] = {ch3ID, ch3Name}
chID[#chID+1] = {ch4ID, ch4Name}
chID[#chID+1] = {ch5ID, ch5Name}
function SendCommand()
cmd = "cd "..Path.." && php miio-cli.php --ip "..IP.." --token "..Token.." --sendcmd '{\"id\":1,\"method\":\""..method.."\",\"params\":"..param.."}'"
end
if (item.isDevice) then
if (item.name == 'miGateway FM') then
if (item.levelName == 'Get Channel ID') then
method = "get_prop_fm"
param = "[]"
SendCommand()
local h = io.popen(cmd)
local r = h:read("*a")
h:close()
_, _, num1, num2, num3, num4, channel = string.find(r, "(%d+)[^%d]+(%d+)[^%d]+(%d+)[^%d]+(%d+)[^%d]+(%d+)[^%d]")
print('Channel ID = '..channel)
item.switchOff().afterSec(1).silent()
else
method = "play_fm"
if (item.levelName == 'On') then
param = "[\"on\"]"
elseif
(item.levelName == 'Off') then
param = "[\"off\"]"
Source.switchOff().checkFirst().silent()
end
SendCommand()
dz.utils.osExecute('('..cmd..' > /dev/null)&')
end
end
if (item.name == 'miGateway FM - Source') then
if (item.state == 'Off') then
method = "play_fm"
param = "[\"off\"]"
dz.devices('miGateway FM').switchOff().silent()
else
for i in pairs(chID) do
if (item.levelName == chID[i][2]) then
method = "play_specify_fm"
param = "["..chID[i][1].."]"
if (FM.levelName ~= 'On') then
FM.switchSelector(30).silent()
end
end
end
end
SendCommand()
dz.utils.osExecute('('..cmd..' > /dev/null)&')
end
end
if (item.isTimer) then
method = "get_prop_fm"
param = "[]"
SendCommand()
local h = io.popen(cmd)
local r = h:read("*a")
h:close()
if (string.find(r, '"pause"')) then
Source.switchOff().checkFirst().silent()
FM.switchOff().checkFirst().silent()
end
if (string.find(r, '"run"')) then
_, _, num1, num2, num3, num4, channel = string.find(r, "(%d+)[^%d]+(%d+)[^%d]+(%d+)[^%d]+(%d+)[^%d]+(%d+)[^%d]")
if (channel == ch1ID and Source.levelName ~= ch1Name) then Source.switchSelector(10).silent()
elseif (channel == ch2ID and Source.levelName ~= ch2Name) then Source.switchSelector(20).silent()
elseif (channel == ch3ID and Source.levelName ~= ch3Name) then Source.switchSelector(30).silent()
elseif (channel == ch4ID and Source.levelName ~= ch4Name) then Source.switchSelector(40).silent()
elseif (channel == ch5ID and Source.levelName ~= ch5Name) then Source.switchSelector(50).silent()
elseif (channel ~= ch1ID)
and (channel ~= ch2ID)
and (channel ~= ch3ID)
and (channel ~= ch4ID)
and (channel ~= ch5ID) then
if (Source.levelName ~= 'Unknown') then
Source.switchSelector(60).silent()
end
end
if (FM.levelName ~= 'On') then
FM.switchSelector(30).silent()
end
end
end
end
}
Play a favorite channel in the MiHome app. In the Domoticz GUI click on the Get Channel ID on the miGateway FM switch. The ID of the channel will be shown in the log.