Kodi Community Forum

Full Version: Variable from 3rd party console script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I decided to create my own skin for Kodi. I have raspberry pi with outdoor thermometer. I would like to display current temperature.
What is the best way to do this?

I have python script (let's assume /get_current_temperature.py) which returns data which can be used in Kodi skin.
It should be updated every hours or even often.

My first idea was to use python-xbmc and update global skin variable via jsonrpc (python script + cron), but looks that is not possible.

removed151214

Three possibilities occur to me off the top of my head (and in ascending order or preference).

You could use an external script run via Cron to write a file, then read the file via a Kodi script and update any window properties (or wherever else you want to do).

You could use the fantastic Kodi script here - http://forum.kodi.tv/showthread.php?tid=209171 - in the Kodi element of the script, and manually implement Pyro4 in the external script. Then you could pass the variable directly from the external script, and do whatever you want with it in the internal one.

You could implement the temperature monitor as a (an? That used to sound better when this project was named XBMC!) Kodi service, including any external modules it requires within the script itself, or provide them as additional Kodi script.module.*'s. Then, the script could set a window property directly, which could be displayed by a skin (or use the script linked in the previous option, if you want to use an additional script/instance of the script to display the information.)

Whichever way you go, the Python Development forum may be a more appropriate place to get more assistance. Smile
Thank you for your support. I will try to use given Kodi script first.
(2014-12-07, 00:32)artemi Wrote: [ -> ]I decided to create my own skin for Kodi. I have raspberry pi with outdoor thermometer. I would like to display current temperature.
What is the best way to do this?

I have python script (let's assume /get_current_temperature.py) which returns data which can be used in Kodi skin.
It should be updated every hours or even often.

My first idea was to use python-xbmc and update global skin variable via jsonrpc (python script + cron), but looks that is not possible.

Did you find a way to do what you wanted. I'm looking to make a program addon that will do the same. Your work could really help getting me started.
There are probably a couple of ways to do what you want:
  1. Create a service within Kodi.
  2. Have your script run outside Kodi but set a variable that Kodi can read.

Create a service
Assuming your sensor is connected to a GPIO pin, you'll probably need to use a module like pigpio in the service as this doesn't require root access to read the pins (as pigpio has a daemon server running as root in the background).

You service would then just read the sensor variable and set a skin setting that your skin can read (e.g. by using "Skin.SetString(string[,value])" - see List_of_built-in_functions (wiki)).

Run a script outside Kodi
You can create a script to read your sensor and set the skin string from outside Kodi by using "xbmc-send" (you'll need to search for download instructions).

I don't think it's currently possible to run built-in functions via JSON but, if I'm wrong, then that would be another way of doing it outside Kodi,

You could then use cron to run your script every hour.


Hope that helps.
I'm trying to archive a similar thing. In my case I have a txt generated by python with some variables that I need to use in my XML but I can't find a simple solution. All I know is I can't edit "on-the-fly" the text label on my xml because Kodi don't read new values if I don't reload the skin.
I think you're doing it wrong then!

If you're trying to hard code the value in the xml file itself then, you're right, the change won't be shown until you reload the skin.

However, if your skin uses an infolabel and you change the value, the skin should reflect that change.
I think that, unless it is something too complex creating a new WindowXML (even if based on the original skin window) will give more freedom to the user. In this case you can have a while cycle to set the value of the label or textbox inside the window class itself.
You can also create a new property for the window (and use it on the label or textbox value) and then you set the property using builtin functions from your service or script. I am not sure about infolabels to be honest...I think they have a list of possibilities (you can't probably create new ones) and they will probably be re-set by kodi itself at some point
I'll happily defer to enen92's jusgment as they're more experienced than I am.

My personal experience is using an infolabel (using Skin.String(stringname)) worked perfectly to display one custom string on the skin I was using. It's very easy to set the string by using Skin.SetString(stringname, value).
(2015-08-27, 15:58)el_Paraguayo Wrote: [ -> ]I think you're doing it wrong then!
Yes probably I'm doing it wrong, otherwise it will works. Tongue
(2015-08-27, 16:14)enen92 Wrote: [ -> ]I think that, unless it is something too complex creating a new WindowXML (even if based on the original skin window) will give more freedom to the user. In this case you can have a while cycle to set the value of the label or textbox inside the window class itself.
You can also create a new property for the window (and use it on the label or textbox value) and then you set the property using builtin functions from your service or script. I am not sure about infolabels to be honest...I think they have a list of possibilities (you can't probably create new ones) and they will probably be re-set by kodi itself at some point
I've already created a new custom xml. It's working fine beside the update of the label. As far as I know $INFO use just predetermined items.
(2015-08-27, 16:44)el_Paraguayo Wrote: [ -> ]I'll happily defer to enen92's jusgment as they're more experienced than I am.

My personal experience is using an infolabel (using Skin.String(stringname)) worked perfectly to display one custom string on the skin I was using. It's very easy to set the string by using Skin.SetString(stringname, value).
OK, then where I need to declare the string name?As a $VAR in variables.xml? And how do you use Skin.SetString on label?

<label>$INFO[Skin.String(tempo)]</label>

doesn't works.

I'll be very grateful if you drop here a real example. Thanks.
A little step forward using an empty $VAR declared on variables.xml :

Code:
<variable name="tempo">
        <value></value>
</variable>

and then on my custom1.xml

Code:
<label>$VAR[tempo,3]</label>

In that way I can use number even if reserved, but again to update it I need to reload the skin. It's me or is an hard thing to archive?

Edit: temporary solved forcing a skin reload on my .py before open the window with the updated string. Dirty hack, I know, but is working.
Use xbmc.executebuiltin("skin.setstring(stringname, value)"). No need to reload the skin.
(2015-08-28, 00:38)el_Paraguayo Wrote: [ -> ]Use xbmc.executebuiltin("skin.setstring(stringname, value)"). No need to reload the skin.
I know I'm NOT an idiot and is obvious there are missing bits on the wiki.
Still I'm unable to make it works in that way (the dirty hack works).
My py:
Code:
import xbmc, imp

def main():
    monitor = xbmc.Monitor()
    if monitor.waitForAbort(10):
        return

    while True:
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        if monitor.waitForAbort(10):
            break
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(10):
            break
    def getVarFromFile(filename):
        f = open(filename)
        global data
        data = imp.load_source('data', '', f)
        f.close()
    getVarFromFile('/home/effe/var.txt')
    tempo2 = data.wait_time
    xbmc.executebuiltin("skin.setstring(tempo,tempo2)")
    xbmc.executebuiltin('XBMC.ActivateWindow(1180)')
        if monitor.waitForAbort(10):
            break
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(10):
            break

if __name__ == '__main__':
    main()
It simply take the var from a txt and should use it on setstring.

And the relevant part of my xml:
Code:
<control type="label">
<top>310</top>
<right>350</right>
<align>center</align>
<font>SuperLargeBold</font>
<textcolor>Highlight</textcolor>
<label>$INFO[skin.String(tempo)]</label>
</control>

The variable tempo is on variable.xml too.
With this configuration the value of my var is set to tempo2 (literally). If I write down the value of the variable obviously works but no update.
Last try then I'll back to my old, simple and working web page. I can't waste a day for a simple setting.

Thanks anyway for the help, I really appreciate it!
Ok.I'm going to try this later (likely this weekend as I'm traveling at the moment) as this should work and I'd hate to think that I've given some advice that doesn't work (and wasted your time in the process).
Thanks, but again the wiki need to be updated at least with some example. The options available are not so immediate to use.
Pages: 1 2