Read Plex status from dummy device  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
DomoRies
Posts: 14
Joined: Friday 25 November 2016 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Read Plex status from dummy device

Post 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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Plex status from dummy device

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoRies
Posts: 14
Joined: Friday 25 November 2016 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Plex status from dummy device

Post 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'.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Plex status from dummy device  [Solved]

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoRies
Posts: 14
Joined: Friday 25 November 2016 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Read Plex status from dummy device

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest