How to write a RCI request?

I have Digi X4 Ethernet gateway(wifi) with smartplug and sensor. How can I write a RCI request for “depends on the number of the sensor’s brightness, turn on/off the smartplug”. I can manually turn on the smartplug using “”, but I need it to be automatically.

Or, if there is a way to get it happen by java? Not using the Digi cloud and ESP?

Thank you for your answer.

The following might be helpful:

http://www.digi.com/wiki/developer/index.php/Rci

This is using RCI inside the cloud to sent request. Is there anyway that java can directly get Json from the device?