Jump to content
C4 Forums | Control4

c4 sdk api question


mlls

Recommended Posts

Hello everyone, I am new in c4 driver developing. Now I am working on smart outlet c4 driver, outlet communicates with c4 controller via zigbee. I write some code and it works, I can switch relay on/off.

 

I have a few questions about ReceivedFromProxy(idBinding, strCommands, tParams) function:

 

When I press on/off button on my driver I am always getting SET_LEVEL as strCommand argument and not ON/OFF as I expect ? Why this happens ?

 

When I press toggle button I am getting TOGGLE as strCommand which  is ok.

 

Also, i would like to understand the mechanism what generates these commands(ON,OFF,TOGGLE,SET_LEVEL.....) ?

 

Thanks in advance

Link to comment
Share on other sites


Any kind of dimmer / switch driver (i.e. driver that connects to a 'light-type' proxy) can receive SET_LEVEL commands , as well as ON/OFF/TOGGLE commands.

 

If you've set the <can_dim> capability of your driver to false, you should only receive SET_LEVEL commands with values of 0 and 100, although this is enforced on the client side (Navigator or other UI), so your driver should just assume if you're not dimming that any SET_LEVEL of > 0 is 'on', any SET_LEVEL of 0 is off.

 

i.e.:

 

function ReceivedFromProxy(idBinding, strCommand, tParams)

  tParams = tParams or {}

  if (strCommand == "SET_LEVEL") then

    local level = tonumber(tParams["LEVEL"]) or 0

    if (level > 0) then

      doOn()

    else

      doOff()

  end

end

 

You can probably ignore RAMP_TO_LEVEL commands, if you're a switch.

 

RyanE

Link to comment
Share on other sites

Thanks RyanE, I handle these commands as you say and it works fine now.

As I say, I am developing a driver for smart outlet which periodically sends average power consumption report over zigbee,

i can receive this report message but I want to display this value on my driver or in property tag ?

Is it possible?  I am modifying light driver

Link to comment
Share on other sites

The only way it's possible is to display it in a DriverWorks property, i.e. you can't modify the Properties page of the light proxy, only the 'list-style' Properties in a DriverWorks driver.

 

Properties are created in the XML portion of the .c4i, and can be readonly if you want to just display values.

 

RyanE

Link to comment
Share on other sites

So, if I understand you correctly,

it is possible to add my own property in XML portion of .c4i (light driver file)  and update it with new average power report data via C4:updateProperty() function? 

Link to comment
Share on other sites

Yes you can.

 

Your XML should look something like this

      <property>        <name>Average Power Report</name>        <type>STRING</type>        <default>        </default>        <readonly>true</readonly>      </property>

Your code to update the property should look something like this

C4:UpdateProperty("Average Power Report", averagePowerVar .. " amps")

i would also recommend you add that power report to a variable.  This will allow you to utilise the value in Control4 programming.

 

 

You can create variables like this

C4:AddVariable("AVERAGE_POWER", 0, "NUMBER")

You can update a variable by doing this

C4:SetVariable("AVERAGE_POWER", averagePowerVar )

Hope this helps.

Link to comment
Share on other sites

I have one more question,

When I switch to List View(in Composer Pro / System design) my driver never change its state. It is a light type driver and it works fine now, but I would like to see state change in list view

when device is turned on/off. Which function causes these indication ? I try C4:SendToProxy() - no result

 

thanks

Link to comment
Share on other sites

you are probably not sending the correct notification

 

Code for on notification

C4:SendToProxy(idBinding,"LIGHT_LEVEL_CHANGED",100,"NOTIFY")

Code for off notification

C4:SendToProxy(idBinding,"LIGHT_LEVEL_CHANGED",0,"NOTIFY")
Link to comment
Share on other sites

Now my driver works well, but as it is actually a light type driver adopted to work as smart outlet driver. It displays a smart outlet properties(active power, reactive power, power factor, total consumption, measurement period...) periodically but

these properties are visible only as list style properties and not in device control view.   

I realize that it is not possible to display power consumption data in device control GUI of light driver. 

 

So, can you give me some advice what to do now? I am developing a smart outlet driver and I need to display all these properties in device control view which user actually see. 

 

Is there a proxy developed for smart outlet device? (I didn't found nothing similar in Composer Pro)

Is it possible to make my own, customized GUI which is suitable for smart outlet device?

 

Best Regards

Link to comment
Share on other sites

So, can you give me some advice what to do now? I am developing a smart outlet driver and I need to display all these properties in device control view which user actually see. 

 

Is there a proxy developed for smart outlet device? (I didn't found nothing similar in Composer Pro)

Is it possible to make my own, customized GUI which is suitable for smart outlet device?

 

One of the limitations of Control4 is that you cannot modify existing proxies.  The lighting proxy (nor any other proxy) has any fields or places for energy usage information.  If you want to showcase your energy usage you can do so by creating a custom 4store application.  Note though this will only be visible on any flash based navigator (onscreen navigator, Control4 touchscreens & MyHome PC).  It will not work on ios or android platforms.

 

www.4store.com

Link to comment
Share on other sites

I am a little bit confused now. In order to develop new driver for smart outlet device I will need 4store account?

Which proxy should I use for that kind device?

Is there some kind of generic proxy for power metering devices in Composer Pro?

 

Here is a short description of smart outlet:

- it communicates with C4 controller over zigbee

- it measure power consumption and sends it periodically to C4 home controller

- it has built in relay which turning on/off load (if the power consumption is to high for example)

Link to comment
Share on other sites

Not to develop the driver.

 

He is giving you an option to show the power usage on a C4 screen. You would need to be create a C4 store application that would show the information to your customer. It cannot be shown at this time through the standard screens.

 

Good luck

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.