Page 2 of 2

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Saturday 16 March 2019 15:23
by waaren
stephanvdplas wrote: Saturday 16 March 2019 12:04 Hello, I use the LMS DZVents adapter with much pleasure. I've only got a small feature request.
Is it possible to expand this function with VolumeUp and VolumeDown?
I do not own an LMS so can you please test this updated device adapter (see below) and report back ?

To do this:
from your domoticz dir

Code: Select all

cp  dzVents\runtime\device-adapters\logitech_media_server_device.lua  dzVents\runtime\device-adapters\logitech_media_server_device.bak
and after that replace dzVents\runtime\device-adapters\logitech_media_server_device.lua with this updated version

test the commands

Code: Select all

domoticz.devices(<name>).volumeUp()
domoticz.devices(<name>).volumeDown()
Updated adapter code

Code: Select all

local TimedCommand = require('TimedCommand')

return {
	baseType = 'device',
	name = 'Logitech Media Server device',

	matches = function (device, adapterManager)
		local res = (device.hardwareType == 'Logitech Media Server')

		if (not res) then
			adapterManager.addDummyMethod(device, 'switchOff')
			adapterManager.addDummyMethod(device, 'stop')
			adapterManager.addDummyMethod(device, 'play')
			adapterManager.addDummyMethod(device, 'pause')
			adapterManager.addDummyMethod(device, 'setVolume')
			adapterManager.addDummyMethod(device, 'startPlaylist')
            adapterManager.addDummyMethod(device, 'playFavorites')
            adapterManager.addDummyMethod(device, 'volumeUp')
            adapterManager.addDummyMethod(device, 'volumeDown')
		end
		return res
	end,

	process = function (device, data, domoticz, utils, adapterManager)

		device.playlistID = data.data.levelVal

		function device.switchOff()
			return TimedCommand(domoticz, device.name, 'Off', 'device', device.state)
		end

		function device.stop()
			return TimedCommand(domoticz, device.name, 'Stop', 'device', device.state)
		end

		function device.play()
			return TimedCommand(domoticz, device.name, 'Play', 'device', device.state)
		end

		function device.pause()
			return TimedCommand(domoticz, device.name, 'Pause', 'device', device.state)
		end

		function device.setVolume(value)
            value = tonumber(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, 'Set Volume ' .. tostring(value), 'device', device.state)
			end
		end

		function device.startPlaylist(name)
			return TimedCommand(domoticz, device.name, 'Play Playlist ' .. tostring(name), 'updatedevice', device.state)
		end

		function device.playFavorites(position)
            position = tonumber(position)

			if (position == nil) then
				position = 0
			end

			return TimedCommand(domoticz, device.name, 'Play Favorites ' .. tostring(position), 'updatedevice', device.state)
		end

        function device.volumeDown()
            local url = domoticz.settings['Domoticz url'] ..  "/json.htm?type=command&param=lmsmediacommand&action=VolumeDown" ..
                       '&idx=' .. device.id
            return domoticz.openURL(url)
        end
        
        function device.volumeUp()
            local url = domoticz.settings['Domoticz url'] ..  "/json.htm?type=command&param=lmsmediacommand&action=VolumeUp" ..
                       '&idx=' .. device.id
            return domoticz.openURL(url)
        end
        
	end

}

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Wednesday 27 March 2019 23:35
by GieBek
Hello.
Sorry for my English
VolumeUp and VolumeDown works great.

Please help, I have a problem with running LMS on raspberry pi zero with logitech squeezebox from max2play.
Sometimes it starts up and sometimes not, I do not know what it depends on.
I would like a script that will give me a radio after activating the PIR sensor, the hour defines the volume.

I tried it like the code below but sometimes it works and sometimes it does not. How to add volume: SetVolume will not turn on the radio, I do not understand why.
I know the script is from something else but I tried. :oops:

What is the better code is very please.

Code: Select all

return {
	on = {
		devices = {'PIR Kuchnia - Sensor'}, -- Change out PIR
	},
   
   execute = function(dz, PIR)
        local Radio = dz.devices('Kuchnia LMS') -- Change out light
   
        local dimTimeTable  = { --  [   'timeSlot'   ]  = dimValue
                                    ['at 00:01-09:00']  = 5,
                                    ['at 09:01-12:00']  = 30,
                                    ['at 12:01-22:00']  = 25,
                                    ['at 22:01-24:00']  = 10,
                              }
                              
        if PIR.state ~= 'On' then 
            --Radio.switchOff().afterMin(1)
            Radio.stop().afterMin(1)
           -- dz.log(Radio.name .. ' switched Off')
        else
            for timeSlot, dimValue in pairs (dimTimeTable) do
               if dz.time.matchesRule(timeSlot) then
                    --if Radio.state ~= 'Off' or Radio.state ~= 'stop' then 
            Radio.SetVolume(20)     
            Radio.Play()
                    --dz.log(Radio.name .. ' switched On (Volumelevel: ' .. dimValue .. ')')
                    return false
                    end
               end      
            end
        end     
    end
}

Earlier I had such a code, but it was the same problem as delete setVolume and the radio started up.

Code: Select all

return {
	on = {
		devices = {
			'PIR Kuchnia - Sensor'
		}
	},
	execute = function(domoticz, device)
        if device.state == 'On' and domoticz.devices('Kuchnia LMS').state == 'Off' and domoticz.time.hour >= 9 and domoticz.time.hour <= 12  then
	        domoticz.devices('Kuchnia LMS').switchOn()
	        domoticz.devices('Kuchnia LMS').setVolume(30)
	        domoticz.devices('Kuchnia LMS').play()
	        
        elseif 
            device.state == 'On' and domoticz.devices('Kuchnia LMS').state == 'Off' and domoticz.time.hour >= 13 and domoticz.time.hour <= 15  then
	            domoticz.devices('Kuchnia LMS').switchOn()
	            domoticz.devices('Kuchnia LMS').setVolume(20)
	            domoticz.devices('Kuchnia LMS').play()
	        
        elseif 
            device.state == 'On' and domoticz.devices('Kuchnia LMS').state == 'Off' and domoticz.time.hour >= 16 and domoticz.time.hour <= 22  then
	            domoticz.devices('Kuchnia LMS').switchOn()
	            domoticz.devices('Kuchnia LMS').setVolume(30)
	            domoticz.devices('Kuchnia LMS').play()
	        
        elseif 
            device.state == 'On' and domoticz.devices('Kuchnia LMS').state == 'Off' and domoticz.time.hour >= 23 and domoticz.time.hour <= 8   then
	            domoticz.devices('Kuchnia LMS').switchOn()
	            domoticz.devices('Kuchnia LMS').setVolume(15)
	            domoticz.devices('Kuchnia LMS').play()
	        
            else
	            domoticz.devices('Kuchnia LMS').switchOff().afterSec(300)
            end
    end
}

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Thursday 28 March 2019 0:13
by waaren
GieBek wrote: Wednesday 27 March 2019 23:35 I have a problem with running LMS on raspberry pi zero with logitech squeezebox from max2play.
Sometimes it starts up and sometimes not, I do not know what it depends on.
I would like a script that will give me a radio after activating the PIR sensor, the hour defines the volume.
Not sure I completely understand but can you try this and report your findings ?

Code: Select all

return {
	on = {
		devices = {'PIR Kuchnia - Sensor'}, -- Change out PIR
	},
   
   execute = function(dz, PIR)
        local Radio = dz.devices('Kuchnia LMS') -- Change out light
        dz.log(Radio.name .. ' state: ' .. Radio.state .. '; level: ' .. Radio.level )
                   
        local dimTimeTable  = { --  [   'timeSlot'   ]  = volume
                                    ['at 00:00-09:00']  = 5,
                                    ['at 09:01-12:00']  = 30,
                                    ['at 12:01-22:00']  = 25,
                                    ['at 22:01-23:59']  = 10,
                              }
                              
        if PIR.state ~= 'On' then 
            --Radio.switchOff().afterMin(1)
            Radio.stop().afterMin(1)
           -- dz.log(Radio.name .. ' switched Off')
        else
            for timeSlot, volume in pairs (dimTimeTable) do
               if dz.time.matchesRule(timeSlot) then
                    if Radio.state ~= 'Off' and Radio.state ~= 'stop' then 
                        Radio.SetVolume(volume)     
                        Radio.Play()
                        dz.log(Radio.name .. ' switched On (Volumelevel: ' .. volume .. ')' )
                        return false
                    end
                end
            end
        end
    end
}

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Thursday 28 March 2019 2:54
by GieBek
Thanks for answering, I know my English is very weak. :cry:

If:

Code: Select all

dz.log(Radio.name .. ' state: ' .. Radio.state .. '; level: ' .. Radio.level )
there is an error
2019-03-28 01:32:36.833 Status: dzVents: Error (2.4.15): ...ipts/dzVents/generated_scripts/Radio test v5 DzVents.lua:8: attempt to concatenate field 'level' (a nil value)
But it does not matter.

Code: Select all

