Python plugin: Kodi

Python and python framework

Moderator: leecollings

User avatar
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

Post by Dnpwwo »

@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: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Python plugin: Kodi

Post by Brutus »

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

Thnx for your answer.
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Python plugin: Kodi

Post by Brutus »

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 NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
User avatar
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

Post by Dnpwwo »

@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: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: Python plugin: Kodi

Post by Brutus »

@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 2447 times
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

@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: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

@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: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin: Kodi

Post by Dnpwwo »

@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: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

@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: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Python plugin: Kodi

Post by poudenes »

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 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

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: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

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: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by bizziebis »

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: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin: Kodi

Post by Dnpwwo »

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: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by bizziebis »

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: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugin: Kodi

Post by Dnpwwo »

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: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Python plugin: Kodi

Post by poudenes »

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 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Holland
Posts: 179
Joined: Friday 12 July 2013 13:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta Ch
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by Holland »

@poudenes

Had exactly the same issue.

Solved by removing the Kodi plugin directory, and I cloned it again.
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

Domoticz crash because of error in Kodi plugin (version 2.5.6):

Code: Select all

2018-09-24 17:16:13.064  Error: Plugin: Connection Exception: 'resolve: Host not found (authoritative)' connecting
2018-09-24 17:16:13.064  (Kodi Living) Connect directive received, action initiation failed.
2018-09-24 17:16:13.064  Error: Domoticz received fatal signal 11 !...
2018-09-24 17:16:13.066  Error:   /home/pi/domoticz/domoticz() [0x254670]
2018-09-24 17:16:13.066  Error:   /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x254728]
2018-09-24 17:16:13.067  Error:   /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0) [0x76c48180]
BTW, Kodi is still running fine.
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Python plugin: Kodi

Post by jake »

Within 24hr, I experienced the same kind of error, with a slightly different log report:

Code: Select all

2018-09-25 18:34:39.809  (Kodi Living) Connected successfully to: 192.168.1.31:9090
2018-09-25 18:34:39.867  (Kodi Living) Update 2:'100' (Kodi Living - Volume)
2018-09-25 18:34:40.212  Error: Domoticz received fatal signal 11 !...
2018-09-25 18:34:40.227  Error:   /home/pi/domoticz/domoticz() [0x254670]
2018-09-25 18:34:40.227  Error:   /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x254728]
2018-09-25 18:34:40.227  Error:   /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer_v2+0) [0x76ce7180]
2018-09-25 18:34:40.227  Error:   /home/pi/domoticz/domoticz(_ZN7Plugins16CPluginTransport16VerifyConnectionEv+0x28
2018-09-25 18:34:40.227  Error:   /home/pi/domoticz/domoticz(_ZN7Plugins7CPlugin7Do_WorkEv+0x19c) [0x5b504c]
2018-09-25 18:34:40.227  Error:   /home/pi/domoticz/domoticz() [0x7e2258]
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest