Implementing Clipsal Interface using Generic Serial Device
Clipsal Switches are used for controlling lights, curtains and temperature controls. They can be connected to the Serial Port and can be controlled via a PC. In the following tutorial, we will add Clipsal Switches using Generic Serial Device and implement Lights and Shutter control through the Linux MCE.
Steps to Add Clipsal Interface
- Create a Device Template 'Clipsal Interface' in Device Category: "Interfaces - Lighting Interface #81"
- Check Implements DCE - Command Line - Generic Serial Device
- In the packages, add "Pluto Generic Serial Device"
- In Device Data, add "#37 COM Port on PC(string)"
- In Commands Section, create and select "Ruby Internal Commands"
This Clipsal Interface will act as a parent device to all the child devices (eg. Lights, Curtains) that are controlled via the serial port to which Clipsal Switch is connected. Now create a device from the device template Clipsal Interface.
Ruby Commands for Lighting
The Clipsal Interface will have all the lighting and curtains as its child devices. The commands from child devices will be directed to Clipsal Interface and this interface will send these commands to the serial port to which clipsal switch is connected.
For the Clipsal Interface, following ruby commands will be implemented:
- #Private Method Listing #373
- #Process IDLE #351
- #Process Incoming Data #350
- #Process Initialize #355
- #Process Receive Command For Child #384
- #Process Release #356
The most important of this command is #Process Receive Command For Child #384, which is process incoming data from child devices. When we receive any command from child device such as Light or Shutter, the ruby commands in this section are invoked and we need to send relevant commands to the serial port to carry out the action on lights or shutters.
To edit the Ruby Commands for #384 Process Receive Command For Child, Edit the Clipsal Interface and click on 'Edit Ruby Codes' besides Implements DCE on the top.
group_no = device_.childdevices_[cmd.devidto_].devdata_ if cmd.id_ == 192 serial_on = "\\05380079"+group_no+"\r" log( "Sending " + serial_on + " \n" ) sendCmd(serial_on) end if cmd.id_ == 193 serial_off = "\\05380001"+group_no+"\r" log( "Sending " + serial_off + " \n" ) sendCmd(serial_off) end log("We got cmd : " + cmd.id.to_s) if cmd.id_ == 184 dim_level = cmd.params_ serial_dim = "\\05380002"+group_no+""+dim_level+"\r" log( "Sending " + serial_dim + " \n") sendCmd(serial_dim) end
In the ruby code, what is happening is when we receive a command from any of the child devices (such as lights, curtains), we also get its port number. Then, using that port number we make a binary string to be sent to the serial port. That binary string is sent to the serial port defined in the Clipsal Interface Device Data.
eg. Command # 192 is the command to switch light ON. The binary string to switch a light ON to be sent to the serial port is:
\05380079 + Port Number + \r
So, we receive the port number from child device (group_no), concatenate it in the binary string and send it to the serial port defined in the Clipsal Interface.