PLEX status (dzVents) [SOLVED]
Moderator: leecollings
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
PLEX status (dzVents) [SOLVED]
Hallo everyone!
today i finisched my PLEX Status script.
it gives my the PLEX mediaplayer status so i can for example controle the lights when a movie is started or paused..
if someone is interested, please let me know so i can make an how-2 and share the script.
today i finisched my PLEX Status script.
it gives my the PLEX mediaplayer status so i can for example controle the lights when a movie is started or paused..
if someone is interested, please let me know so i can make an how-2 and share the script.
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
Please share.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
Please share.
oke EdwinK... here we go..
The script uses the Tautulli api.. so first you need to install Tautulli..
Code: Select all
https://github.com/Tautulli/Tautulli-Wiki/wiki/Installation
* webhook url :
Code: Select all
http://<domoticzURL + port>/json.htm?type=command¶m=customevent&event=plex_woonkamer
(becouse we use an customEvent, you need to be on dzVents: 3:0:0!!)
* Webhook Method: post
* description: what ever you want
on the page: Triggers select:
* Playback Start
* Playback Stop
* Playback Pause
* Playback Resume
On the page: Conditions:
* Parameter: Player
* Operator: is
* Value: (Here you have to search in Plex for youre plex player name (in my case: SHIELD Android TV)
Then save the webhook.
We also need the API Key from tautulli, you can find it: settings/Web Interface, scrol down en note the API. Also make sure API is enabled.
Now were done in Tautulli.
In Domoticz you have to create a dummy device... first switch and then change it to: media player in Domoticz UI.
The script whit some final instructions.
Code: Select all
local scriptVersion = ' release: v1.3: 20200306 '
local scriptVar = ' plex woonkamer ' .. scriptVersion
--<[================================================================================================]>--
--<[ dzVents: Plex status 2 Domoticz ]>--
--<[================================================================================================]>-
local tautulli_ip = 'xxx' -- tautulli ip:port
local tautulli_api = 'xx' -- tautulli api key
local plex_player = 'SHIELD Android TV' -- the plex player you want the status off
local dz_plex_player = 26 -- IDX number plex media player device
return
{
on = { customEvents = { 'plex_woonkamer',}, -- if you change the webhook URL make sure this match
timer = { 'every minute' -- this only runs when a movie is playing on selected player
},
httpResponses = { scriptVar .. '*', },
},
logging = { level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when testen and ok.
marker = scriptVar,
},
data = { plex = { initial = {}, },
},
execute = function(dz, item, triggerInfo)
local jsonPlexInfo = {}
local callback = scriptVar .. 'getPlexInfo'
-- make sure timer only trigger script when pms is active
if item.isCustomEvent then
dz.data.plex.active = 'true'
end
if dz.data.plex.active == 'true' then
if item.isCustomEvent or item.isTimerer then
end
-- get plex information trough tautulli api
local function getPlexInfo( target, json, callback)
local url = 'http://' .. target .. '/' .. json
dz.openURL
({
url = url,
method = 'GET',
callback = callback,
})
end
if item.isCustomEvent or item.isTimer then
getPlexInfo( tautulli_ip, '/api/v2?apikey=' .. tautulli_api .. '&cmd=get_activity', callback )
return
end
if item.isHTTPResponse then
jsonPlexInfo = dz.utils.fromJSON(item.data)
if not(jsonPlexInfo) then return end
else
dz.log('Unexpected result from API ',dz.LOG_ERROR )
dz.utils.dumpTable(item)
end
dz.data.initialize('plex')
-- find match in player name (api showing more players when more streams are active)
for _, record in ipairs(jsonPlexInfo.response.data.sessions) do
if record.player:match(plex_player) then
dz.data.plex.active = ('true')
dz.data.plex.state = (record.state)
dz.data.plex.title = (record.full_title)
dz.data.plex.progress = (record.progress_percent)
end
end
-- Change json output for updating device
if dz.data.plex.state == 'playing' then player_state = 7
elseif dz.data.plex.state == 'buffering' then player_state = 7
elseif dz.data.plex.state == 'paused' then player_state = 2
end
-- updating device
if dz.data.plex.active == 'true' then
dz.devices(dz_plex_player).update(player_state, dz.data.plex.title .. ' : ' .. dz.data.plex.progress .. ' %').silent()
else
dz.devices(dz_plex_player).update(0, 'no media playing').silent()
end
end
end
}
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
Trying this tomorrow 

Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
Trying this tomorrow
oké..

please let me know if evertything worked out!
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
So far it's working:
- Spoiler: show
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
can you share the script?but nothing changes on the switch.
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
The same script you posted above, but adapted
- Spoiler: show
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
you sure youre plex_player is: Plex Server?The same script you posted above, but adapted
Normaly its something like: Chrome, Chromecast, SHIELD Android TV, or something..
if youre not sure, start streaming with the device you want to know the status of, then go to plex en check: Activity.
In this example it: "Chrome" you need!
Changed the script a litlle, this should be working!
Code: Select all
local scriptVersion = ' v1.3: 20200306 '
local scriptVar = ' plex woonkamer ' .. scriptVersion
--<[================================================================================================]>--
--<[ dzVents: Plex status 2 Domoticz ]>--
--<[================================================================================================]>-
local tautulli_ip = '192.168.0.11:8181'
local tautulli_api = '****'
local plex_player = 'Plex Server'
local dz_plex_player = 508
return
{
on = { customEvents = { 'plex_woonkamer',},
timer = { 'every minute'
},
httpResponses = { scriptVar .. '*', },
},
logging = { level = domoticz.LOG_ERROR,
marker = scriptVar,
},
data = { plex = { initial = {}, },
},
execute = function(dz, item, triggerInfo)
local jsonPlexInfo = {}
local callback = scriptVar .. 'getPlexInfo'
if item.isCustomEvent then
dz.data.plex.active = 'true'
end
if dz.data.plex.active == 'true' then
if item.isCustomEvent or item.isTimerer then
end
local function getPlexInfo( target, json, callback)
local url = 'http://' .. target .. '/' .. json
dz.openURL
({
url = url,
method = 'GET',
callback = callback,
})
end
if item.isCustomEvent or item.isTimer then
getPlexInfo( tautulli_ip, '/api/v2?apikey=' .. tautulli_api .. '&cmd=get_activity', callback )
return
end
if item.isHTTPResponse then
jsonPlexInfo = dz.utils.fromJSON(item.data)
if not(jsonPlexInfo) then return end
else
dz.log('Unexpected result from API ',dz.LOG_ERROR )
dz.utils.dumpTable(item)
end
dz.data.initialize('plex')
for _, record in ipairs(jsonPlexInfo.response.data.sessions) do
if record.player:match(plex_player) then
dz.data.plex.active = ('true')
dz.data.plex.state = (record.state)
dz.data.plex.title = (record.full_title)
dz.data.plex.progress = (record.progress_percent)
end
end
if dz.data.plex.state == 'playing' then dz.data.plex.state = 7
elseif dz.data.plex.state == 'buffering' then dz.data.plex.state = 7
elseif dz.data.plex.state == 'paused' then dz.data.plex.state = 2
end
if dz.data.plex.active == 'true' then
dz.devices(dz_plex_player).update(dz.data.plex.state, dz.data.plex.title .. ' : ' .. dz.data.plex.progress .. ' %').silent()
else
dz.devices(dz_plex_player).update(0, 'no media playing').silent()
end
end
end
}
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
Got the following:
So I assume it should be TV UE50J6200?
So I assume it should be TV UE50J6200?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
exactlySo I assume it should be TV UE50J6200?
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
also make sure youre webhook settings match...So I assume it should be TV UE50J6200
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
That was the one part I forgot to change 

Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: PLEX status (dzVents)
And now i've got it working 
Thanks. Maybe you could put this in the WIKI?

Thanks. Maybe you could put this in the WIKI?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
i hope you enjoy it!And now i've got it working

im not an scripting expert... just create the script (whit lots of help from @waaren) becouse i could not find anything in dzVents for plex..
i think there can be some aprovements and have some ideas to add..
(to be honest, i have no clue how to place it on the wiki

-
- Posts: 6
- Joined: Saturday 19 April 2014 14:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
What a great script. I had to update my Raspberry PI and Domoticz for it (which turned to be much easier than expected - previous versions I had to compile myself because of desired OpenZwave support), and it worked straight out of the box.
Do you all have any examples of attached Lighting-scripts? My preference was to dim a group of Hue lights to 0 (matching a cinema experience) but I'll settle of 'off' for 'playing' and 'resume', and for 'on' at all other events...
Do you all have any examples of attached Lighting-scripts? My preference was to dim a group of Hue lights to 0 (matching a cinema experience) but I'll settle of 'off' for 'playing' and 'resume', and for 'on' at all other events...
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
thnx! @finalcut62What a great script
Code: Select all
local mediaPlayerStates =
{
Off = 0,
On = 1,
Paused = 2,
Stopped = 3,
Video = 4,
Audio = 5,
Photo = 6,
Playing = 7,
Disconnected = 8,
Sleeping = 9,
Unknown = 10,
}
-
- Posts: 11
- Joined: Saturday 20 January 2018 12:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
Script looks great, trying it tomorrow. Is it correct that you need the plex pass to let this work? That's something to keep in mind when trying this 

-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
No script is not using PLEX but Tautulli.. and as far i know, you can run Tautulli withoud PLEX pass.Is it correct that you need the plex pass to let this work?
Good luck!
Please let me know if everything went well...
-
- Posts: 11
- Joined: Saturday 20 January 2018 12:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: PLEX status (dzVents)
Installed everything and works pretty good! And indeed no plex pass needed.
Who is online
Users browsing this forum: No registered users and 0 guests