Be a part of CinemaVision today! Once registered and logged in, you will have access to public chat and your own private messenger, you can view and contribute guides, collaborate on the forums, review downloads, give reputation to your fellow members, contribute content and so much more. Registering is quick and completely free, so what are you waiting for? Sign In Sign Up
Here is a more advanced way to dim the lights in your home theater room using OpenHAB and CinemaVision using the action files. With this setup you can control how quick or slow your lights will dim and to what percentage of brightness with a chosen value between 0 - 100. This requires edits to the items file and the rules file within OpenHAB.
The items file is a simple edit. Simply add the following line:
String HT_Dimmer "HT Dimmer Data [%s]"
The rules file we will be adding a new rule to handle the JSON data we will send to it in the action file. Place this rule anywhere you would like within the file. I have placed instructions and explanations within the comments of the rule for those wanting to understand what's occurring.
/* CinemaVision Customizable Dimmer */
rule "Home Theater Dimmer"
when
/* Trigger the rule when HT_Dimmer receives the information via JSON */
Item HT_Dimmer received command
then
/* Set current state of your dimmer in the home theater. This can be a single dimmer attached to one light you have in the room or a group dimmer like in this example that controls all the lights in the room */
var Number curstate = 0
if(Light_LivRoom_AllLights_Dim.state instanceof PercentType) curstate = Light_LivRoom_AllLights_Dim.state as PercentType
/* This will take the JSON we send from the action file within CinemaVision and parse out our configuration parameters */
var String json = (HT_Dimmer.state as StringType).toString
/* Example JSON being sent {"_type": "dimDown", "DimPercent": 70, "increments": 5, "speed": 500} */
var String type = transform("JSONPATH", "$._type", json)
/* Place an entry to the log to verify we are receiving a value for the type parameter being sent */
logInfo("HT Rule", "JSON Information " + type)
/* If the type sent via JSON is dimDown execute this block of code */
if (type == "dimDown") {
/* Place an entry to the log to verify we started the dimDown Loop
logInfo("HT Rule", "Starting dimDown Loop")
/* set the variable dimto to the percentage we want to dim down to and output to the log to make sure the information was in fact saved. Using example we should have this set to 70. */
var dimto = new Integer(transform("JSONPATH", "$.DimPercent", json))
logInfo("HT Rule", "dimto variable = " + dimto)
/* set the variable inc to the percentage we want dim each time the loop runs. and output to the log to make sure the information was in fact saved. Using example we should have this set to 5. */
var inc = new Integer(transform("JSONPATH", "$.increments", json))
logInfo("HT Rule", "inc variable = " + inc)
/* set the variable speed to the amount of time in milliseconds to wait before running the while statement again and output to the log to make sure the information was in fact saved. Using example we should have this set to 500 which is half a second. */
var speed = new Integer(transform("JSONPATH", "$.speed", json))
logInfo("HT Rule", "speed variable = " + speed)
/* Output to the log our current dimmer state to make sure this variable is set as well */
logInfo("HT Rule", "curstate = " + curstate)
while(curstate > dimto)
{
/* Take the current state of the dimmer and subtract are percentage increments */
curstate=curstate - inc
/* Send the new current state to our dimmer */
sendCommand(Light_LivRoom_AllLights_Dim, curstate)
/* Wait the time we choose in milliseconds before running the loop again */
Thread::sleep(speed)
}
}
/* This is the same as the above code block only this time we'll be increasing the lights. */
if (type == "dimUp") {
logInfo("HT Rule", "Starting dimUp Loop")
var dimto = new Integer(transform("JSONPATH", "$.DimDownPercent", json))
logInfo("HT Rule", "dimto variable = " + dimto)
var inc = new Integer(transform("JSONPATH", "$.increments", json))
logInfo("HT Rule", "inc variable = " + inc)
var speed = new Integer(transform("JSONPATH", "$.speed", json))
logInfo("HT Rule", "speed variable = " + speed)
logInfo("HT Rule", "curstate = " + curstate)
while(curstate > dimto)
{
curstate=curstate - inc
sendCommand(Light_LivRoom_AllLights_Dim, curstate)
Thread::sleep(speed)
}
}
/* Set the HT_Dimmer state to the string done and output to logfile */
logInfo("HT Rule", "Successful execution of Home Theater Dimmer rule!")
postUpdate(HT_Dimmer,"Done")
end
**NOTE: I have found that if you are using the OpenHAB Designer in Ubuntu, the transform triggers will underline in red saying this is not correct. However this is not true and the rule will work just fine. It seems this occurs with the designer sometimes and its being looked at. Also if you do not want to flood your logfile you can remove the logInfo lines from the code. I placed these here during development to ensure everything was being passed along correctly and left in to help any troubleshoot any issues you may have.
The last bit we need to do is create our action files. For me I have 4 text files labeled where I have them triggering in my sequence. Example, I have a text file called theater_lights_triva.txt which triggers before my triva slides. I've found it easier using this naming convention for easy of updating. Here is how you would format your action file in order to properly send over the JSON information. Please note that JSON is CaSe SeNsItIvE.
http://INSERT_OH_IP:INSERT_OH_PORT/rest/items/HT_Dimmer - This is the REST API string of the Dimmer we created in the items file. Replace the red text with your OpenHAB servers IP and Port
{"_type": "dimDown", "DimPercent": 70, "increments": 5, "speed": 500} - This is the JSON String that gets parsed by our rule within OpenHAB. See below breakdown
_type = This value can be either dimDown or dimUp depending on if you want to dim your lights up or down within the sequence. DimPercent = This is going to be the percentage of the dimmer we want to be at when the rule triggers increments = This is the percentage value you would like to dim by speed = This is how long to wait in milliseconds before dropping by the next increment.
** NOTE: If you have security enabled within OpenHAB you will need to add an additional line to your action file. The 2nd line in the action file will need to be the following: HEADERS: {"Authorization": "Basic=XXXXX"} - You can generate the Basic=XXXX by using the Postman plugin for Chrome. Using Postman you can place in your user credentials and the header line will generate for you. You can than place this within the header line and you will than be able to send your JSON request lines with authorization turned on. Here is an example of how the action file can look
http://INSERT_OH_IP:INSERT_OH_PORT/rest/items/HT_Dimmer - This is the REST API string of the Dimmer we created in the items file. Replace the red text with your OpenHAB servers IP and Port
HEADERS: {"Authorization": "Basic=XXXXX"} - Authorization header for using with an OpenHAB server with security enabled.
{"_type": "dimDown", "DimPercent": 70, "increments": 5, "speed": 500} - This is the JSON String that gets parsed by our rule within OpenHAB. See below breakdown
This information is also explained in the rule comments but here it is again in a more compressed form. Save the file and place in your actions folder on your Kodi system where you have the CinemaVision folders. Then within the Sequence editor add the action. In the example above I placed this right before the trivia slides start. Once you place the action in, point it to your newly created .txt file. Save your sequence and run it, your lights should now react within the sequence.
Feel free to ask any questions or if you find anything that needs tweaked let me know!
Here is a more advanced way to dim the lights in your home theater room using OpenHAB and CinemaVision using the action files. With this setup you can control how quick or slow your lights will dim and to what percentage of brightness with a chosen value between 0 - 100. This requires edits to the items file and the rules file within OpenHAB.
The items file is a simple edit. Simply add the following line:
The rules file we will be adding a new rule to handle the JSON data we will send to it in the action file. Place this rule anywhere you would like within the file. I have placed instructions and explanations within the comments of the rule for those wanting to understand what's occurring.
**NOTE: I have found that if you are using the OpenHAB Designer in Ubuntu, the transform triggers will underline in red saying this is not correct. However this is not true and the rule will work just fine. It seems this occurs with the designer sometimes and its being looked at. Also if you do not want to flood your logfile you can remove the logInfo lines from the code. I placed these here during development to ensure everything was being passed along correctly and left in to help any troubleshoot any issues you may have.
The last bit we need to do is create our action files. For me I have 4 text files labeled where I have them triggering in my sequence. Example, I have a text file called theater_lights_triva.txt which triggers before my triva slides. I've found it easier using this naming convention for easy of updating. Here is how you would format your action file in order to properly send over the JSON information. Please note that JSON is CaSe SeNsItIvE.
_type = This value can be either dimDown or dimUp depending on if you want to dim your lights up or down within the sequence.
DimPercent = This is going to be the percentage of the dimmer we want to be at when the rule triggers
increments = This is the percentage value you would like to dim by
speed = This is how long to wait in milliseconds before dropping by the next increment.
** NOTE: If you have security enabled within OpenHAB you will need to add an additional line to your action file. The 2nd line in the action file will need to be the following:
HEADERS: {"Authorization": "Basic=XXXXX"} - You can generate the Basic=XXXX by using the Postman plugin for Chrome. Using Postman you can place in your user credentials and the header line will generate for you. You can than place this within the header line and you will than be able to send your JSON request lines with authorization turned on. Here is an example of how the action file can look
This information is also explained in the rule comments but here it is again in a more compressed form. Save the file and place in your actions folder on your Kodi system where you have the CinemaVision folders. Then within the Sequence editor add the action. In the example above I placed this right before the trivia slides start. Once you place the action in, point it to your newly created .txt file. Save your sequence and run it, your lights should now react within the sequence.
Feel free to ask any questions or if you find anything that needs tweaked let me know!
Share this post
Link to post
Share on other sites