KodiRemote for Micasaverde Vera Home Automation – Part 2

KodiRemote for Micasaverde Vera Home Automation – Part 2

In part one here I discussed the installation and setup for the newer project called KodiRemote for integrating Kodi Media Center and the Micasaverde Vera Z-wave controller. This is based on the older project XBMCState.

In part two I will look at creating some scenes in Vera and using the playback status updates sent from Kodi to Vera to automate some lighting and curtain control. In Vera I created three new scenes.

  • Kodi – Close Curtains
  • Kodi – Lounge Dim 25%
  • Kodi – Lounge On

image

Scene – “Kodi – Lounge Dim 25%”

On the Triggers tab of this scene I created four new triggers. I named them as follows:

  • Kodi – Video Resumed
  • Kodi – Video Starting
  • Kodi – Music Starting
  • Kodi – Music Resuming

image

So if any of these triggers are detected the lights will be dimmed down to 25%.

If we look at one of the triggers we can see in more detail how it works. Under the “Device” field you select the KodiRemote device instance you would like to configure. As these scenes are for the Kodi HTPC in my Living Room I selected the #113 “Kodi01 – KodiRemote” device from the device list.

In the “What type of event is the trigger?” Select “Player State Changes”.

In the “Name for this trigger” field give the trigger a suitable name, in this example I called it “Kodi – Video Resumed”.

In the “Player State” field you select the playback state of Kodi, in this example I selected “Video is resumed”.

This means that when Video is resumed on the Kodi Media Center PC, this Vera scene with this trigger will then perform some action.

 

image

Here is another screen shot of the “Kodi – Music Starting” trigger.

image

So once you have created all your triggers we then need to complete the scene creation by adding our actions that Vera will carry out.

In my case I have some LUUP code that should be run when either one of the four triggers are detected.

image

I have also created a Virtual Switch in Vera using the Virtual Switch plug-in from the MiOS Marketplace here.

I named the Virtual Switch “Link Kodi to Devices?”

image

If the Virtual Switch is turned ON then Kodi Media Center is linked to the three scenes.

  • Kodi – Close Curtains
  • Kodi – Lounge Dim 25%
  • Kodi – Lounge On

If the Virtual Switch is turned OFF then Kodi Media Center is not linked to the three scenes and the automation of dimming or brightening the living room lights or automatically closing the curtains, will not happen.

E.G. By using a Virtual Switch such as this one, you can turn on and off the integration between Kodi and Vera which is very useful, as you might not want it to happen all the time.

    image

    In the name field enter a suitable name for the Virtual Switch.

    image

    In the Text1 field I entered the text “Linked = ON”.

    You also need to make a note of the Virtual Switches device ID number in Vera? As we will use this in our scenes LUUP code.

    image

    Here is the Luup code from my “Kodi – Lounge Dim 25%” scene.

    1: Link_XBMC_to_devices = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1″,”Status”,92)

    2: if(Link_XBMC_to_devices=="1")then

    3: luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="5"},0)

    4: end

    Basically it does the following:

    1. Checks first to get the current status of the Virtual Switch with the device ID number 92. Is it on or off? 1 is ON 0 is OFF.

    2. If that Virtual Switch device is currently turned ON then..

    3. Run another scene to dim the lights 25%, in this case it runs my scene number 5 which is just a regular scene that dims the lights to 25%.

    4. If the Virtual Switch was turned OFF then it would just end and not do anything.

    Here is the “Kodi – Lounge On” scene triggers.
    • Kodi – Video Paused
    • Kodi – Music Stopped
    • Kodi – Music Paused
    • Kodi – Video Ended
    • Kodi – Video Stopped

    image

    So if any of these triggers are detected then the LUUP code in the “Kodi Lounge On” scene will be run.

    image

    1: Link_XBMC_to_devices = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",92)

    2: if(Link_XBMC_to_devices=="1")then
    
    3: luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="1"},0)

    4: end

    1. Checks first to get the current status of the Virtual Switch with the device ID number 92. Is it on or off? 1 is ON 0 is OFF.

    2. If that Virtual Switch device is currently turned ON then..

    3. Run another scene to turn on the Lounge lights, in this case it runs my scene number 1 which is just a regular scene that turns on the lounge lights to 100%.

    4. If the Virtual Switch was turned OFF then it would just end and not do anything.

    So with these two scenes and the triggers that have been added to each and if the Virtual Switch is turned ON, then for example if I start playback of a movie in Kodi Media Center, the lounge lights will automatically dim down to 25%. And if I then pause or stop video playback the lounge lights will automatically brighten up to 100%.

    Obviously we only want this to take place when its actually night time, this is where the Day or Night plug-in for Vera we installed in Part one comes in to play.

    In the KodiRemote (Micasaverde Kodi Event) add-on for Kodi in the settings there, we need to specify that the various playback states are set to “Night”.

    image

    [image%255B152%255D.png]

    And finally I have a third scene in Vera for my Z-wave curtain rail.

    I only have one trigger in this scene and that is “Kodi – Video Starting”.

    Basically this scene closes the curtains if it is currently night? and if the curtains are still open? and if I start to play video in Kodi Media Center, then the curtains will be automatically closed.

    image

    Here is the LUUP code for the “Kodi – Close Curtains” scene.

    image

    1: Link_XBMC_to_devices = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",92)

    2: if(Link_XBMC_to_devices=="0")then return false end

    3: are_curtains_open = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",107)

    4: if(are_curtains_open=="100")then

    5:      luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="138"},0)

    6: end

    1. Checks first to get the current status of the Virtual Switch with the device ID number 92. Is it on or off? 1 is ON 0 is OFF.

    2. If that Virtual Switch device is currently turned OFF then just end and do nothing.

    3. Checks to see if the curtains are currently opened or not? Device ID #107 is the device ID number in Vera for my Fibaro Blind Controller module.

    4. If the curtains are open (which is 100) then..

    5. Run another scene to close the curtains, in this case it runs my scene number 138, which is just a regular scene that closes the curtains.

    6. End.

    These are the three regular scenes in Vera, that the Kodi automation scenes run when all the conditions are met. And these scenes ID numbers are the ones referenced in the various LUUP code above etc.

    image

    Summary

    Well I hope this all makes sense as its quite hard to explain. But with the KodiRemote add-ons for Kodi Media Center and Vera, you can integrate the two together and have Vera perform actions based on Kodi’s current media playback status. I am sure there are various ways of setting up your scenes in Vera, I’m for example not using PLEG and tend to just add the LUUP code myself. But as long as you know how to create the triggers with the KodiRemote devices, then you can go about creating the actions for your scenes as you normally would.

    Here is a short video clip showing “Video Starting” playback in Kodi. I then pause and resume the video a few times. The video quality isn’t great, but you get the idea if you watch it.

     

    Share

    Leave a Reply

    Your email address will not be published. Required fields are marked *