Sunday, March 2, 2014

Control4 - Set Lights with Python

I wrote a script to implement the following functions for lighting:
  • Set Dimmer Level
  • Ramp to Level with Duration
  • Get Light Level
  • Get Light State
It's a work in progress. I thought I'd upload the code that I have so far. Ideally, I'd like to make a Python module. My apologies in advance for any formatting errors.

Usage:

In a previous post, I showed how to get the device IDs. If you run that script, you should obtain output similar to this:

Output:

...
276, Kitchen Main Cans
264, Family Ceiling Cans Dim.
...


Functions:

Below are some example uses for the functions.
setLevel(276, 1)  # Sets Kitchen Main Cans
setLevel(264, 50) # Sets Family Ceiling lights to 50% 
time.sleep(3)     # Wait 3 seconds
rampToLevel(264, 0, 3000) # Ramp ceiling lights to 0% over 3 seconds
print getLevel(264)       # Outputs light intensity

print getLightState(276)  # Outputs light state

An important thing to add is the use of the getLevel and getLightState functions. The getLevel function only works with dimmer switches. In the future. I'll add error checking to make it work for normal switches too. To get information about toggle switches use the getLightState function. It will either return 1 or 0 for on and off, respectively. getLightState works for dimmers, too.

When I find some time, I'll implement arguments so the scripts can be called with IDs and values in a console.

Script:

The script is on my git repo, lightsControl.py:

2 comments:

  1. HI sagar

    Please contact me on prakash@dtiautomation.com

    I would like to discuss some ideas.

    ReplyDelete
  2. interesting challenge for a weblog. i've been searching the net for fun and got here re your internet site. gorgeous pronounce. thank you a ton for sharing your knowledge! it is exciting to look that some people but complement an attempt into coping with their websites. i'll be actual to check verify inside the works anew particular quickly. control4

    ReplyDelete