Python plugin: Kodi

Python and python framework
User avatar
Dnpwwo
Posts: 657
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin: Kodi

Post by Dnpwwo » Tuesday 12 December 2017 10:42

Latest Update: v2.0.6 - December 12th, 2017 requires recent beta
  • 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
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

jake
Posts: 309
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake » Wednesday 27 December 2017 2:06

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.

TheCondor
Posts: 40
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Kodi

Post by TheCondor » Wednesday 27 December 2017 23:34

Dnpwwo wrote:
Tuesday 12 December 2017 10:42
Latest Update: v2.0.6 - December 12th, 2017 requires recent beta
  • 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


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!

User avatar
Dnpwwo
Posts: 657
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin: Kodi

Post by Dnpwwo » Friday 29 December 2017 3: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:
  • 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
with the Kodi V8 API you seem to be able to do the first 2 1/2 of the 4 (mostly).

The command you mentioned switches the window to the screen saver but not properly. Have a look at:
Spoiler: show
2017-12-29 11:02:42.065 (Тест) onCommand called for Unit 1: Parameter 'Home', Level: 0, Connected: True
2017-12-29 11:02:42.125 (Тест) GUI.OnScreensaverDeactivated recieved, Player ID: -1
2017-12-29 11:05:42.537 (Тест) GUI.OnScreensaverActivated recieved, Player ID: -1
2017-12-29 11:05:43.166 EventSystem: script device trigger (Test)
2017-12-29 11:05:43.166 (Тест) Update 9:'Screensaver' (Тест - Status)
2017-12-29 11:06:08.202 User: Admin initiated a switch command (42/Тест - Status/Off)
2017-12-29 11:06:08.261 (Тест) onCommand called for Unit 1: Parameter 'Off', Level: 0, Connected: True
2017-12-29 11:06:08.313 (Тест) GUI.OnScreensaverDeactivated recieved, Player ID: -1
2017-12-29 11:06:08.528 EventSystem: script device trigger (Test)
2017-12-29 11:06:08.529 (Тест) Update 1:'' (Тест - Status)
2017-12-29 11:06:08.729 (Тест) Sleep command accepted.
2017-12-29 11:06:08.986 EventSystem: script device trigger (Test)
2017-12-29 11:06:08.987 (Тест) Update 9:'Screensaver' (Тест - Status)
2017-12-29 11:17:16.395 (Тест) GUI.OnScreensaverDeactivated recieved, Player ID: -1
2017-12-29 11:17:17.004 EventSystem: script device trigger (Test)
2017-12-29 11:17:17.005 (Тест) Update 1:'' (Тест - Status)
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.

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

TheCondor
Posts: 40
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Kodi

Post by TheCondor » Saturday 30 December 2017 12:30

Dnpwwo wrote:
Friday 29 December 2017 3: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:
  • 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
with the Kodi V8 API you seem to be able to do the first 2 1/2 of the 4 (mostly).

The command you mentioned switches the window to the screen saver but not properly. Have a look at:
Spoiler: show
2017-12-29 11:02:42.065 (Тест) onCommand called for Unit 1: Parameter 'Home', Level: 0, Connected: True
2017-12-29 11:02:42.125 (Тест) GUI.OnScreensaverDeactivated recieved, Player ID: -1
2017-12-29 11:05:42.537 (Тест) GUI.OnScreensaverActivated recieved, Player ID: -1
2017-12-29 11:05:43.166 EventSystem: script device trigger (Test)
2017-12-29 11:05:43.166 (Тест) Update 9:'Screensaver' (Тест - Status)
2017-12-29 11:06:08.202 User: Admin initiated a switch command (42/Тест - Status/Off)
2017-12-29 11:06:08.261 (Тест) onCommand called for Unit 1: Parameter 'Off', Level: 0, Connected: True
2017-12-29 11:06:08.313 (Тест) GUI.OnScreensaverDeactivated recieved, Player ID: -1
2017-12-29 11:06:08.528 EventSystem: script device trigger (Test)
2017-12-29 11:06:08.529 (Тест) Update 1:'' (Тест - Status)
2017-12-29 11:06:08.729 (Тест) Sleep command accepted.
2017-12-29 11:06:08.986 EventSystem: script device trigger (Test)
2017-12-29 11:06:08.987 (Тест) Update 9:'Screensaver' (Тест - Status)
2017-12-29 11:17:16.395 (Тест) GUI.OnScreensaverDeactivated recieved, Player ID: -1
2017-12-29 11:17:17.004 EventSystem: script device trigger (Test)
2017-12-29 11:17:17.005 (Тест) Update 1:'' (Тест - Status)
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.

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!

TheCondor
Posts: 40
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Kodi

Post by TheCondor » Saturday 13 January 2018 15:27

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:

Code: Select all

#!/bin/bash
SSHPASS='libreelec' sshpass -e ssh [email protected] "sleep 2; kodi-send --action="Stop" && sleep 2; kodi-send --action="ActivateScreensaver""
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.

User avatar
EdwinK
Posts: 1000
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python plugin: Kodi

Post by EdwinK » Saturday 20 January 2018 18:20

Can I use this plugin for two (or more) Kodi devices ?
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

User avatar
Dnpwwo
Posts: 657
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin: Kodi

Post by Dnpwwo » Saturday 20 January 2018 23:16

@EdwinK,

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

User avatar
EdwinK
Posts: 1000
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python plugin: Kodi

Post by EdwinK » Sunday 21 January 2018 0:01

Okay. Thanks. Will do.
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest