- Optionally highlights devices that can not be found on the network (red banner in web UI)
- Supports screensaver events (Kodi 17+) and shows Kodi as 'Sleeping' when screensaver is on
Python plugin: Kodi
Moderator: leecollings
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
Latest Update: v2.0.6 - December 12th, 2017 requires recent beta
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: 742
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Python plugin: Kodi
This is a very welcome update, it saves installing the Kodi plugin to let Kodi sent a JSON signa to Domoticz to tell when Kodi is sleeping / not sleeping.
I updated the plugin and indeed, it now has the extra option. I will keep a look on it and eventually kill the Kodi plugin and use the Domoticz plugin as an input to switch off the devices.
I updated the plugin and indeed, it now has the extra option. I will keep a look on it and eventually kill the Kodi plugin and use the Domoticz plugin as an input to switch off the devices.
Re: Python plugin: Kodi
Thanks, finally i can manage the TVs under domoticz. Just a suggest: why not add an option in the hardware settings -> shutdown command that start the screensaver. Should be this json:
Code: Select all
{"jsonrpc":"2.0","method":"GUI.ActivateWindow","id":1,"params":{"window":"screensaver"}}
In this way it's possible to set in kodi -> cec option to shutdown tv when screensaver start, so it's possible to shutdown all by domoticz in Just one tap!
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
@TheCondor,
Not a bad idea so I've added it, I run Pi3's so never shut them down (because you can't turn them back on ) so it may be useful but it might not do what you want.
The Kodi screensaver is a bit weird because in a perfect world you would be able to:
The command you mentioned switches the window to the screen saver but not properly. Have a look at:
It will look okay on the Domoticz end because I have hardcoded the Kodi to show sleeping if you tell it to switch to the screensaver but have no idea what it will mean for CEC.
Version 2.1.6 pushed to the git repository.
Not a bad idea so I've added it, I run Pi3's so never shut them down (because you can't turn them back on ) so it may be useful but it might not do what you want.
The Kodi screensaver is a bit weird because in a perfect world you would be able to:
- Know when the screen saver activates
- Know when the screen save deactivates
- Be able to activate the screen saver
- Query if the screensaver is active
The command you mentioned switches the window to the screen saver but not properly. Have a look at:
- Spoiler: show
It will look okay on the Domoticz end because I have hardcoded the Kodi to show sleeping if you tell it to switch to the screensaver but have no idea what it will mean for CEC.
Version 2.1.6 pushed to the git repository.
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
Re: Python plugin: Kodi
Dnpwwo wrote: ↑Friday 29 December 2017 2:02 @TheCondor,
Not a bad idea so I've added it, I run Pi3's so never shut them down (because you can't turn them back on ) so it may be useful but it might not do what you want.
The Kodi screensaver is a bit weird because in a perfect world you would be able to:with the Kodi V8 API you seem to be able to do the first 2 1/2 of the 4 (mostly).
- Know when the screen saver activates
- Know when the screen save deactivates
- Be able to activate the screen saver
- Query if the screensaver is active
The command you mentioned switches the window to the screen saver but not properly. Have a look at:Normally Activate and Deactivate events are paired (as you would expect) but setting the window Deactivates the screen saver (regardless of whether it is on or not) but there is never an Activate event afterwards. Even more strange is that the log shows another Deactivate later when I hit a key on a remote. This may be a bug on the Kodi end.
- Spoiler: show
It will look okay on the Domoticz end because I have hardcoded the Kodi to show sleeping if you tell it to switch to the screensaver but have no idea what it will mean for CEC.
Version 2.1.6 pushed to the git repository.
you are right, the rpc screensaver command is broken in some way, or works in a different way than the same command works locally.
Much pepole claim that RPC API need to support CEC direct command but these posts are at least one year older so probably will never be implemented.
I've found a workaround, i'll send you in private maybe you can integrate in some way in your script. Thanks and happy new year!
Re: Python plugin: Kodi
Hi, i've found this way and it's working for send the screensaver command to a kodi box.
My box need to be always on, otherwise i cannot wake up from sleep and need to unplug/plug the wire, it's the same as a raspberry, but in the kodi options (libreelec), system, input, cec adapter i can set this options for shutdown tv:
DEVICE TO POWER ON AT START -> TV
DEVICE TO SHUTDOWN AT STOP -> TV
SEND "INACTIVE SOURCE" COMMAND AT STOP
PUT DEVICE IN STANDBY WHEN SCREENSAVER START -> YES
WAKE UP DEVICE WHEN SCREENSAVER DISACTIVE -> YES
WHEN TV IS OFF -> STOP PLAYING
WHEN SOURCE CHANGE -> STOP PLAYING
and with this bash script i can connect trough ssh to the box and send kodi the command to start screensaver:
you need to install sshpass on the domoticz machine, but probably it's possible to send the password using default ssh and a bit of scripting.
With all of this i can use the tv remote and also domoticz to controll all.
My box need to be always on, otherwise i cannot wake up from sleep and need to unplug/plug the wire, it's the same as a raspberry, but in the kodi options (libreelec), system, input, cec adapter i can set this options for shutdown tv:
DEVICE TO POWER ON AT START -> TV
DEVICE TO SHUTDOWN AT STOP -> TV
SEND "INACTIVE SOURCE" COMMAND AT STOP
PUT DEVICE IN STANDBY WHEN SCREENSAVER START -> YES
WAKE UP DEVICE WHEN SCREENSAVER DISACTIVE -> YES
WHEN TV IS OFF -> STOP PLAYING
WHEN SOURCE CHANGE -> STOP PLAYING
and with this bash script i can connect trough ssh to the box and send kodi the command to start screensaver:
Code: Select all
#!/bin/bash
SSHPASS='libreelec' sshpass -e ssh [email protected] "sleep 2; kodi-send --action="Stop" && sleep 2; kodi-send --action="ActivateScreensaver""
With all of this i can use the tv remote and also domoticz to controll all.
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Python plugin: Kodi
Can I use this plugin for two (or more) Kodi devices ?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
@EdwinK,
Just create multiple instances of the hardware plugin, I run three and they don't clash with each other.
Just create multiple instances of the hardware plugin, I run three and they don't clash with each other.
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
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Python plugin: Kodi
Okay. Thanks. Will do.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Re: Python plugin: Kodi
After installing this plugin I'm getting this error in domoticz log whit debug turned on
Code: Select all
2018-01-30 20:10:33.134 (HTPC) Calling message handler 'onHeartbeat'.
2018-01-30 20:10:33.134 (HTPC) Sending 62 bytes of data:.
2018-01-30 20:10:33.134 (HTPC) 7b 22 6a 73 6f 6e 72 70 63 22 3a 22 32 2e 30 22 2c 22 6d 65 {"jsonrpc":"2.0","me
2018-01-30 20:10:33.134 (HTPC) 74 68 6f 64 22 3a 22 50 6c 61 79 65 72 2e 47 65 74 41 63 74 thod":"Player.GetAct
2018-01-30 20:10:33.134 (HTPC) 69 76 65 50 6c 61 79 65 72 73 22 2c 22 69 64 22 3a 31 30 30 ivePlayers","id":100
2018-01-30 20:10:33.134 (HTPC) 31 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 1}
2018-01-30 20:10:33.184 (HTPC) Received 68 bytes of data:.
2018-01-30 20:10:33.184 (HTPC) 7b 22 69 64 22 3a 31 30 30 31 2c 22 6a 73 6f 6e 72 70 63 22 {"id":1001,"jsonrpc"
2018-01-30 20:10:33.184 (HTPC) 3a 22 32 2e 30 22 2c 22 72 65 73 75 6c 74 22 3a 5b 7b 22 70 :"2.0","result":[{"p
2018-01-30 20:10:33.185 (HTPC) 6c 61 79 65 72 69 64 22 3a 31 2c 22 74 79 70 65 22 3a 22 76 layerid":1,"type":"v
2018-01-30 20:10:33.185 (HTPC) 69 64 65 6f 22 7d 5d 7d .. .. .. .. .. .. .. .. .. .. .. .. ideo"}]}
2018-01-30 20:10:33.185 (HTPC) Calling message handler 'onMessage'.
2018-01-30 20:10:33.185 Error: (HTPC) 'onMessage' failed 'TypeError':'onMessage() takes 2 positional arguments but 4 were given'.
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
@Kivi,
The version of Domoticz you are running is too old.
The version of Domoticz you are running is too old.
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
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
@TheCondor,
New version of Kodi plugin (2.2.1) pushed to github that activates the screensaver using the proper "ActivateScreensaver" function via the UDP interface.
Saves you using SSH and a bash script.
New version of Kodi plugin (2.2.1) pushed to github that activates the screensaver using the proper "ActivateScreensaver" function via the UDP interface.
Saves you using SSH and a bash script.
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: 742
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Python plugin: Kodi
Thanks for the extension of the plugin!
May I throw in my old request again: the option to give Kodi a 'rewind' command?
My stereo is turned on as soon as Domoticz detects that Kodi plays audio/video. However, before the stereo outputs sound, the track already is at 10 seconds. I would prefer to 'pause', turn on the receiver, wait x seconds, 'REWIND' and 'play' again. This would greatly improve the user experience and the WAF
'pause' and 'play' are already implemented, therefore the 'rewind' command would be very welcome to improve the script!
May I throw in my old request again: the option to give Kodi a 'rewind' command?
My stereo is turned on as soon as Domoticz detects that Kodi plays audio/video. However, before the stereo outputs sound, the track already is at 10 seconds. I would prefer to 'pause', turn on the receiver, wait x seconds, 'REWIND' and 'play' again. This would greatly improve the user experience and the WAF
'pause' and 'play' are already implemented, therefore the 'rewind' command would be very welcome to improve the script!
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
Bug Fix version 2.2.3 added that resolved issue with source selector and added 'Weather' as an option.
@jake,
From a Domoticz script I think you could already do something like:
@jake,
From a Domoticz script I think you could already do something like:
- Pause
- Turn on reciever
- Send 'Set Level 0 AFTER 10' to the '<myKodi'sName> - Playing' device (this seeks to start of the file)
- Play
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
Re: Python plugin: Kodi
Thanks awesome integration. This kodi plugin should now replace the default IMHO
-
- Posts: 742
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Python plugin: Kodi
Ah, good idea.Dnpwwo wrote:Bug Fix version 2.2.3 added that resolved issue with source selector and added 'Weather' as an option.
@jake,
From a Domoticz script I think you could already do something like:
- Pause
- Turn on reciever
- Send 'Set Level 0 AFTER 10' to the '<myKodi'sName> - Playing' device (this seeks to start of the file)
- Play
However, I don't get it to work
First of all, this is the first time I am trying to control Kodi, where I before acted on the status of Kodi only
Secondly, I use dzVents, which has kodi commands, but obviously pointed towards the standard 'Kodi media server'. I tried to rework that in the the deviceadapter folder of dzVents, but so far no luck.
Where the integrated Kodi media server had 1? device, your plugin creates several. Which device should I use to pause/play?
What is the code for it in standard LUA? I tried this:
Code: Select all
commandArray['Kodi Woonkamer - Status']='Pause'
Code: Select all
commandArray['Kodi Woonkamer - Playing']='Pause'
Can I use
Code: Select all
commandArray['Kodi Woonkamer - Status']='Play AFTER' .. variablexyz
Re: Python plugin: Kodi
I was think yesterday evening on something usefull maybe:
add an option in the hardware plugin panel -> RASPBERRY/AMLOGIC and when selected map the 'status' device in this way:
when screensaver is on (sleeping) -> the selector appear as OFF (like it appear with ping failed)
when screensaver is off (source on) -> selector appear as currently.
In this way maybe is possible to let the status switch works in two different states:
SWITCH ON -> send screensaver INACTIVE
SWITCH OFF ->send screensaver ACTIVE (like now after your update).
The "bug" is thate currently, when the source is sleeping and you click (or tap in domotociz app) the status device it send again the SCREENSAVER ON command and the kodi box wakeup and istantly goes sleep again.
Let me know if you think this could be usefull, we are all here for help you as better as we can
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin: Kodi
@jake,
I haven't looked at dzVents but I would recommend doing it simple Lua first then converting to dzVents if you want to.
Play and Pause commands can be sent to any of the devices in Domoticz and they will be applied to the currently playing media. If there is nothing playing the commands were silently ignored, I've added an log message now when that happens. I would suggest:though to make sure that timing is not an issue. From what you have said the amp will still be turning on so you won't hear the audio.
I realised thatwon't work because Domotics interprets a 'set level 0' command as an 'Off' command which isn't great so I added a 'Rewind' command as you suggested. I didn't have time to test it but it just seeks to '0' so it should work.
You will need to download version 2.3.11 from https://github.com/dnpwwo/Domoticz-Kodi-Plugin
If you are still having issues turn debug on execute you script and post the output
I haven't looked at dzVents but I would recommend doing it simple Lua first then converting to dzVents if you want to.
Play and Pause commands can be sent to any of the devices in Domoticz and they will be applied to the currently playing media. If there is nothing playing the commands were silently ignored, I've added an log message now when that happens. I would suggest:
Code: Select all
commandArray['Kodi Woonkamer - Playing']='Pause AFTER 2'
I realised that
Code: Select all
commandArray['Kodi Woonkamer - Playing']='Set Level 0 AFTER 10'
You will need to download version 2.3.11 from https://github.com/dnpwwo/Domoticz-Kodi-Plugin
If you are still having issues turn debug on execute you script and post the output
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: 742
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Python plugin: Kodi
I will indeed go for a stripped down LUA script, purely to test functionality, before adding it to a complex dzVents script. Too many trigger influence that script during execution of the kodi command. I think I will add a multi selector with play paus rewind.
-
- Posts: 742
- Joined: Saturday 30 May 2015 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: Python plugin: Kodi
I just created the proposed script and virtual switch selector:
Pressing the Pause button, gave the exptected reaction
Pressing the Play button, didn't make Kodi go 'Play', but give this message in the log:
The status device displays 'Pause'
The playing device displays 'Off' (while the track was at 70%)
While still in this state, I pressed the 'Rewind' button. Nothing happens, the log message is quite similar
With the Kodi remote I put the track to Play again and that works
Then I clicked on my selector swich Play button (while Kodi was playing already). The log:
The status device displays 'Pause'
The playing device displays 'Off' (while the track was at 72%). The 'Off' seems normal, since it does the same when I 'Pause' with the Kodi remote.
Code: Select all
--test functionality of kodi python plugin
-- add a switch selector with name 'Koditest'
-- Define 3 buttons, Pause, Rewind and Play
commandArray = {}
if devicechanged['Koditest'] == 'Pause' then
commandArray['Kodi Woonkamer - Playing']='Pause AFTER 2'
print('given the Pause command after 2 sec')
elseif devicechanged['Koditest'] == 'Rewind' then
commandArray['Kodi Woonkamer - Playing']='Rewind'
print('given the rewind command')
elseif devicechanged['Koditest'] == 'Play' then
commandArray['Kodi Woonkamer - Playing']='Play'
print('given the Play command')
end
return commandArray
Pressing the Play button, didn't make Kodi go 'Play', but give this message in the log:
Code: Select all
2018-02-17 11:15:28.229 User: Admin initiated a switch command (285/Koditest/Set Level)
2018-02-17 11:15:28.238 (Virtual Devices) Light/Switch (Koditest)
2018-02-17 11:15:28.498 LUA: given the Play command
2018-02-17 11:15:28.500 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Koditest.lua
2018-02-17 11:15:28.570 (Kodi Woonkamer) onCommand called for Unit 4: Parameter 'Play', Level: 0, Connected: True
The playing device displays 'Off' (while the track was at 70%)
While still in this state, I pressed the 'Rewind' button. Nothing happens, the log message is quite similar
Code: Select all
2018-02-17 11:22:27.776 (Kodi Woonkamer) onCommand called for Unit 4: Parameter 'Rewind', Level: 0, Connected: True
Then I clicked on my selector swich Play button (while Kodi was playing already). The log:
Code: Select all
2018-02-17 11:29:53.516 User: Admin initiated a switch command (285/Koditest/Set Level)
2018-02-17 11:29:53.525 (Virtual Devices) Light/Switch (Koditest)
2018-02-17 11:29:53.781 LUA: given the Play command
2018-02-17 11:29:53.783 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Koditest.lua
2018-02-17 11:29:53.807 (Kodi Woonkamer) onCommand called for Unit 4: Parameter 'Play', Level: 0, Connected: True
2018-02-17 11:29:53.963 (Kodi Woonkamer) Update 2:'William Walton:Symphony no 1' (Kodi Woonkamer - Status)
2018-02-17 11:29:53.973 (Kodi Woonkamer) Update 0:'71' (Kodi Woonkamer - Playing)
2018-02-17 11:29:55.231 (Kodi Woonkamer) Update 0:'72' (Kodi Woonkamer - Playing)
The playing device displays 'Off' (while the track was at 72%). The 'Off' seems normal, since it does the same when I 'Pause' with the Kodi remote.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest