Turn switch on when pausing kodi?
Moderator: leecollings
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Turn switch on when pausing kodi?
Hi!
Im a new user of Domoticz and i think that its a great automation tool.
My question is, is it possible to turn on and of switches when i play and pause kodi?
If so, how should i set it up!
I use kodi in another device, its a minix media player that runs kodi under Android.
Thanks in advance.
Im a new user of Domoticz and i think that its a great automation tool.
My question is, is it possible to turn on and of switches when i play and pause kodi?
If so, how should i set it up!
I use kodi in another device, its a minix media player that runs kodi under Android.
Thanks in advance.
-
- Posts: 65
- Joined: Tuesday 24 February 2015 15:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
Here's a script I use to carry on watching a program (tv show of film) in bed
When I run the "bed time" scene it triggers this script (and turns lots of lights off).
This script checks to see if the lounge kodi is paused and therefore assumes i want to carry on watching it in bed.
If not paused then it doesn't run - i'm going to bed to sleep lol
commandArray = {};
FullResult=""
function send(msg)
runcommand = "echo "..string.char(34).."POST "..msg.. " HTTP/1.1"..string.char(13)..string.char(10)..string.char(13)..string.char(10)..string.char(34).."| telnet "..IP.." "..Port.." "
print (runcommand)
os.execute(runcommand)
end
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
FullResult=s
return s
end
function sendToKodi(IP, msg)
msg2="jsonrpc?request="..urlencode(msg)
runcommand = "curl http://"..(IP)..":"..(8080).."/"..(msg2)..""
print (runcommand)
os.capture(runcommand,false)
end
function sleep(n)
os.execute("sleep " .. tonumber(n))
end
if devicechanged['LoungeToBedroomKodi'] and devicechanged['LoungeToBedroomKodi']=='On' then
print("Kodi Lounge To Bedroom Script Started..")
PausedType=""
PausedID=0
--if lounge xbmc paused:
if otherdevices['Lounge (Kodi)'] == 'Paused' then
--query currently playing
sendToKodi('192.168.2.105','{"jsonrpc":"2.0","method":"Player.GetItem","params":{"properties":[],"playerid":1},"id":"VideoGetItem"}')
print(" Full Result: "..FullResult)
--store id and type playing
if string.len(FullResult) > 0 then
PausedType=string.sub(FullResult, string.find(FullResult,"type")+7, -5)
idstart=string.find(FullResult,"item")+12
idend=string.find(FullResult,",",idstart)-1
PausedID=string.sub(FullResult,idstart,idend)
print(PausedType.." "..PausedID)
end
if PausedType == 'movie' or PausedType == 'episode' then
--stop lounge kodi so it updates resume point
sendToKodi('192.168.2.105','{"jsonrpc":"2.0","id":1,"method":"Player.Stop","params":{"playerid":1}}')
--turn bedroom tv On
commandArray['Bedroom TV']='Set Level 10'
--wait a small delay to allow resume point to be updated in kodi sql database
sleep(2)
--start movie/tv show playing with resume
if PausedType == 'movie' then
sendToKodi('192.168.2.140','{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"movieid":'..PausedID..'},"options":{"resume":true}}}')
end
if PausedType == 'episode' then
sendToKodi('192.168.2.140','{"jsonrpc": "2.0","id": "1","method":"Player.Open","params":{"item":{"episodeid":'..PausedID..'},"options":{"resume":true}}}')
end
--wait a small delay to allow kodi to get ready to pause
sleep(1)
--pause it, ready to watch!
sendToKodi('192.168.2.140','{"jsonrpc":"2.0","id":1,"method":"Player.PlayPause","params":{"playerid":1}}')
end
end
end
return commandArray
When I run the "bed time" scene it triggers this script (and turns lots of lights off).
This script checks to see if the lounge kodi is paused and therefore assumes i want to carry on watching it in bed.
If not paused then it doesn't run - i'm going to bed to sleep lol
commandArray = {};
FullResult=""
function send(msg)
runcommand = "echo "..string.char(34).."POST "..msg.. " HTTP/1.1"..string.char(13)..string.char(10)..string.char(13)..string.char(10)..string.char(34).."| telnet "..IP.." "..Port.." "
print (runcommand)
os.execute(runcommand)
end
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
FullResult=s
return s
end
function sendToKodi(IP, msg)
msg2="jsonrpc?request="..urlencode(msg)
runcommand = "curl http://"..(IP)..":"..(8080).."/"..(msg2)..""
print (runcommand)
os.capture(runcommand,false)
end
function sleep(n)
os.execute("sleep " .. tonumber(n))
end
if devicechanged['LoungeToBedroomKodi'] and devicechanged['LoungeToBedroomKodi']=='On' then
print("Kodi Lounge To Bedroom Script Started..")
PausedType=""
PausedID=0
--if lounge xbmc paused:
if otherdevices['Lounge (Kodi)'] == 'Paused' then
--query currently playing
sendToKodi('192.168.2.105','{"jsonrpc":"2.0","method":"Player.GetItem","params":{"properties":[],"playerid":1},"id":"VideoGetItem"}')
print(" Full Result: "..FullResult)
--store id and type playing
if string.len(FullResult) > 0 then
PausedType=string.sub(FullResult, string.find(FullResult,"type")+7, -5)
idstart=string.find(FullResult,"item")+12
idend=string.find(FullResult,",",idstart)-1
PausedID=string.sub(FullResult,idstart,idend)
print(PausedType.." "..PausedID)
end
if PausedType == 'movie' or PausedType == 'episode' then
--stop lounge kodi so it updates resume point
sendToKodi('192.168.2.105','{"jsonrpc":"2.0","id":1,"method":"Player.Stop","params":{"playerid":1}}')
--turn bedroom tv On
commandArray['Bedroom TV']='Set Level 10'
--wait a small delay to allow resume point to be updated in kodi sql database
sleep(2)
--start movie/tv show playing with resume
if PausedType == 'movie' then
sendToKodi('192.168.2.140','{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"movieid":'..PausedID..'},"options":{"resume":true}}}')
end
if PausedType == 'episode' then
sendToKodi('192.168.2.140','{"jsonrpc": "2.0","id": "1","method":"Player.Open","params":{"item":{"episodeid":'..PausedID..'},"options":{"resume":true}}}')
end
--wait a small delay to allow kodi to get ready to pause
sleep(1)
--pause it, ready to watch!
sendToKodi('192.168.2.140','{"jsonrpc":"2.0","id":1,"method":"Player.PlayPause","params":{"playerid":1}}')
end
end
end
return commandArray
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Turn switch on when pausing kodi?
Please use a code block for code...
I don't want Domoticz to constantly poll my Kodi player to see if it's playing or not.
I put Kodi in payse/play with a minimote.
When I pause it, light of the kithcen ('wasbak') turns on.
When I unpause it and the light is still on I update a device that triggert switch off of multiple lighst (hall, garage etc).
I don't want Domoticz to constantly poll my Kodi player to see if it's playing or not.
I put Kodi in payse/play with a minimote.
When I pause it, light of the kithcen ('wasbak') turns on.
When I unpause it and the light is still on I update a device that triggert switch off of multiple lighst (hall, garage etc).
Code: Select all
<?php //part of pass2php
function miniliving2s()
{
global $s,$i;
$ctx=stream_context_create(array('http'=>array('timeout'=>3)));
file_get_contents('http://192.168.2.7:1597/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Player.PlayPause","params":{"playerid":1}}',false,$ctx);
if($s['wasbak']=='On') file_get_contents('http://127.0.0.1:8084/json.htm?type=command¶m=udevice&idx=198&nvalue=0&svalue=On');
else file_get_contents('http://127.0.0.1:8084/json.htm?type=command¶m=switchlight&idx=61&switchcmd=On');
}
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
Thank you for your answers!
really nice to see that it would work.
im sorry to say that i dont understand the code that you posted, i started with Domoticz 1 week ago, so im not that good att programming yet,
Should i just copy paste the code/text?
Is it in Lua that i should paste the code/text?
im really sorry for the stupid questions
really nice to see that it would work.
im sorry to say that i dont understand the code that you posted, i started with Domoticz 1 week ago, so im not that good att programming yet,
Should i just copy paste the code/text?
Is it in Lua that i should paste the code/text?
im really sorry for the stupid questions
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
i must ad that im using a logitech harmony one to control my kodi player, so i dont use the remote from Domoticz, can Domoticz somehow see the events made from kodi?
if its possible i guess that the events being made from kodi could control Domoticz to tunr on and off light when playing a movie.
if its possible i guess that the events being made from kodi could control Domoticz to tunr on and off light when playing a movie.
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Turn switch on when pausing kodi?
Have a look at http://www.domoticz.com/wiki/Kodi#Event ... ifications to see if that does what you want.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
thank you for answering.Dnpwwo wrote:Have a look at http://www.domoticz.com/wiki/Kodi#Event ... ifications to see if that does what you want.
i have managed to set up kodi to domoticz, so when i now play a movie i see the move title, and if i play or pause the move, it is all shown in domoticz,
i have set up some simple blocklys for some of the light at home, if a switch is triggered it will automaticly shut down after 60 mins.
but i guess that is my limit, i really dont know how to set the incomming events from kodi to switch of some of the lamps in my house.
i have looked at every block in blockly, but i cant figure out how to set it up.
i have also read that link that you provided above, but it didnt make me wiser.
I would really apericate some futher guidence, maby wich blocky i should use?
thanks in advance.
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Turn switch on when pausing kodi?
I don't use Blockly but you can do it via a Lua script in the same Event page:
Code: Select all
commandArray = {}
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='Lounge Kodi') then
print ("Kodi event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
if (deviceValue == "On") or (deviceValue == "Off") then
if (timeofday['Nighttime'] == true) and (otherdevices['Lounge Dimmer'] == 'Off') then otherdevices['Lounge Dimmer'] == 'Set Level 25' end
elseif (deviceValue == "Paused") then
if (timeofday['Nighttime'] == true) and (otherdevices['Lounge Dimmer'] == 'Off') then otherdevices['Lounge Dimmer'] == 'Set Level 25' end
elseif (deviceValue == "Video") then
if (otherdevices['Lounge Dimmer'] ~= 'Off') then commandArray['Lounge Dimmer'] = "Off" end
if (otherdevices['Front Door Dimmer'] ~= 'Off') then commandArray['Front Door Dimmer'] = "Off AFTER 3" end
if (otherdevices['Hall Dimmer'] ~= 'Off') then commandArray['Hall Dimmer'] = "Off AFTER 5" end
end
end
end
return commandArray
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
Hi!Dnpwwo wrote:I don't use Blockly but you can do it via a Lua script in the same Event page:
Code: Select all
commandArray = {} -- loop through all the changed devices for deviceName,deviceValue in pairs(devicechanged) do if (deviceName=='Lounge Kodi') then print ("Kodi event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'"); if (deviceValue == "On") or (deviceValue == "Off") then if (timeofday['Nighttime'] == true) and (otherdevices['Lounge Dimmer'] == 'Off') then otherdevices['Lounge Dimmer'] == 'Set Level 25' end elseif (deviceValue == "Paused") then if (timeofday['Nighttime'] == true) and (otherdevices['Lounge Dimmer'] == 'Off') then otherdevices['Lounge Dimmer'] == 'Set Level 25' end elseif (deviceValue == "Video") then if (otherdevices['Lounge Dimmer'] ~= 'Off') then commandArray['Lounge Dimmer'] = "Off" end if (otherdevices['Front Door Dimmer'] ~= 'Off') then commandArray['Front Door Dimmer'] = "Off AFTER 3" end if (otherdevices['Hall Dimmer'] ~= 'Off') then commandArray['Hall Dimmer'] = "Off AFTER 5" end end end end return commandArray
so i just copy/paste, and replace the red marked devices with my own ones, and it should probably work?
thanks in advance
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
Hi!
i actually think i got it working, i tried different things in blockly, and i set it up like the picture shows.
This seems to work, when i pauses some of the lights turn on, but it seems like its only the logic blocky, paused that works.
none of the playing and stopped works, i really dont know why.
Does any one else know why none of these logical, like Playing, Stopped or stopp works?
I would like to get the lights to turn of after i stopp the movie.
[img] [/img]
thanks.
i actually think i got it working, i tried different things in blockly, and i set it up like the picture shows.
This seems to work, when i pauses some of the lights turn on, but it seems like its only the logic blocky, paused that works.
none of the playing and stopped works, i really dont know why.
Does any one else know why none of these logical, like Playing, Stopped or stopp works?
I would like to get the lights to turn of after i stopp the movie.
[img] [/img]
thanks.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Turn switch on when pausing kodi?
Try with 'different' than Paused. Like != or /=
- blackdog65
- Posts: 311
- Joined: Tuesday 17 June 2014 18:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Norfolk, UK
- Contact:
Re: Turn switch on when pausing kodi?
I remember there was a plug-in available for Kodi that was originally meant for X10. I used it a year or 2 back when I was using Kodi. The plug-in sent json requests when a specific action was performed i.e. Play set lights off, pause set lights 50% and stop set lights back full... or however you wanted it set. Of course this can be used to switch scenes in blockly with "if dark" etc.
I've just returned to using Kodi, so I'll investigate further and report back.
I've just returned to using Kodi, so I'll investigate further and report back.
CubieTruck Master
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
RasPi slaves
Aeon Labs Z-Stick, multi sensor
Fibaro Dimmers, relays, Universal sensors
EQ3 MAX!
TKB Sockets
RFXCOM
LightwaveRF sockets, switches, relays, doorbell
MySensors
ESPEasy ESP8266-12E
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
thanks for your answers.
i tried everything in the blue pause block from the picture above, but nothing cant trigger the light to turn on when i stop the movie, pause works great for just pause, but nothing for stopping the movie.
any other suggerstions?
i tried everything in the blue pause block from the picture above, but nothing cant trigger the light to turn on when i stop the movie, pause works great for just pause, but nothing for stopping the movie.
any other suggerstions?
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
i didnt really uderstand that "different", how could i ad != and/= ?Egregius wrote:Try with 'different' than Paused. Like != or /=
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Turn switch on when pausing kodi?
In the dropdown where you select the equal sign there's also 'not equal' indicated by a equal sign with a slash thru it:
Notice: just try to help, I never use blockly...
Notice: just try to help, I never use blockly...
-
- Posts: 564
- Joined: Sunday 11 December 2016 13:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Turn switch on when pausing kodi?
I apreciate your help, i will give this a try later.Egregius wrote:In the dropdown where you select the equal sign there's also 'not equal' indicated by a equal sign with a slash thru it:
Notice: just try to help, I never use blockly...
Thank you.
-
- Posts: 145
- Joined: Tuesday 08 July 2014 15:10
- Target OS: -
- Domoticz version: 4.9700
- Location: UK
- Contact:
Re: Turn switch on when pausing kodi?
I use an addon running in kodi called callbacks, been using it on v16 & now v17 as I didn't even know the above methods existed.
http://kodi.wiki/view/Add-on:Kodi_Callbacks
http://forum.kodi.tv/showthread.php?tid=256170
Works quite well to just call a Json http request from within kodi.
http://kodi.wiki/view/Add-on:Kodi_Callbacks
http://forum.kodi.tv/showthread.php?tid=256170
Works quite well to just call a Json http request from within kodi.
Who is online
Users browsing this forum: No registered users and 1 guest