Logitech Media Server (LMS) dzVents adapter
Posted: Sunday 12 November 2017 22:47
Hi !
I have made very simple custom dzVents' adapter for Logitech Media Server (LMS) based on adapter for "Kodi". Its look like this.
Without changed in code Domoticz (only add adapter) I can play song in mp3 from "playlist" Favorites and my own defined (Test1 and Test2) from LMS (Synlogy) on my phone (android) with very cheap apps "Squeeze player".
(LMS and domoticz -> https://www.domoticz.com/wiki/Logitech_Media_Server)
My example of dzVents script looks like this (1 device to play song and 1 switch dummy for action):
Ok. Now problems.
1. First -For some reason I can do only One (last one !) valid command with lms for One period of script. (so that's reason I commented on other commands in the example)
When i try do 2 command for example SetVolume() and PlayPlayList() only one command is made by eventhandler.
I dont know how this fix.
2. Unfortunately, the command "afterSec(x)" does not work for this device so i cant do lms.lmsSetVolume(20) and next lms.lmsPlayFavorites(4).afterSec(5)
3. If I want to choose a song from my favorite list, little change in EventSystem.cpp in function CEventSystem::ScheduleEvent is needed like this.
but without bigger changed in domoticz its not possible choose song from "custom list" (Test1 or Test2).
Can anyone help me with this problems ?.
I have made very simple custom dzVents' adapter for Logitech Media Server (LMS) based on adapter for "Kodi". Its look like this.
Code: Select all
return {
baseType = 'device',
name = 'lms device',
matches = function (device, adapterManager)
local res = (device.hardwareType == 'Logitech Media Server')
if (not res) then
adapterManager.addDummyMethod(device, 'lmsSwitchOff')
adapterManager.addDummyMethod(device, 'lmsStop')
adapterManager.addDummyMethod(device, 'lmsPlay')
adapterManager.addDummyMethod(device, 'lmsPause')
adapterManager.addDummyMethod(device, 'lmsSetVolume')
adapterManager.addDummyMethod(device, 'lmsPlayPlaylist')
adapterManager.addDummyMethod(device, 'lmsPlayFavorites')
end
return res
end,
process = function (device, data, domoticz, utils, adapterManager)
function device.lmsSwitchOff()
--return TimedCommand(domoticz, device.name, 'Off')
domoticz.sendCommand(device.name, 'Off')
end
function device.lmsStop()
--return TimedCommand(domoticz, device.name, 'Stop')
domoticz.sendCommand(device.name, 'Stop')
end
function device.lmsPlay()
--return TimedCommand(domoticz, device.name, 'Play')
domoticz.sendCommand(device.name, 'Play')
end
function device.lmsPause()
--return TimedCommand(domoticz, device.name, 'Pause')
domoticz.sendCommand(device.name, 'Pause')
end
function device.lmsSetVolume(value)
if (value < 0 or value > 100) then
utils.log('Volume must be between 0 and 100. Value = ' .. tostring(value), utils.LOG_ERROR)
else
--return TimedCommand(domoticz, device.name, 'Pause')
domoticz.sendCommand(device.name, 'Set Volume ' .. tostring(value))
end
end
function device.lmsPlayPlaylist(name)
if (position == nil) then
position = ''
end
domoticz.sendCommand(device.name, 'Play Playlist ' .. tostring(name))
end
function device.lmsPlayFavorites(position)
if (position == nil) then
position = 0
end
domoticz.sendCommand(device.name, 'Play Favorites ' .. tostring(position))
end
end
}
(LMS and domoticz -> https://www.domoticz.com/wiki/Logitech_Media_Server)
My example of dzVents script looks like this (1 device to play song and 1 switch dummy for action):
Code: Select all
local lmsDevice='samsung SM-J500FN' -- lms devices to play songs.
return {
on = {
devices = {
'test1' -- dummy switch devices
}
},
execute = function(domoticz, mySwitch)
local lms = domoticz.devices(lmsDevice)
--lms.lmsSetVolume(20)
if mySwitch.state=='On' then
lms.lmsPlayPlaylist('Test2') -- play playlist with name "Test2"
--lms.lmsPlay()
end
if mySwitch.state=='Off' then
lms.lmsPlayPlaylist('Test1') -- play playlist with name "Test1"
--lms.lmsPlayFavorites(4)
--lms.lmsPause()
--lms.lmsStop()
--lms.lmsSwitchOff()
end
end
}
1. First -For some reason I can do only One (last one !) valid command with lms for One period of script. (so that's reason I commented on other commands in the example)
When i try do 2 command for example SetVolume() and PlayPlayList() only one command is made by eventhandler.
I dont know how this fix.
Code: Select all
2017-11-12 22:54:31.599 dzVents: Info: Handling events for: "test1", value: "On"
2017-11-12 22:54:31.599 dzVents: Info: ------ Start internal script: lms: Device: "test1 (Dummy)", Index: 2
2017-11-12 22:54:31.600 dzVents: Info: ------ Finished lms
2017-11-12 22:54:31.601 Command=Set Volume 20, FOR=0.00, AFTER=0.00, RANDOM=0.00, REPEAT=1 INTERVAL 0.00
2017-11-12 22:54:31.602 EventSystem: Scheduled Set Volume after 0.00.
2017-11-12 22:54:31.602 Command=Play Playlist Test2, FOR=0.00, AFTER=0.00, RANDOM=0.00, REPEAT=1 INTERVAL 0.00
2017-11-12 22:54:31.603 EventSystem: Scheduled Play Playlist after 0.00.
2017-11-12 22:54:31.603 EventSystem: Script event triggered: dzVents\runtime\dzVents.lua
2017-11-12 22:54:32.026 EventSystem: {"id":1,"method":"slim.request","params":["8c:27:6e:f9:ab:d2",["playlist", "play", "Test2"]]}
3. If I want to choose a song from my favorite list, little change in EventSystem.cpp in function CEventSystem::ScheduleEvent is needed like this.
Code: Select all
if (pBaseHardware == NULL) // if not handled try Logitech
{
pBaseHardware = m_mainworker.GetHardwareByType(HTYPE_LogitechMediaServer);
if (pBaseHardware == NULL) return false;
CLogitechMediaServer *pHardware = reinterpret_cast<CLogitechMediaServer*>(pBaseHardware);
if (sParams.length() > 0)
{
level = atoi(sParams.c_str());
}
}
but without bigger changed in domoticz its not possible choose song from "custom list" (Test1 or Test2).
Can anyone help me with this problems ?.