OedzesG wrote: ↑Sunday 08 March 2020 22:36
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
Once tautulli is instaled you can go to settings and navigate to Notification Agents and create a "webhook'
* webhook url :
Code: Select all
http://<domoticzURL + port>/json.htm?type=command¶m=customevent&event=plex_woonkamer
( you can change: woonkamer to something else, but then in the script you need to change the custom event in exactly the same name)
(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
}