return {
	on = {
		devices = {'PIR Kuchnia - Sensor'}, -- Change out PIR
	},
   
   execute = function(dz, PIR)
        local Radio = dz.devices('Kuchnia LMS') -- Change out light
        --dz.log(Radio.name .. ' state: ' .. Radio.state .. '; level: ' .. Radio.level )
                   
        local dimTimeTable  = { --  [   'timeSlot'   ]  = volume
                                    ['at 00:00-09:00']  = 9,
                                    ['at 09:01-12:00']  = 30,
                                    ['at 12:01-22:00']  = 25,
                                    ['at 22:01-23:59']  = 10,
                              }
                              
        if PIR.state ~= 'On' then 
            --Radio.switchOff().afterMin(1)
            Radio.stop().afterMin(1)
           -- dz.log(Radio.name .. ' switched Off')
        else
            for timeSlot, volume in pairs (dimTimeTable) do
               if dz.time.matchesRule(timeSlot) then
               		Radio.setVolume(volume)
                        Radio.play()
                        dz.log(Radio.name .. ' switched On (Volumelevel: ' .. volume .. ')' )
                        return false
                end
            end
        end
    end
}
When setVolume(volume) is over Radio.play() the music starts to play the volume does not change.
When Radio.play() is over setVolume(volume) the volume changes, music does not play. :shock:
I thought maybe there must be a delay. AND YES

Code: Select all

if dz.time.matchesRule(timeSlot) then
                        Radio.setVolume(volume)
                        Radio.play().afterSec(5)
                        dz.log(Radio.name .. ' switched On (Volumelevel: ' .. volume .. ')' )
                        return false
The code above works properly. :) One second also works.
I will test it a few days and I will answer if it works 100%

Thank you very much for your help. Greetings.

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Tuesday 07 May 2019 10:20
by stephanvdplas
test the commands

Code: Select all

domoticz.devices(<name>).volumeUp()
domoticz.devices(<name>).volumeDown()
Hello Waaren,

This works perfectly. Thank you for implementing this. Only 1 thing: It does change the volume (up or down) with step 2. It would be great if the step could be set by parameter of the function (e.g. domoticz.devices('kitchen').volumeDown(10) would lower the volume with 10)

Regards,
Stephan

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Tuesday 07 May 2019 13:43
by waaren
stephanvdplas wrote: Tuesday 07 May 2019 10:20 It would be great if the step could be set by parameter of the function (e.g. domoticz.devices('kitchen').volumeDown(10) would lower the volume with 10)
I can try but don't have an LMS so if you can you send me the result of a

Code: Select all

domoticz.devices('kitchen').dump()  
I might have enough information to work with.

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Tuesday 04 June 2019 12:46
by GieBek
Hello, although there is movement on the watch, the LMS switches off after 3 minutes.
What can be changed for the Radio to play when there is movement in the room.

Code: Select all

return {
	on = {
		devices = {'Kuchnia - Sensor'}, -- Change out PIR
	},
   
   execute = function(dz, PIR)
        local Radio = dz.devices('Kuchnia LMS') -- Change out light
        --dz.log(Radio.name .. ' state: ' .. Radio.state .. '; level: ' .. Radio.level )
                   
        local dimTimeTable  = { --  [   'timeSlot'   ]  = volume
                                --  ['at 00:00-08:00']  = 15,
                                    ['at 08:01-09:59']  = 18,
                                    ['at 10:00-21:00']  = 24,
                                    ['at 21:01-23:59']  = 13,
                              }
                              
        if PIR.state ~= 'On' then
            Radio.switchOff().afterMin(3)
        else
            for timeSlot, volume in pairs (dimTimeTable) do
               if dz.time.matchesRule(timeSlot) and Radio.state == 'Off' then
                        Radio.setVolume(volume-12)
                        Radio.play().afterSec(1)
                        Radio.setVolume(volume-10).afterSec(2)
                        Radio.setVolume(volume-8).afterSec(4)
                        Radio.setVolume(volume-6).afterSec(6)
                        Radio.setVolume(volume-4).afterSec(8)
                        Radio.setVolume(volume-2).afterSec(10)
                        Radio.setVolume(volume-1).afterSec(11)
                        Radio.setVolume(volume).afterSec(12)
                        --dz.log(Radio.name .. ' switched On (Volumelevel: ' .. volume .. ')' )
                        return false
                end
            end
        end
    end
}

Re: Logitech Media Server (LMS) dzVents adapter

Posted: Tuesday 04 June 2019 13:00
by waaren
GieBek wrote: Tuesday 04 June 2019 12:46 Hello, although there is movement on the watch, the LMS switches off after 3 minutes.
What can be changed for the Radio to play when there is movement in the room.
Try with inserting

Code: Select all

Radio.cancelQueuedCommands() 
at line 17