Python plugin: Kodi

Python and python framework
User avatar
Dnpwwo
Posts: 736
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 » Thursday 07 June 2018 14:13

@Brutus,

The python plugin uses a different command set to the native implementation.

I've documented it on github: https://github.com/dnpwwo/Domoticz-Kodi-Plugin
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
Brutus
Posts: 322
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Python plugin: Kodi

Post by Brutus » Thursday 07 June 2018 15:11

That explains a lot :lol: :roll: I need to use "Trigger"
Going to change my scripts tonight.

Thnx for your answer.
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

User avatar
Brutus
Posts: 322
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Python plugin: Kodi

Post by Brutus » Thursday 07 June 2018 18:21

So I changed my scripts. The "Trigger" Favorites works great.

But the Volume doesn't. That command isn't changed:

Code: Select all

commandArray['Kodi TV Woonkamer'] = 'Set Volume 100'
The Log says it works:

Code: Select all

2018-06-07 18:17:20.530 (Kodi) onCommand called for Unit 1: Parameter 'Set Volume', Level: 100, Connected: True 
Using the manual remote control you can change the volume.

Code: Select all

2018-06-07 19:00:23.003 (Kodi) Update 2:'80' (Kodi - Volume)
2018-06-07 19:00:23.446 (Kodi) Update 2:'82' (Kodi - Volume) 
Am I doing something wrong?

Greetings
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

User avatar
Dnpwwo
Posts: 736
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 08 June 2018 5:20

@Brutus,

You are sending the command to the wrong device. The plugin creates 4 devices , one of them is the 'Volume' device (Unit #3). Assuming ''Kodi TV Woonkamer" is what you named the hardware then try:

Code: Select all

commandArray['Kodi TV Woonkamer - Volume'] = 'Set Volume 100'
If you renamed the 'Volume' device to something else you will obviously need to use its new name

You should see some thing like this in the log:

Code: Select all

2018-06-07 18:17:20.530 (Kodi) onCommand called for Unit 3: Parameter 'Set Volume', Level: 100, Connected: True 
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
Brutus
Posts: 322
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Python plugin: Kodi

Post by Brutus » Friday 08 June 2018 8:48

@Dnpwwo

That makes sense but still nothing changes:

Command:

Code: Select all

commandArray[1]={['Kodi - Volume'] = 'Set Volume 75'}
Log:

Code: Select all

2018-06-08 08:41:50.148 (Kodi) onCommand called for Unit 3: Parameter 'Set Volume', Level: 75, Connected: True
Devices:
Naamloos.jpg
Naamloos.jpg (99.27 KiB) Viewed 859 times
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

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

Re: Python plugin: Kodi

Post by jake » Friday 15 June 2018 22:52

@Dnpwwo:

Have you had time to look into my 'crash log' o Domoticz after the Kodi plugin didn't find Kodi for a second?
jake wrote:I am running the last version of the Kodi plugin, 2.5.6

Today my Domoticz crashed: these are the last lines in the log:
First:

Code: Select all

(Kodi Woonkamer) Device has disconnected                                                   
(Kodi Woonkamer) Update 9:'Screensaver' (Kodi Woonkamer - Status)                          
(Kodi Woonkamer) Update 20:'20' (Kodi Woonkamer - Source)                                  
(Kodi Woonkamer) Update 2:'100' (Kodi Woonkamer - Volume)                                  
(Kodi Woonkamer) Update 0:'0' (Kodi Woonkamer - Playing)
then a couple seconds later:

Code: Select all

Error: Plugin: Connection Exception: 'resolve: Host not found (authoritative)' connecting to 'onHeartbeat:9090'
(Kodi Woonkamer) Connect directive received, action initiation failed.                     
Domoticz received fatal signal 11 !...                                              
/home/pi/domoticz/domoticz() [0x2522b8]                                           
/home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x252370]                   
/lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0) [0x76cb3180]
The weird thing is that nobody used/started Kodi at all today. Kodi is running fine on it's own pi as well.

