Sunday, March 30, 2014

Control4 - Uncovering SOAP Commands

I've currently been using the Programming interface in ComposerHE to figure out SOAP commands. It has been good for lighting, but ideally I want to do everything the MyHome iOS/Android app can do such as controlling the volume, changing channels, thermostat, etc.

Luckily, there is a method to capture the SOAP commands sent from the MyHome app. So far, I've only tried this on Android

Step 1 - Packet Capture:

Requirements:

Steps:

  1. Install tPacketCapture and Wireshark
  2. Start Capturing
  3. Open MyHome Application
  4. Perform functions that you would like to capture
  5. Stop Capturing
  6. Upload pcap file to PC via USB/Email

Step 2 - Filtering the data

  1. Open the pcap file in Wireshark
  2. Use the following filter: frame matches "(?i)sendtodevice"

You'll have to read through the filtered message to find what's relevant to your command. I wanted to determine the volume up, volume down, info, and cancel buttons. The following was captured for volume down:


SOAP Command captured from Wireshark:

<c4soap name="SendToDeviceAsync" async="1" seq="866">
<param name="iddevice" type="number">10</param>
<param name="data" type="string">
<devicecommand>
<command>PULSE_VOL_DOWN</command>
<params></params>
</devicecommand>
</param>
</c4soap>

The iddevice number is 10. For my Control4 system 10 is the family room. In an earlier post I showed how to list Director items by ID. I modified the script to list rooms. The script is called getControl4Rooms.py. The modification was really trivial, but I uploaded the script in case there's people that aren't familiar with python.

Step 3 - Sending SOAP Command with Python

If you clone my git repo there will be a script called TestSendSOAP.py. You can insert the message that you captured in Wireshark to test it out.

If anything is unclear, please let me know. This is far from complete. I'm not sure if some commands only work if the system is in a specific state. I'm currently working on encapsulating Control4 items in a python module. Lighting is currently implemented and will be a future post, but the code is on git.

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:

Control4 - List of Director Items by ID

I will be following up with a tutorial to set light intensity. I'll be doing something similar to RyanE, but in Python.


The posted script will list all Control4 devices with names and IDs. The IDs will be important for a future post to manually set/get light intensity.

Requirements:

- IP of Control4 Director (can be found using Control4 app or Composer)
BeautifulSoup module
- Sockets (built-in python module)

Script:

The script can be found on git. The file is called getControl4Items.py:
https://github.com/sapatel91/pyControl4/tree/master/Scripts

Sources:

https://code.google.com/p/control4toolkit/wiki/Protocols
http://untestedhacks.com/2012/command-line-light-control/

If you have questions or find any bugs, feel free to ask.