Announcement

Collapse
No announcement yet.

How to trigger HS Events from Kodi/XBMC interface

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to trigger HS Events from Kodi/XBMC interface

    Here is a quick example showing how to add a button in the XBMC skin that trigger an event in HS when clicked.

    step 1: Create a simple python script with these two lines:
    Code:
    import xbmc
    
    xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "JSONRPC.NotifyAll", "params": {"sender": "SimpleScript", "message": "Toggle Lights"}, "id": 1 }')
    the parameters sender and message will be checked by HomeSeer to know which event to trigger (see step 3)

    step 2: Modify the XBMC skin to add a button which, when clicked, will run the script.
    For example I have added a button for the Confluence skin by adding the following lines of code in VideoOSD.xml just before the subtitles button:
    Code:
                <control type="button" id="249">
                    <posx>-55</posx>
                    <posy>0</posy>
                    <width>55</width>
                    <height>55</height>
                    <label>13395</label>
                    <font>-</font>
                    <texturefocus>icon_favourites.png</texturefocus>
                    <texturenofocus>icon_favourites.png</texturenofocus>
                    <onleft>205</onleft>
                    <onright>250</onright>
                    <onup>1000</onup>
                    <ondown>1000</ondown>
                    <onclick>XBMC.RunScript(D:\SimpleScript.py)</onclick>
                </control>
    and here is how it shows in XBMC:
    Click image for larger version

Name:	screenshot000.jpg
Views:	1
Size:	53.1 KB
ID:	1205795

    step 3: Now we just need to tell HomeSeer to do something when it receives the notification from XBMC. We do so by creating an Event with a XBMC Trigger of type "Addon Trigger", and we set the parameter values for sender and message as in our script.
    Click image for larger version

Name:	xbmctrigger.jpg
Views:	2
Size:	49.1 KB
ID:	1205796

    et voila
    Last edited by spud; April 10, 2015, 10:11 AM.

    #2
    I have submitted a patch to the xbmc project to simplify this process.
    https://github.com/xbmc/xbmc/pull/3230
    The patch has been accepted and will be in the next version of xbmc (Gotham 13.0)

    So, in this version only step 2 and 3 will be needed, and in step 2 the change will become:
    Code:
                <control type="button" id="249">
                    <posx>-55</posx>
                    <posy>0</posy>
                    <width>55</width>
                    <height>55</height>
                    <label>13395</label>
                    <font>-</font>
                    <texturefocus>icon_favourites.png</texturefocus>
                    <texturenofocus>icon_favourites.png</texturenofocus>
                    <onleft>205</onleft>
                    <onright>250</onright>
                    <onup>1000</onup>
                    <ondown>1000</ondown>
                    <onclick>XBMC.NotifyAll(SimpleScript, Toggle Lights)</onclick>
                </control>

    Comment


      #3
      This is really really cool, I look forward to being able to give this a go when i get some time.

      I am curious, in your work around XBMC do you know if there is any way to assign a script like this, or a notify statement to a button on a physical remote. Currently my system has me using remotes with RFXCOM, which then triggers a JSON URL call to move left, right, up, down etc. The reason i do it this way is because I have two buttons on the remote I want to use to control the lights, and another few buttons which select the appropiate input (e.g. pressing a computer button on the remote turns on the TV, selects the HDMI1 input, and lets me control the XBMC player). It would be far easier if i just got a MCE style remote with XBMC and mapped some buttons on the remote to XBMC commands for notifyall, so that you press the button on the remote, which then sends the XBMC notifyall command to say toggle the lights, or turn off the TV or so-on, and the HA responds accordingly.
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment


        #4
        Originally posted by travisdh View Post
        This is really really cool, I look forward to being able to give this a go when i get some time.

        I am curious, in your work around XBMC do you know if there is any way to assign a script like this, or a notify statement to a button on a physical remote. Currently my system has me using remotes with RFXCOM, which then triggers a JSON URL call to move left, right, up, down etc. The reason i do it this way is because I have two buttons on the remote I want to use to control the lights, and another few buttons which select the appropiate input (e.g. pressing a computer button on the remote turns on the TV, selects the HDMI1 input, and lets me control the XBMC player). It would be far easier if i just got a MCE style remote with XBMC and mapped some buttons on the remote to XBMC commands for notifyall, so that you press the button on the remote, which then sends the XBMC notifyall command to say toggle the lights, or turn off the TV or so-on, and the HA responds accordingly.
        I think what you are looking for is the keymap files:
        http://wiki.xbmc.org/index.php?title=Keyboard.xml

        you can customize these files the same way you can customize a skin. So for example to let the blue button of your remote toggle lights you would use this code:

        Code:
        <keymap>
          <global>
            <remote>
              <blue>XBMC.NotifyAll(SimpleScript, Toggle Lights)</blue>
            </remote>
          </global>
        </keymap>
        Note: this code will work in xbmc 13 (Gotham) when my fix will be merged in the offical xbmc code. For version 12 (Frodo) you still need the intermediary python script.

        Comment


          #5
          Last night I had this set up and was able to successfully turn my lights on several times from my remote, problem was I wasn't getting a "toggle" it would just turn it on only, based on my event setup.

          Today I switched my event set up to use a toggle function that I found in HSTouch. Now if I run the event manually it toggles the lights on and off just as I wanted it to. However no for some reason I can't get Kodi (XBMC) to actually trigger the function.

          I got tired of working on this in my living room with the TV so I configured this to go from my "Desktop - Kodi" send the simple message when I press the "a" key on my keyboard to trigger the event. However I can't seem to get the event to trigger.


          logs from kodi just pressing the a key a bunch of times:
          18:24:16 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:18 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:18 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:18 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:18 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:18 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:18 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:18 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:18 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:18 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
          18:24:18 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
          18:24:18 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
          18:24:18 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
          18:24:19 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0


          There are no log enteries in homeseer log at that time. However I know the HS Addon and KODI are communicating I can control KODI from HS.


          Homeseer event is set up like this;
          IF XBMC: Addon Trigger
          Instance = Desktop KODI
          Sender = Simple Script
          Message = Toggle Lights

          Then Simulate release on Element Family Room:Family Room Light Toggle on client(s) All Clients

          Again if I run the event manually the lights toggle on and off perfectly.

          Thanks for any help.

          Comment


            #6
            Originally posted by maui917 View Post
            Last night I had this set up and was able to successfully turn my lights on several times from my remote, problem was I wasn't getting a "toggle" it would just turn it on only, based on my event setup.

            Today I switched my event set up to use a toggle function that I found in HSTouch. Now if I run the event manually it toggles the lights on and off just as I wanted it to. However no for some reason I can't get Kodi (XBMC) to actually trigger the function.

            I got tired of working on this in my living room with the TV so I configured this to go from my "Desktop - Kodi" send the simple message when I press the "a" key on my keyboard to trigger the event. However I can't seem to get the event to trigger.


            logs from kodi just pressing the a key a bunch of times:
            18:24:16 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:17 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:17 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:17 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:17 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:18 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:18 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:18 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:18 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:18 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:18 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:18 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:18 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:18 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0
            18:24:18 T:8364 DEBUG: CApplication::OnKey: a (0xf041) pressed, action is XBMC.NotifyAll(SimpleScript, Toggle Lights)
            18:24:18 T:8364 DEBUG: CAnnouncementManager - Announcement: Toggle Lights from SimpleScript
            18:24:18 T:8364 DEBUG: GOT ANNOUNCEMENT, type: 512, from SimpleScript, message Toggle Lights
            18:24:19 T:8364 DEBUG: Keyboard: scancode: 0x1e, sym: 0x0061, unicode: 0x0061, modifier: 0x0


            There are no log enteries in homeseer log at that time. However I know the HS Addon and KODI are communicating I can control KODI from HS.


            Homeseer event is set up like this;
            IF XBMC: Addon Trigger
            Instance = Desktop KODI
            Sender = Simple Script
            Message = Toggle Lights

            Then Simulate release on Element Family Room:Family Room Light Toggle on client(s) All Clients

            Again if I run the event manually the lights toggle on and off perfectly.

            Thanks for any help.
            not sure if it is a typo in your post or a real error, but in your HS event Sender is set as "Simple Script" with a space whereas in the Kodi logs there is no spaces "SimpleScript"

            Comment


              #7
              HA! I checked spelling on Toggle Lights and Simple Script like three times before I posted this.

              Somehow I missed the space. That was the problem.

              Solved!!!

              Thanks

              Comment


                #8
                I love Linux :-) I try to follow your instruction, I'm on Kodi 5, I think I have found the file you have mentioned but after editing the VideoOSD.xml file it does not let me rewrite it. I'm login as root, what am I doing wrong?
                /usr/share/kodi/addons/skin.confluence/720p


                Thanks,
                Aldo

                Comment


                  #9
                  I missed one important details, I use Openelec and raspberry pi2

                  Comment


                    #10
                    Originally posted by aldo View Post
                    I love Linux :-) I try to follow your instruction, I'm on Kodi 5, I think I have found the file you have mentioned but after editing the VideoOSD.xml file it does not let me rewrite it. I'm login as root, what am I doing wrong?
                    /usr/share/kodi/addons/skin.confluence/720p


                    Thanks,
                    Aldo
                    I don't have any experience with openlec, but according to this link
                    http://forum.kodi.tv/showthread.php?tid=222841
                    (which is probably you asking, right?). you need to create a new skin.

                    Comment


                      #11
                      Hi Spud,
                      I was able to implement it using another skin, it is amazing. I have a small trouble figuring out how to write the event that if the light is on switch to off or vice versa. How would you write such event?

                      Thanks,
                      Aldo

                      Comment


                        #12
                        Originally posted by aldo View Post
                        Hi Spud,
                        I was able to implement it using another skin, it is amazing. I have a small trouble figuring out how to write the event that if the light is on switch to off or vice versa. How would you write such event?

                        Thanks,
                        Aldo
                        it depends on what kind of lights you are trying to control and what control are available, but I think the easiest would be to have 2 events with the same trigger but different conditions

                        IF XBMC Addon Trigger
                        AND IF Light is ON
                        THEN set light to OFF

                        IF XBMC Addon Trigger
                        AND IF Light is OFF
                        THEN set light to ON

                        Comment


                          #13
                          Thanks Spud, it worked great.

                          Aldo

                          Comment


                            #14
                            I wish not to hijack anything, but I suppose this is slightly relevant to the original topic.

                            With my Vera, I am able to install a KODI plugin (not vera plugin) that allows me to activate triggers, devices, and scenes from within kodi itself.

                            For example, when movie starts playing, lights dim automatically by triggering a vera scene.

                            This is all done through a simple kodi plugin gui, no need for xmls or any scripting.

                            Is this sort of plugin not going to be available for us to use with Homeseer?

                            I know this question isn't directly related to the info in this thread, but I though if anyone would know, spud would

                            Edit: Here's a list of things in kodi that can trigger an event on the vera:
                            Music started
                            Video Started
                            Music paused
                            Video paused
                            Music resumed
                            Video resumed
                            Music stopped
                            Video stopped
                            Music ended
                            Video ended
                            Home menu
                            Video menu
                            Music menu
                            Weather menu
                            Setting menu
                            Program menu
                            Picture Menu

                            As you can see, this could be VERY useful! Sure beats having to make extra xbmc buttons

                            Comment


                              #15
                              Originally posted by amp3d View Post
                              I wish not to hijack anything, but I suppose this is slightly relevant to the original topic.

                              With my Vera, I am able to install a KODI plugin (not vera plugin) that allows me to activate triggers, devices, and scenes from within kodi itself.

                              For example, when movie starts playing, lights dim automatically by triggering a vera scene.

                              This is all done through a simple kodi plugin gui, no need for xmls or any scripting.

                              Is this sort of plugin not going to be available for us to use with Homeseer?

                              I know this question isn't directly related to the info in this thread, but I though if anyone would know, spud would

                              Edit: Here's a list of things in kodi that can trigger an event on the vera:
                              Music started
                              Video Started
                              Music paused
                              Video paused
                              Music resumed
                              Video resumed
                              Music stopped
                              Video stopped
                              Music ended
                              Video ended
                              Home menu
                              Video menu
                              Music menu
                              Weather menu
                              Setting menu
                              Program menu
                              Picture Menu

                              As you can see, this could be VERY useful! Sure beats having to make extra xbmc buttons
                              As far as I know there is no Kodi Addon for Homeseer
                              However there is a number of these triggers you can do from HS3 using the plugin, like for example use the Status device to trigger an event when something starts playing.

                              Do you have a link for this vera addon? maybe we can hack it to make it work with HS.

                              Comment

                              Working...
                              X