Lua and Kodi

Moderator: leecollings

rickwilleme
Posts: 53
Joined: Wednesday 16 December 2015 15:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.6792
Location: Landgraaf, The Netherlands
Contact:

Re: Lua and Kodi

Post by rickwilleme »

Just did. Hope they're able to find the root cause of this issue :)
https://github.com/domoticz/domoticz/issues/693
Raspberry Pi ~ Fibaro Dimmer (Z-Wave) ~ Several KAKU switches and dimmers (433 MHz) ~ Amazon Echo ~ Somfy RTS ~ Sony TV ~ Kodi/XBMC ~ Essent E-Thermostaat (ICY) ~ Cresta thermostat ~ Wundermap Weather ~ Smoke detectors
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Lua and Kodi

Post by Dnpwwo »

I don't believe this is a problem with the Kodi plugin but more a feature of the way events are handled within Domoticz itself :o

From memory, when a new event is submitted for a device it overrides events already in the queue under most circumstances. I believe this is prevent unexpected results if multiple events were sent to a device in rapid succession. At the end of the day, Domoticz is designed to handle simple devices like switches so sending streams of commands does not make sense.

That said, there are work arounds as shown here:

Code: Select all

commandArray = {}

-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
    print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
    if (deviceName=='Test Trigger') then
        commandArray[1] = { ['Lounge Kodi'] = 'Pause' }
        commandArray[2] = { ['Lounge Kodi'] = 'Set Volume 50 AFTER 3' }
    end
end

return commandArray
By specifically delaying the second command both are executed as the log shows:

Code: Select all

2016-06-12 18:05:23.419 Kodi: (Lounge Kodi) Sent command: 'Input.ExecuteAction pause'.
2016-06-12 18:05:23.903 LUA: Device based event fired on 'Lounge Kodi', value 'Unknown'
2016-06-12 18:05:23.419 (Kodi Servers) Lighting 2 (Lounge Kodi)
2016-06-12 18:05:26.913 Kodi: (Lounge Kodi) Sent command: 'Set Volume'.
2016-06-12 18:05:26.915 Kodi: (Lounge Kodi) Volume changed to 50.00000, Muted: false.
2016-06-12 18:05:26.973 Kodi: (Lounge Kodi) Volume set to 50.
2016-06-12 18:05:27.137 LUA: Device based event fired on 'Lounge Kodi', value 'Unknown'
2016-06-12 18:05:26.913 (Kodi Servers) Lighting 2 (Lounge Kodi)
Have a play with it but it seemed to me that delays of less than 3 seconds were ignored so maybe you can activate the plugin then schedule the pause.

Good luck :)
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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua and Kodi

Post by dannybloe »

I agree that for commands that change the actual state of the device this is the best way to go. However, this fails with the 'execute script' command. That is a different beast and you should be able to just send a dozen of those and all of them should be executed. It's like the openURL command or sendNotification (with whatever syntax that is). They have to be queued and executed one by one. So yeah, for pause and play it doesn't make sense to have them execute all, just the last one.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
Plaagje
Posts: 42
Joined: Thursday 30 April 2015 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Netherlands
Contact:

Re: Lua and Kodi

Post by Plaagje »

Hi all,

I tried to play around with kodi and lua scripts and would like to pause my Kodi only when kodi is playing video's.
But i can only get to print the On and Off statuses and not Video Audio Photo or Paused...

I have 2 Kodi's (Kodi Livingroom, Kodi Bedroom)

This is my script:

Code: Select all

commandArray = {}

-- loop through all the devices and find the Kodi Mediaplayers
for deviceName in pairs(otherdevices) do
	Name = tostring(deviceName)
	name = deviceName:sub(1,4)
    if (name=='Kodi') then
		print (deviceName..":"..otherdevices[deviceName]);
		if (devicechanged['Doorbell_Switch'] == 'On' and otherdevices[deviceName] == 'Video') then
			commandArray[deviceName] = 'Pause'
		end
    end
end
return commandArray
The only status i see is:

Code: Select all

2017-04-01 17:15:03.275 LUA: Kodi Livingroom:On
2017-04-01 17:15:03.275 LUA: Kodi Bedroom:On
I can see the status on the dummy switch changing to Video

Image


--EDIT--

when the status changes this show up in the log:

Image

Anyone an idea or workaround?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest