Page 1 of 1

Read Plex status from dummy device

Posted: Thursday 30 April 2020 16:17
by DomoRies
Hi all,
i'm using this great script for reading my Plex status: https://www.domoticz.com/forum/viewtopi ... 72&t=31629

Now i would like to have my lighting respond to it so i have a separate script to read the Plex status from the dummy (Switch type: media player). Unfortunately I can't get it to respond. Does anyone have an idea what I'm doing wrong?

This is the script:

Code: Select all

return {
	on = {
	    devices    = {642} -- dz_plex_player IDX number plex media player device
    },

		logging = {	level = domoticz.LOG_DEBUG,
					marker = 'plexlivingroom',
    },
	
	execute = function(domoticz, plexmedia)

	local playingtest = domoticz.devices(301) -- Dummy test switch playing
	local pausedtest = domoticz.devices(303) -- Dummy test switch paused

	-- when Plex is playing switch on device
	if (plexmedia.state == 7) then
	--if (plexmedia.state == 'playing') then
	--if (plexmedia.nValue == 7) then
		playingtest.switchOn()
	
	-- when Plex paused switch on device	
	elseif (plexmedia.state == 2) then
	--elseif (plexmedia.state == 'paused') then
	--elseif (plexmedia.nValue == 2) then
		pausedtest.switchOn()	
	end
end
}

Re: Read Plex status from dummy device

Posted: Thursday 30 April 2020 16:44
by waaren
DomoRies wrote: Thursday 30 April 2020 16:17 Now i would like to have my lighting respond to it so i have a separate script to read the Plex status from the dummy (Switch type: media player).

can you try this? It does show you the actual state and nValue and check for the states as string

Code: Select all

return {
    on = {
        devices    = {642} -- dz_plex_player IDX number plex media player device
    },

        logging = {    level = domoticz.LOG_DEBUG,
                    marker = 'plexlivingroom',
    },
    
    execute = function(domoticz, plexmedia)

        local playingtest = domoticz.devices(301) -- Dummy test switch playing
        local pausedtest = domoticz.devices(303) -- Dummy test switch paused

        domoticz.log('plexmedia state: ' .. (plexmedia.state or ' no State?'), domoticz.LOG_DEBUG)
        domoticz.log('plexmedia nvalue: ' .. plexmedia.nValue, domoticz.LOG_DEBUG)
        
        -- when Plex is playing switch on device
        if (plexmedia.state == '7' ) then
        --if (plexmedia.state == 'playing') then
        --if (plexmedia.nValue == 7) then
            playingtest.switchOn()
        
        -- when Plex paused switch on device    
        elseif (plexmedia.state == '2' ) then
        --elseif (plexmedia.state == 'paused') then
        --elseif (plexmedia.nValue == 2) then
            pausedtest.switchOn()    
        end
    end
}

Re: Read Plex status from dummy device

Posted: Thursday 30 April 2020 16:59
by DomoRies
waaren wrote: Thursday 30 April 2020 16:44
DomoRies wrote: Thursday 30 April 2020 16:17 Now i would like to have my lighting respond to it so i have a separate script to read the Plex status from the dummy (Switch type: media player).

can you try this? It does show you the actual state and nValue and check for the states as string

Code: Select all

return {
    on = {
        devices    = {642} -- dz_plex_player IDX number plex media player device
    },

        logging = {    level = domoticz.LOG_DEBUG,
                    marker = 'plexlivingroom',
    },
    
    execute = function(domoticz, plexmedia)

        local playingtest = domoticz.devices(301) -- Dummy test switch playing
        local pausedtest = domoticz.devices(303) -- Dummy test switch paused

        domoticz.log('plexmedia state: ' .. (plexmedia.state or ' no State?'), domoticz.LOG_DEBUG)
        domoticz.log('plexmedia nvalue: ' .. plexmedia.nValue, domoticz.LOG_DEBUG)
        
        -- when Plex is playing switch on device
        if (plexmedia.state == '7' ) then
        --if (plexmedia.state == 'playing') then
        --if (plexmedia.nValue == 7) then
            playingtest.switchOn()
        
        -- when Plex paused switch on device    
        elseif (plexmedia.state == '2' ) then
        --elseif (plexmedia.state == 'paused') then
        --elseif (plexmedia.nValue == 2) then
            pausedtest.switchOn()    
        end
    end
}
Thanks for your reaction.
Strange, I played something in plex and paused but nothing happens in the log. The device is updated by the 'Plex status script'.

Re: Read Plex status from dummy device  [Solved]

Posted: Thursday 30 April 2020 17:07
by waaren
DomoRies wrote: Thursday 30 April 2020 16:59 Strange, I played something in plex and paused but nothing happens in the log. The device is updated by the 'Plex status script'.
The posted Plex status script uses the option silent() if you have not removed that it will not trigger any subsequent scripts.

Re: Read Plex status from dummy device

Posted: Thursday 30 April 2020 17:16
by DomoRies
waaren wrote: Thursday 30 April 2020 17:07
DomoRies wrote: Thursday 30 April 2020 16:59 Strange, I played something in plex and paused but nothing happens in the log. The device is updated by the 'Plex status script'.
The posted Plex status script uses the option silent() if you have not removed that it will not trigger any subsequent scripts.
Wow thank you very much! Never thought about that. It works now :D :D