Python plugin: Kodi

Python and python framework

Moderator: leecollings

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,

Now I use these commands:

Code: Select all

commandArray['Kodi TV Woonkamer'] = 'Stop'
commandArray['Kodi TV Woonkamer'] = 'Play Favorites 0'
commandArray['Kodi TV Woonkamer'] = 'Pause'
commandArray['Kodi TV Woonkamer'] = 'Play AFTER 60'
I still use the default kodi player in Domoticz to execute these commands. I already changed the name in the LUA scripts and I can see some reactions in the Log file but the actual commands don't seem to work.

Maybe the problem is that I use the wrong device because there are four of them now (status/source/volume/playing):

Code: Select all

commandArray['Kodi Woonkamer - Status'] = 'Play AFTER 60'
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,

I had to change a couple of commands because of the way Domoticz works internally.
  • To use Playlists try: Trigger Playlist ActionMovies or Trigger Playlist ActionMovies 15
  • To use Favourites try: Trigger Favorites or Trigger Favorites 3
  • To execute an addon use: Run <add-on name>
Basic stuff like Play/Pause and Stop should be the same.

If you are having trouble turn debug mode on and post the log and I will have a look.

EDIT: Just saw the 2nd bit of your post. The Domoticz device you use shouldn't matter because the command is sent to the underlying Kodi hardware which is the same for all your 'Woonkamer' devices
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,

Thank you for your reply, I will change the favorites command to:

Code: Select all

commandArray['Kodi TV Woonkamer'] = 'Trigger Favorites 0'
If I understand it correctly I only have the change the hardware name to "Kodi TV Woonkamer" instead of "Kodi Woonkamer" ofcourse remove the Old one:
Naamloos.jpg
Naamloos.jpg (78.86 KiB) Viewed 4452 times
And when I use this command for example:

Code: Select all

commandArray['Kodi TV Woonkamer'] = 'Stop'
Everything should work as before.

EDIT:
I tested the following command on the newest (1.5.2) plugin:

Code: Select all

commandArray['Kodi Woonkamer - Status'] = 'Stop'
Because this command doesn't work:

Code: Select all

commandArray['Kodi Woonkamer'] = 'Stop'
With the first command I see this line in the Log and nothing happend:

Code: Select all

2017-04-24 13:29:21.923 (Kodi Woonkamer) onCommand called for Unit 1: Parameter 'Stop', Level: 0, Connected: True 
When I use the "remote control" of the "Kodi Woonkamer - Status" device the command works and I get the same Log entry:

Code: Select all

2017-04-24 13:30:27.733 (Kodi Woonkamer) onCommand called for Unit 1: Parameter 'Stop', Level: 0, Connected: True 
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,

That looks right. The Lua commandArray is associated with Domoticz devices and not the underlying hardware.

There isn't a standard way of documenting plugins yet, I'll create a help page when there is showing the commands.
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,

I just tested the Favorites command :(
My whole Domoticz freezes, restarts and freezes again because the test script started sending the command again. I removed the plugin folder and disabled the script. After that I could place everything back in order.

Code: Select all

commandArray = {}

if  test == 'On' then
    commandArray['Kodi Woonkamer - Status'] = 'Trigger Favorites 0'
end

return commandArray
Also with this command:

Code: Select all

commandArray = {}

if  test == 'On' then

    commandArray['TEST'] = 'Off'
    commandArray['Kodi Woonkamer - Status'] = 'Trigger Favorites'
end

return commandArray
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,

Strange. I use the script below to control my Kodi. 'Lounge Kodi' is the renamed 'Status' device.

All the values come through as before for Pausing, Audio & Video etc. 'Lounge Radio' is a dummy device mapped to the Kodi Favourites and also works well.

Code: Select all

-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
    -- Lounge Kodi rules
    if (deviceName=='Lounge Kodi') then
        print ("Kodi event fired on '"..deviceName.."', value '"..tostring(deviceValue).."', Denon state '"..otherdevices['Denon'].."', Lounge Radio state '"..otherdevices['Lounge Radio'].."'");
        if (deviceValue == "On") or (deviceValue == "Off") then
            if (otherdevices['Lounge Radio'] ~= 'Off') then commandArray['Lounge Radio'] = "Off" end
            if (timeofday['Nighttime'] == true) and (otherdevices['Lounge Dimmer'] == 'Off') then SetDimmerLevel('Lounge Dimmer') end
        elseif (deviceValue == "Paused") then
            if (timeofday['Nighttime'] == true) and (otherdevices['Lounge Dimmer'] == 'Off') then SetDimmerLevel('Lounge Dimmer') end
        elseif (deviceValue == "Audio") then
            if (otherdevices['Denon'] ~= 'Kodi') then commandArray['Denon'] = 'Set Level 30' end
        elseif (deviceValue == "Video") then
            if (otherdevices['Denon'] ~= 'Kodi') then commandArray['Denon'] = 'Set Level 30' end
            if (otherdevices['Lounge Radio'] == 'Off') then --slight hack because Internet Radio streams show as Video
                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
    if (deviceName=='Lounge Radio') then
        print ("Kodi event fired on '"..deviceName.."', value '"..deviceValue.."', Lounge Kodi state '"..otherdevices['Lounge Kodi'].."', Denon state '"..otherdevices['Denon'].."'");
        -- Need to synchronise radio event with Denon Amplifier and Lounge Kodi states
        -- URLs for streaming can be found here: http://streamlist.southerncrossaustereo.com.au/
        if (deviceValue == 'Off') then
            if (otherdevices['Lounge Kodi'] ~= 'On') then commandArray['Lounge Kodi'] = 'Stop' end
        else
            -- The Denon start up can cause a Kodi 'Stop' command so 
            if (deviceValue == '101.9 Fox FM') then
                commandArray['Lounge Kodi'] = 'Trigger Favorites 0'
            elseif (deviceValue == '104.3 Gold FM') then
                commandArray['Lounge Kodi'] = 'Trigger Favorites 1'
            elseif (deviceValue == '105.1 Triple M FM') then
                commandArray['Lounge Kodi'] = 'Trigger Favorites 2'
            end
            if (otherdevices_lastupdate['$Denon - Power'] == 'Off') then
                commandArray['Denon - Volume'] = 'Set Level 30 AFTER 5'
            end
        end
    end
 end
Is your beta version up to date? Can't think of any other reason for the issues you describe.
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,

I'm running Beta V3.7379 on Windows 7 64 Bits.

I renamed the "Status" device to "Kodi Woonkamer" but it keeps crashing when I execute this command line:

Code: Select all

commandArray['Kodi Woonkamer'] = 'Trigger Favorites 0'
Then the only solution is to use both the plugins.
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
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by G3rard »

@Dnpwwo, is there anything special needed in a plugin to enable the remote function?
I made a plugin for my TV, which has the following code to generate the device.

Code: Select all

Domoticz.Device(Name="Status", Unit=1, Type=17, Image=2, Switchtype=17).Create()
That is the same type and switchtype as you use in your Kodi plugin, but it wont show the remote options when pressing on the remote.
Not using Domoticz anymore
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python plugin: Kodi

Post by zak45 »

+1 for me
What I know this work only for Kodi & Panasonic...
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,

If you are still having issues can you turn debugging on for the plugin and post the output. It would be useful if you ran it from the command line to make sure I can see the whole log, it is quite verbose and the web interface quite often drops some output.

@G3rard & @zak45,

The problem is in the web front end, there is no default remote, the default is to do nothing. If kodi was the default it would show a remote and send commands to the running plugin.

I can't change this at the moment because there are some big Python changes coming and my dev setup is quite different to the current beta channel.

Domoticz.js needs to be tweaked, ShowMediaRemote and click_media_remote functions (around line 3250) to make that happen.

EDIT: To test to see if it would work you could change the name of your hardware in the plugin XML definition to have the work 'Kodi' in it. Then the remote should come up and actions should go to your 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
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python plugin: Kodi

Post by zak45 »

@Dnpwwo
Great.. thanks a lot, test it and it's work.

@G3rard
have include on it the modification for Sony, so this should work for you also ;-)
Do not forget to refersh the cache.
and here is my python code used for testing, can give you some idea :

Code: Select all

def remoteSend(Command,Unit):
    global numberMute

    remoteKEY=("KEY_MUTE","KEY_VOLUP","KEY_VOLDOWN")
    remoteSEEK=("Mute","VolumeUp","VolumeDown")
    
    if Command in remoteSEEK:
        k = remoteSEEK.index(Command) 
        
        if Command == "Mute":
            numberMute += 1
        SamsungSend(str(remoteKEY[k]),Unit,0)
        if Parameters["Mode6"] == "Debug":
            Domoticz.Log('Remote send: ' + str(k) + str(remoteKEY[k]))
    else:
        Domoticz.Error('Remote command not defined: ' + Command)
    
    return