A restart of Domoticz got things rolling again, but a plugin crashing the whole setup wasn't what I had in mind today ;-)

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

Re: Python plugin: Kodi

Post by jake » Friday 15 June 2018 23:00

@Dnpwwo

You introduced the nice 'Rewind' feature that I use every time a Kodi video or audio starts while the receiver is still off.

I put the stream on 'pause', start/boot the receiver and rewind the playing stream, not to miss the start.

This works fine for 'Audio' (it rewinds and starts playing from 0.00), but 'Video' always keeps paused. Both 'audio' and 'video' trigger the same log registration, but for 'video' I always manually have to hit 'play' again (it also hasn't rewinded to 0:00)

Code: Select all

2018-06-15 22:43:17.073 (Kodi Woonkamer) onCommand called for Unit 4: Parameter 'Rewind', Level: 0, Connected: True
Could it be something in the plugin that doesn't properly rewind 'video', that it differs from 'Audio'?

User avatar
Dnpwwo
Posts: 736
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 16 June 2018 6:10

@jake,

Theoretically it should work for every media type, the decription of the Kodi method is "Seek through the playing item" for the active player. The rewind method just does a seek to "0" which should be pretty robust in theory so I'm surprised you are having issues.

A couple of questions/suggestions:
  • One potential difference between audio and video is often duration. Could you try a short video (song length) or long audio (movie length) stream to see if stream length is a factor?
  • Does seeking in general work on your video streams using the "Playing" device?
  • You could try changing line 426 in plugin.py to be

    Code: Select all

                        self.KodiConn.Send('{"jsonrpc":"2.0","method":"Player.Seek","params":{"playerid":' + str(self.playerID) + ',"value":{ "hours":0, "minutes":0, "seconds":0, "milliseconds":0}}}')
    to move from a percentage based rewind to a time based one. (I haven't tried this and the doco is far from clear so it may be incorrect)
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: 439
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake » Saturday 16 June 2018 21:11

@Dpnwwo

I don't have a long audio and short video at hand.

Shuffling around during a video with the 'playing' device works fine, backwards, forward, no problem

I updated line 426 with the revised code, but the behaviour stays the same

The rewinding action for video is executed partly, because it does rewind the video to 0:00. It only doesn't start to play.
It doesn't make a difference whether I start a local video file or a video stream from an add-on like youtube or 'uitzending gemist', the Dutch replay service from the national television.

Anyhow, since I saw that the video file was properly rewinded, I added a 'Play' command with a 1 second delay (dzVents) to the rewind command. This works fine for video and doesn't seem to hurt (stutter) for audio.

poudenes
Posts: 545
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Python plugin: Kodi

Post by poudenes » Monday 18 June 2018 17:49

Hi All,

I get this error sometimes and then a Signal 11 error:

Code: Select all

2018-06-18 16:59:02.375  Error: Plugin: Connection Exception: 'resolve: Host not found (authoritative)' connecting to 'onHeartbeat:9090'
2018-06-18 16:59:02.375  (Kodi) Connect directive received, action initiation failed.
2018-06-18 16:59:02.376  Error: (Kodi) 'onConnect' failed 'AttributeError':''str' object has no attribute 'Address''.
2018-06-18 16:59:02.376  Error: Domoticz received fatal signal 11 !...
2018-06-18 16:59:02.379  Error:   /home/pi/domoticz/domoticz() [0x25458c]
2018-06-18 16:59:02.379  Error:   /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x254644]
2018-06-18 16:59:02.379  Error:   /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer+0) [0x76c0a6b0]
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

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

Re: Python plugin: Kodi

Post by jake » Monday 18 June 2018 17:53

Last night my domoticz crashed again on the same symptoms with the Kodi plugin. I have already put the "time out of lost devices" on 'false' before this crash.

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

Re: Python plugin: Kodi

Post by jake » Monday 18 June 2018 23:53

Tonight domoticz crashed again on Kodi. It is really a pity that the whole system goes down on a hiccup in a single plugin. In winter time I am running a virtual thermostat from domoticz. Downtime has effects by then :). (on the WAF for sure)

In the meantime I now enabled all debugging on the Kodi plugin to have a better record at the next crash.

User avatar
bizziebis
Posts: 539
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by bizziebis » Sunday 26 August 2018 7:30

The plugin doesn't work anymore in the latest beta (V4.9946)

The log is flooded with

Code: Select all

2018-08-26 07:14:13.140 Error: (Kodi Python Beneden) 'onMessage' failed 'AttributeError':''dict' object has no attribute 'decode''.
2018-08-26 07:14:13.140 Error: (Kodi Python Beneden) ----> Line 638 in '/home/pi/domoticz/plugins/Domoticz-Kodi-Plugin/plugin.py', function onMessage
2018-08-26 07:14:13.140 Error: (Kodi Python Beneden) ----> Line 149 in '/home/pi/domoticz/plugins/Domoticz-Kodi-Plugin/plugin.py', function onMessage
2018-08-26 07:14:13.140 Error: (Kodi Python Beneden) 'onMessage' failed 

Code: Select all

2018-08-26 07:23:05.297 Status: PluginSystem: Started, Python version '3.5.3'.
It was working on a version of 7 July.

User avatar
Dnpwwo
Posts: 736
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 » Sunday 26 August 2018 8:34

The currently maintained Kodi plugin is here: https://github.com/dnpwwo/Domoticz-Kodi-Plugin

Can you give that one a try and let me know if there are any issues
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
bizziebis
Posts: 539
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by bizziebis » Sunday 26 August 2018 9:24

Yes, I was using that already. Updated it this morning but it didn't work. But I see you updated it again and now it works :)

User avatar
Dnpwwo
Posts: 736
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 » Sunday 26 August 2018 11:08

Yeah, I forgot to push the change.

Worked for me but no one else :oops:
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

poudenes
Posts: 545
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Python plugin: Kodi

Post by poudenes » Tuesday 28 August 2018 12:10

Hi All,

Version: 4.9957
Build Hash: edc90313
Compile Date: 2018-08-28 06:55:18
dzVents Version: 2.4.7
Python Version: 3.7.0 (default, Aug 28 2018, 09:30:30) [GCC 6.3.0 20170516]

After a clear reinstall of domoticz (because of a usb-stick failure) i get this error after restart domoticz

Code: Select all

2018-08-28 10:07:14.722  Status: (Kodi) Started.
2018-08-28 10:07:14.912  Status: (Kodi) Entering work loop.
2018-08-28 10:07:14.913  Status: (Kodi) Initialized version 2.6.4, author 'dnpwwo'
2018-08-28 10:07:14.916  Error: (Kodi) 'onStart' failed 'ValueError':'invalid literal for int() with base 10: 'null''.
2018-08-28 10:07:14.916  Error: (Kodi) ----> Line 629 in '/home/pi/domoticz/plugins/Domoticz-Kodi-Plugin/plugin.py'
2018-08-28 10:07:14.916  Error: (Kodi) ----> Line 92 in '/home/pi/domoticz/plugins/Domoticz-Kodi-Plugin/plugin.py'
and see this error while running domoticz:

Code: Select all

2018-08-28 10:09:23.326  (Kodi) Unhandled exception in onHeartbeat, forcing disconnect.
2018-08-28 10:09:23.328  (Kodi) Device has disconnected
Can this happen because of install latest Python 3.7.0?
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

Holland
Posts: 352
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by Holland » Sunday 02 September 2018 20:25

@poudenes

Had exactly the same issue.

Solved by removing the Kodi plugin directory, and I cloned it again.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests