[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)

  Thread Rating:
  • 3 Votes - 4.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #16
(2013-03-28 16:21)fernandovg Wrote:  Can I run this infinite loop script in you add-on?

Shouldn't be a problem. I see you already tried and it is working. Glad it also works for you!
find quote
fernandovg Offline
Fan
Posts: 407
Joined: Jul 2012
Reputation: 4
Location: Brazil
Post: #17
Is it possible to add multiple scripts "per category"?

[Image: all-thin-banner.jpg]
find quote
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #18
(2013-03-29 16:40)mbw2001 Wrote:  Would it be possible to catch the "Put display to sleep when idle" from Power Saving?

I am currently powering down my projector when the screen saver is activated, but i would like to be able to use Dim for screen saver and only poweroff the projector when idle.

Sorry don't really understand. You don't want to use the "screensaver start" callback but another one which is related to the "put display to sleep"??

I don't know if xbmc publishes that callback to addons though... But I'll check anyway...
find quote
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #19
(2013-03-29 19:42)fernandovg Wrote:  Is it possible to add multiple scripts "per category"?

What do you mean "per category"? You mean by knowing if a movie or audio is playing? If so you can already do something similar as the scripts execute with an argument telling if the item played is video or audio.

Regards,
find quote
fernandovg Offline
Fan
Posts: 407
Joined: Jul 2012
Reputation: 4
Location: Brazil
Post: #20
No. More than one script at Xbmc Startup, etc

[Image: all-thin-banner.jpg]
find quote
spoyser Offline
Donor
Posts: 376
Joined: Oct 2011
Reputation: 21
Post: #21
(2013-03-30 14:13)fernandovg Wrote:  No. More than one script at Xbmc Startup, etc

Just have it start a script that then starts all the scripts you want.
find quote
hallonterror Offline
Junior Member
Posts: 2
Joined: Apr 2013
Reputation: 0
Post: #22
This script seems very promising. I previously used an external method to detect changes in the state of XBMC, but this plugin would improve and simplify what I'm trying to do.

I have a Raspberry Pi running Xbian. I have installed something called WiringPi that allows access to the GPIO pins without root or sudo. From the terminal I am able to call

Code:
>> /home/xbian/init.sh
>> /home/xbian/on.sh
>> /home/xbian/off.sh

to init the correct pins as outputs, turn them on and then off again.

There are no errors as far as I can see in the XBMC log. The content of the script files are very rudimentary;

Code:
#!/bin/bash
gpio export 22 out
gpio export 23 out
gpio export 24 out
gpio export 25 out

Takes care of setting the pins while the following changes the state to on or off:

Code:
#!/bin/bash
gpio -g write 22 0
gpio -g write 23 0
gpio -g write 24 0
gpio -g write 25 0
Code:
#!/bin/bash
gpio -g write 22 1
gpio -g write 23 1
gpio -g write 24 1
gpio -g write 25 1

The strings shown to me in the settings for the plugin shows the exact same paths as used above, when manually running the scripts. I have set the init script to run at start and the other two when the screensaver stops or starts. I downloaded the latest available version from the homepage today (2013-04-11).

Am I doing something fundamentally wrong? The states of the pins just wont change...
find quote
fernandovg Offline
Fan
Posts: 407
Joined: Jul 2012
Reputation: 4
Location: Brazil
Post: #23
Try ssh and: sh on.sh

See the result

[Image: all-thin-banner.jpg]
find quote
hallonterror Offline
Junior Member
Posts: 2
Joined: Apr 2013
Reputation: 0
Post: #24
I did.
Code:
>>sh on.sh
gives the exact same result as the ./on.sh would. What I mean by this is that the scripts work as intended they are just not executed or doesn't do anything when run from the plugin.
(This post was last modified: 2013-04-13 01:53 by hallonterror.)
find quote
dven Offline
Junior Member
Posts: 2
Joined: Apr 2013
Reputation: 0
Post: #25
script on "Player starts" execute twice:

Code:
21:35:51 T:140389381601152   DEBUG: CAnnouncementManager - Announcement: OnPlay from xbmc
21:35:51 T:140389381601152   DEBUG: GOT ANNOUNCEMENT, type: 1, from xbmc, message OnPlay
21:35:51 T:140389033953024   DEBUG: XBMC callbacks: player starts
21:35:51 T:140389033953024   DEBUG: XBMC callbacks: Going to execute script = "/home/xbmc/test.sh"
21:35:51 T:140389033953024   DEBUG: XBMC callbacks: player starts
21:35:51 T:140389033953024   DEBUG: XBMC callbacks: Going to execute script = "/home/xbmc/test.sh"

please, help fix it
find quote
TheCooK Offline
Junior Member
Posts: 10
Joined: Apr 2010
Reputation: 0
Post: #26
Thanks for the great script!

It saved my day... now i can use my zwave dimmer to control light Scenes when watching a movie...

i made three Versions of the same small console application to call an URL... i dont know if anyone will use this, but why not post it here:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace callurl
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://rpi:8083/ZWaveAPI/Run/devices%5B2%5D.instances%5B0%5D.commandClasses%5B0x26%5D.Set(99)";
            WebRequest request = HttpWebRequest.Create(url);
            WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string urlText = reader.ReadToEnd();

        }
    }
}

of course you guys Need to set "URL" to whatever you want to call... the above Thing turns my light on to "99" %
one more Thing... if you want to avoid a console window when starting the .exe - in Visual Studio just go to Project Settings and set "Output" to "Windows Application" ... and its gone!

Thanks again!

TheCooK

edit by Kib: I added some proper code tags Smile
(This post was last modified: 2014-02-08 01:04 by Kib.)
find quote
ajoburg Offline
Junior Member
Posts: 27
Joined: Feb 2013
Reputation: 0
Location: San Francisco
Post: #27
Are the scripts specified by setting value="/path/to/my/script" in the resources/settings.xml file (as described here)?

My file is as follows...and the addon loads...but no scripts are logged. Any ideas?

settings.xml
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<settings>
    <category label="32000">.
      <setting label="32010" type="executable" id="xbmc_starts"/>
      <setting label="32012" type="executable" id="player_starts" value="/home/pi/test.py"/>
      <setting label="32013" type="executable" id="player_stops"/>
      <setting label="32014" type="executable" id="player_pauses"/>
      <setting label="32015" type="executable" id="player_resumes"/>
      <setting label="32016" type="executable" id="screensaver_starts"/>
      <setting label="32017" type="executable" id="screensaver_stops"/>
      <setting label="32018" type="executable" id="xbmc_idle"/>
      <setting label="32019" type="slider" id="idle_time" default="10" range="1,1,60" option="int" />
    </category>
</settings>

xbmc.log
Code:
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script version 0.2 started
23:29:36 T:2929574976   DEBUG: NEWADDON PythonCallbackHandler construction with PyThreadState 0xb3f00860
23:29:36 T:2955805760   DEBUG: CecLogMessage - command 'POLL' was not acked by the controller
23:29:36 T:2955805760   DEBUG: CecLogMessage - >> POLL not sent
23:29:36 T:2938229824    INFO: Python script stopped
23:29:36 T:2938229824   DEBUG: Thread XBPyThread 2938229824 terminating
23:29:36 T:2929574976   DEBUG: NEWADDON PythonCallbackHandler construction with PyThreadState 0xb3f00860
23:29:36 T:2929574976   DEBUG: XBMC callbacks: Reading properties
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script xbmc starts = ""
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script player starts = ""
23:29:36 T:2921186368  NOTICE:  StorageServer Module loaded RUN
23:29:36 T:2921186368  NOTICE: StorageClient-2.5.0 Starting server
23:29:36 T:2921186368  NOTICE: StorageServer-2.5.0 Storage Server starting /home/pi/.xbmc/userdata/addon_data/script.common.plugin.cache/commoncache.db
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script player stops = ""
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script player pauses = ""
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script player resumes = ""
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script screensaver starts = ""
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script screensaver stops = ""
23:29:36 T:2929574976   DEBUG: XBMC callbacks: script idle = ""
find quote
matbor Offline
Senior Member
Posts: 147
Joined: Jun 2004
Reputation: 0
Location: Melbourne, Australia
Post: #28
Couple of quick questions...

* will this run python scripts?
* will it work on ATV2?

The reason for my two questions are that I have a couple of Python scripts on my ATV2 that I can run from within XBMC -> System -> File Manager -> (Navigate to the same directory as below) -> xbmc_play.py and they work perfectly fine, they do what I want them to do.

But when I add them to your plugin, I can see it calling the scripts but it doesn't do anything else!

Part of the Log; (have full log if u need it, but can't see any other XBMC callbacks)
Code:
22:52:50 T:145391616   DEBUG: XBMC callbacks: player starts
22:52:50 T:145391616   DEBUG: XBMC callbacks: Going to execute script = "/var/mobile/Library/Preferences/XBMC/userdata/Scripts/xbmc_play.py"


Thx
Matt.

4x ATV2's (v4.3) XBMC Frodo12.2. Raspberry Pi running MYSQL 5.5.31-0+wheezy1. NAS is a Drobo FS
(This post was last modified: 2013-06-05 15:11 by matbor.)
find quote
pilluli Offline
Fan
Posts: 340
Joined: Jul 2006
Reputation: 1
Post: #29
It does work on python scripts (actually, all of mine are python)

Could you paste the first 3-4 lines of the script?

The script needs to be marked as executable, meaning, that you should be able to run it stand-alone.

Mine look llike this:

Code:
#!/usr/bin/env python

import os
import time
import sys

# Check if not music
if not 'music' in sys.argv[1]:



(2013-06-05 12:48)matbor Wrote:  Couple of quick questions...

* will this run python scripts?
* will it work on ATV2?

The reason for my two questions are that I have a couple of Python scripts on my ATV2 that I can run from within XBMC -> System -> File Manager -> (Navigate to the same directory as below) -> xbmc_play.py and they work perfectly fine, they do what I want them to do.

But when I add them to your plugin, I can see it calling the scripts but it doesn't do anything else!

Part of the Log; (have full log if u need it, but can't see any other XBMC callbacks)
Code:
22:52:50 T:145391616   DEBUG: XBMC callbacks: player starts
22:52:50 T:145391616   DEBUG: XBMC callbacks: Going to execute script = "/var/mobile/Library/Preferences/XBMC/userdata/Scripts/xbmc_play.py"


Thx
Matt.
find quote
matbor Offline
Senior Member
Posts: 147
Joined: Jun 2004
Reputation: 0
Location: Melbourne, Australia
Post: #30
my settings.xml

my xbmc_play.py (which I changed to look like yours)

my original xbmc_stop.py (I later added the test_stop.py script to the this)

my test_stop.py script<-- This just writes to the xbmc.log file with a print statement does nothing else. (PRINTs "XBMC TEST STOP SCRIPT" to the xbmc.log file when run)

my file permissions (note, haven't done them all)

my xbmc log file

The logfile;
@21:52:41 T:150085632; I manually run the script 'test_stop.py' from within XBMC's file manager and it works fine.

@21:53:16 T:105340928; you can see where I kicked off a video and it calls the xbmc_play.py file but doesn't do anything.

@21:53:23 T:105340928; you can see here that I stopped the video and it again calls the test_stop.py file but again doesn't do anything. (it is only meant to write to the logfile )

Couple of notes.
* All the scripts that I have written work fine from within the xbmc file manager.
* I can't run any python script from the commandline (via SSH), but I think that is because I use ATV2's (correct me if i'm wrong here)

Hope this helps!

4x ATV2's (v4.3) XBMC Frodo12.2. Raspberry Pi running MYSQL 5.5.31-0+wheezy1. NAS is a Drobo FS
find quote
Post Reply