domoticz.js.gz
(35.52 KiB) Downloaded 75 times
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python plugin: Kodi

Post by zak45 »

More ... more simple

put Kodi keyword on the plugin name i.e:
<plugin key="SamsungTV" name="Samsung TV with Kodi Remote" author="zak45"

and voila...

Big THANKS @Dnpwwo
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by G3rard »

@Dnpwwo, @zak45, thanks!
Indeed added the word Kodi to the name of the plugin and then the remote works :)
Not using Domoticz anymore
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 »

New version of the Kodi plugin that adds on screen notifications from the plugin it self.

Currently in Domoticz you can enable notifications for one or more Kodi globally. If you want finer control, turn off the existing Kodi notifications and enable notifications in the hardwate screen for an individual Kodi plugin. You must supply a notification name without spaces.

Now the plugin will show up on the 'Notifications' page for devices and you can send notifications to it.
Kodi 1.6.0.rar
(33.41 KiB) Downloaded 109 times
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,

Thank you for this update! This will solve my old problem on a Windows Machine that can't send notifications when installed as a service.

Greetings.

EDIT: My joy was for a short time.. It still doesn't work at A Windows Machine running Domoticz as a service.
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
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Python plugin: Kodi

Post by G3rard »

@Dnpwwo, thanks for this update.
The new notification method works great!
Not using Domoticz anymore
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, do you think you will be able to complete the feature request to add another Kodi state (besides on/off/video/audio): something like sleep, by detecting when the screensaver is active?
maomanna
Posts: 94
Joined: Monday 30 November 2015 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Kodi

Post by maomanna »

i have 3 kodi's, but only 1 is updating its status. The others keep saying: Unavailable.
All services are enabled. ports are correct, no username and passwords.

what am i doing wrong?
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 »

Update Kodi plugin that works with new beta. Other functionality is unchanged.
Kodi 1.7.1.rar
(33.33 KiB) Downloaded 147 times
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
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Python plugin: Kodi

Post by capman »

Domoticz version beta 3.7468 with python from Jadahl on synology. Plugin version 1.7.1
Get some errors in the log
Spoiler: show
2017-06-05 13:39:15.034 (Kodi woonkamer) 'kodi':'ID: 103, Base: 'kodi', Name: Kodi, Description: 'Kodi''
2017-06-05 13:39:15.034 (Kodi woonkamer) 'KodiRound':'ID: 116, Base: 'KodiRound', Name: Kodi, Description: 'Kodi Media Player''
2017-06-05 13:39:15.034 (Kodi woonkamer) 'KodiBlack':'ID: 115, Base: 'KodiBlack', Name: Kodi, Description: 'Kodi Media Player''
2017-06-05 13:39:15.034 (Kodi woonkamer) 'Kodi':'ID: 114, Base: 'Kodi', Name: Kodi, Description: 'Kodi Media Player''
2017-06-05 13:39:15.034 (Kodi woonkamer) Device count: 4
2017-06-05 13:39:15.035 (Kodi woonkamer) Device: 1 - ID: 369, Name: 'Kodi woonkamer - Status', nValue: 1, sValue: ''
2017-06-05 13:39:15.035 (Kodi woonkamer) Device ID: '369'
2017-06-05 13:39:15.035 (Kodi woonkamer) Device Name: 'Kodi woonkamer - Status'
2017-06-05 13:39:15.035 (Kodi woonkamer) Device nValue: 1
2017-06-05 13:39:15.035 (Kodi woonkamer) Device sValue: ''
2017-06-05 13:39:15.035 (Kodi woonkamer) Device LastLevel: 0
2017-06-05 13:39:15.035 (Kodi woonkamer) Device Image: 114
2017-06-05 13:39:15.035 (Kodi woonkamer) Device: 2 - ID: 370, Name: 'Kodi woonkamer - Source', nValue: 10, sValue: '10'
2017-06-05 13:39:15.035 (Kodi woonkamer) Device ID: '370'
2017-06-05 13:39:15.035 (Kodi woonkamer) Device Name: 'Kodi woonkamer - Source'
2017-06-05 13:39:15.035 (Kodi woonkamer) Device nValue: 10
2017-06-05 13:39:15.035 (Kodi woonkamer) Device sValue: '10'
2017-06-05 13:39:15.036 (Kodi woonkamer) Device LastLevel: 0
2017-06-05 13:39:15.036 (Kodi woonkamer) Device Image: 114
2017-06-05 13:39:15.036 (Kodi woonkamer) Device: 3 - ID: 371, Name: 'Kodi woonkamer - Volume', nValue: 2, sValue: '100'
2017-06-05 13:39:15.036 (Kodi woonkamer) Device ID: '371'
2017-06-05 13:39:15.036 (Kodi woonkamer) Device Name: 'Kodi woonkamer - Volume'
2017-06-05 13:39:15.036 (Kodi woonkamer) Device nValue: 2
2017-06-05 13:39:15.036 (Kodi woonkamer) Device sValue: '100'
2017-06-05 13:39:15.036 (Kodi woonkamer) Device LastLevel: 100
2017-06-05 13:39:15.036 (Kodi woonkamer) Device Image: 8
2017-06-05 13:39:15.036 (Kodi woonkamer) Device: 4 - ID: 372, Name: 'Kodi woonkamer - Playing', nValue: 0, sValue: '0'
2017-06-05 13:39:15.047 (Kodi woonkamer) Device ID: '372'
2017-06-05 13:39:15.047 (Kodi woonkamer) Device Name: 'Kodi woonkamer - Playing'
2017-06-05 13:39:15.047 (Kodi woonkamer) Device nValue: 0
2017-06-05 13:39:15.047 (Kodi woonkamer) Device sValue: '0'
2017-06-05 13:39:15.047 (Kodi woonkamer) Device LastLevel: 28
2017-06-05 13:39:15.047 (Kodi woonkamer) Device Image: 114
2017-06-05 13:39:15.047 (Kodi woonkamer) Device Image update: 'Kodi', Currently 114, should be 114
2017-06-05 13:39:15.048 (Kodi woonkamer) Device Image update: 'Kodi', Currently 114, should be 114
2017-06-05 13:39:15.048 (Kodi woonkamer) Device Image update: 'Kodi', Currently 114, should be 114
2017-06-05 13:39:15.048 Error: (Kodi woonkamer) 'onStart' failed 'AttributeError':'module 'Domoticz' has no attribute 'Connection''.
2017-06-05 13:39:15.048 Error: (Kodi woonkamer) ----> Line 518 in /usr/local/domoticz/var/plugins/Kodi/plugin.py, function onStart
2017-06-05 13:39:15.048 Error: (Kodi woonkamer) ----> Line 90 in /usr/local/domoticz/var/plugins/Kodi/plugin.py, function onStart

2017-06-05 13:39:21.740 (RFXtrx433) Temp (Kelder)
2017-06-05 13:39:24.726 (Kodi woonkamer) Calling message handler 'onHeartbeat'.
2017-06-05 13:39:24.727 Error: (Kodi woonkamer) 'onHeartbeat' failed 'AttributeError':''NoneType' object has no attribute 'Connected''.
2017-06-05 13:39:24.727 Error: (Kodi woonkamer) ----> Line 546 in /usr/local/domoticz/var/plugins/Kodi/plugin.py, function onHeartbeat
2017-06-05 13:39:24.727 Error: (Kodi woonkamer) ----> Line 421 in /usr/local/domoticz/var/plugins/Kodi/plugin.py, function onHeartbeat

2017-06-05 13:39:32.523 (RFXtrx433) Temp + Humidity (Gastentoilet)
2017-06-05 13:39:32.732 (RFXtrx433) Temp + Humidity (Gastentoilet)
2017-06-05 13:39:34.936 (Kodi woonkamer) Calling message handler 'onHeartbeat'.
2017-06-05 13:39:34.937 Error: (Kodi woonkamer) 'onHeartbeat' failed 'AttributeError':''NoneType' object has no attribute 'Connected''.
2017-06-05 13:39:34.937 Error: (Kodi woonkamer) ----> Line 546 in /usr/local/domoticz/var/plugins/Kodi/plugin.py, function onHeartbeat
2017-06-05 13:39:34.937 Error: (Kodi woonkamer) ----> Line 421 in /usr/local/domoticz/var/plugins/Kodi/plugin.py, function onHeartbeat

.
.
.
And so on....
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest