C-Bus lighting device

Can anyone help me out, I’m having trouble searching through the forum and documentation to try and find out how to create a device and make it interact with my C-bus system. I have network device that controls my C-Bus lighting, and I’ve figured out the LUA code to switch the lights on and off, make them go to a percentage and to figure out to find out what status and level the light is at.

So I’m trying to create a device that functions just like a normal z-wave light, on/off/dim and polling it to get the status. Can anyone point me in the direction of some documentation?

I believe that there is a dedicated CBUS forum.
Best try whirlpool>gadgets>homeautomotion thread for details, IIRC someone posted the details there.

http://forums.whirlpool.net.au/forum-replies.cfm?t=1650689

I didn’t think the systems where compatible as CBUS is hardwired, but nothing nowadays would surprise me.

To create a plugin, you’ll have to take an existing plugin and go through it to see how it all comes together. There really is not a full set of documentation for plugin creation. Start by looking at the ping or wake on lan plugins found here:

code.mios.com

Also look here:

http://wiki.micasaverde.com/index.php/Luup_Plugins_ByHand
http://wiki.micasaverde.com/index.php/UI4_UI5_Migration
http://wiki.micasaverde.com/index.php/Luup_plugins:_Static_JSON_file
http://wiki.micasaverde.com/index.php/Luup_Somfy_Walkthrough

  • Garrett

It doesn’t look as though anybody has written a plugin for C-Bus so you would need to write your own. If you are comfortable working with Luup and XML it should be possible but it is not a five-minute task.

Your starting point would be to read: http://wiki.micasaverde.com/index.php/Luup_Plugins and follow all the links for additional detail.

If you want to see what it takes, have a look at: MiLightWU1. This is a plugin that controls WiFi LED lamps via UDP but behaves like a DimmableLight on Vera.

After a fair bit of trial and error I think I’ve got the hang of most of it, although having trouble sending the command. I think it’s something to do with the string I’m setting.

So basically I have the following code:

  local msg 
  local networknum = luup.variable_get("urn:dcineco-com:serviceId:CBUSLights","NetworkNum",15)
  local applicationnum = luup.variable_get("urn:dcineco-com:serviceId:CBUSLights","ApplicationNum",15)
  local groupnum = luup.variable_get("urn:dcineco-com:serviceId:CBUSLights","GroupNum",15)
  msg = tostring("ramp " .. networknum .. "/" .. applicationnum .. "/" .. groupnum .." 100% 0s")

  local IPaddr = luup.variable_get("urn:dcineco-com:serviceId:CBUSLights","IPaddr",15)
  local IPport = luup.variable_get("urn:dcineco-com:serviceId:CBUSLights","IPport",15)

  socket = require("socket")
  local tcp = socket.tcp()
  tcp:settimeout(3)
  tcp:connect(IPaddr, IPport)
  tcp:send(msg)
  tcp:close(socket)

Which doesn’t work… but if I replace tcp:send(msg) with tcp:send(“ramp 254/56/14 100% on”) which is all is included in the msg variable it doesn’t work. I know the msg is getting generated correctly, as I output to the log and it’s correct. I’m assuming it’s something about declaring it as a string or something?

Thanks in advance

Is there a significant difference between:

"100% 0s"

and

"100% on"

perhaps?

Super thanks for all the information, I’ve finally got it all working! Now have my dimmable and non-dimmable lights working perfectly, I have attached the devices in case anyone else is looking for them. I’m now working on a bit of code to poll the cbus cgate server to find out the current status of the device.

The telnet command that I’m trying to read in isn’t working though as the receive syntax appears to have changed or doesn’t work as listed. The receive command is listed as receive’*l’ for a single line and receive’*a’ for everything. I need a multi-line response. Below is the code I’m trying to run in the test box but it fails.

local ipaddr = “192.168.1.100”
local ipport = “20023”
local msg = “ramp 254/56/14 0% 0s”
local datamsg
local socket = require(“socket”)
local tcp = socket.tcp()
tcp:connect(ipaddr, ipport)
tcp:send(msg)
datamsg = tcp:receive’*a’
tcp:close(socket)
luup.log(datamsg)

I hope you have the time and patience to see this through because i have a couple of friends here in Tasmania that would love to to be able to control their cbus sytems and would ultimately love a full cbus plugin. They get very jealous of my $100 full colour android tablet remotes and $100 modules!!

Regards Simon

Hi Simon,

Getting there! A couple of tricky parts to get past still as I’m still a newbie to Vera myself, but the plan is to write a plugin eventually and include all the various C-Bus devices. Got Lights (dimmable and non-dimmable) and Fans so far. Other devices to be added when I get them in the house :slight_smile:

1 Like

Hi,

So I’ve created all the code for Lights and Dimmable Lights and now have the cubs system talking to the vera, but I seem to be having a trick with the non-dimmable function. I can’t seem to have a trigger against it as I don’t get an option for selecting the device on or off. The dimmable one works fine, so I’ve done something wrong!

Anyone have any ideas?

Thanks,
Pete

How are you progressing with the plugin @peteinau?

Managed to write it to work fine using a C-Gate server talking to the CNI, and have a bit of code running on the C-Gate server to make it update the vera when you actually use a button on the wall.

I’m not quite experienced enough to transform it to monitor the C-Gate server directly, or create a master/child device. But it’s definitely working pretty well for lights for me now :slight_smile:

OK… Here goes

I have written a plugin (I think it qualifies) to the CBUS system from scratch. I recently purchased a house which has some Cbus stuff in it, and replacing all of it would be silly, so I just made it play nice with my VERA and other zwave modules.

WARNING: I knew very little about LUA code before writing this, and even less about writing vera plugins with LUUP and UPnP. I consier this still an Alpha in terms of other people using it. I have tested it for maybe a couple of hours all-together. If that’s not bad enough I knew nothing about CBUS/CGATE until 5 days ago…

I am 100% sure there are better cleaner ways to do many of the implementation I have done here, and I am quite open to input and code suggestions. As allways, take the code, and do your own thing if you please, but please give me some credit, and if it’s for the benefit of my code, please share :wink:

Summary:
This is a master child device, it will create and manage the children automatically

What it needs(prerequisites):

[ul][li]CBUS[/li]
[li]CGATE[/li][/ul]

Configuration:
All Set up via configuration->advanced variables:

[ul][li]IPaddr[/li]
[li]IPport (defaults to 20023)[/li]
[li]ApplicationNum (defaults to 56 for lighting)[/li]
[li]NetworkNum (defaults to 254)[/li]
[li]Project (defaults to HOME)[/li][/ul]

What it does:

[ul][li]Opens Socket Connection to CGATE and Set’s up Defined Project[/li]
[li]Calls the CGATE TREE Function to enumerate the Group and Unit List. Also figures out what type of devices they are DIMMER/RELAY for now.[/li]
[li]Set’s up the Cgate Events to Status changes, then we dont have to poll. [/li]
[li] Create Child devices for each Group created in the CBUS network[/li]
[li] You can control (ON, OFF, DIM) the devices like any other[/li][/ul]

What it doesn’t do:

[ul][li]Does not talk directly to RS232. Have not even investigate this, would be nice, then you could eliminate CGATE server, but then, will have to figure out the CBUS protocol, and won’t have the management of CGATE[/li]
[li]Does not cater for any other devices except Lighting Application at this time[/li][/ul]

TODO:

[ul][li]Initial Load of Devices does not reteive status initially, unless an event comes from CGATE… Need an hour or two to do this still[/li]
[li]More robust Error handling and recovery. I have got most rudimentary recovery for disconnects, power fails etc, but not nearly enough yet I think.[/li]
[li]Learn some more about plugin-ins. So that it conforms to all DO’s and DONT’s. I’m not sure if this plugin is written correctly, or stable.[/li]
[li]Wrap it all up nicely as a proper plugin with install[/li][/ul]

Have a go at it, and let me know how it goes…

PLEASE… give feedback.

Hey tiaanv,

Loving your work!

So far seems pretty stable to me, and a lot less hassle than what I was using to get the update back. I’ve started using it as my main connection to the CBUS so I will let you know how the stability goes :slight_smile: Also is working fine with SimpleWave on my iPhone

I’m only using lighting (and exhaust fans that show up as lighting anyway!), so thats as far as mine goes. I think the only thing that would be nice if I could get the description for the group rather than the “C-Bus Group 11=REL” as the labels.

Thanks,
Pete

[quote=“tiaanv, post:13, topic:175506”]What it doesn’t do:

[ul][li]Does not talk directly to RS232. Have not even investigate this, would be nice, then you could eliminate CGATE server, but then, will have to figure out the CBUS protocol, and won’t have the management of CGATE[/li]
[li]Does not cater for any other devices except Lighting Application at this time[/li][/ul][/quote]

The C-Bus RS232 (PCI) or Ethernet interface (PCN) are obviously tidier in terms of the way you connect to C-Bus and the ability to remove the C-Gate dependence , and the associated PC that it is running on but it’s a huge change in terms of coding complexity. The raw C-Bus protocol is pretty complex and chatty and adding support for C-Bus applications that are different to the lighting application is very challenging. It can be done but it would put a lot of overhead on Vera which would be problematic and detrimental to the solution I feel.

C-Gate also does a great job of modelling the C-Bus networks ensuring that state information is well maintained even across bridges. So staying with C-Gate is probably the best option. I know there is some talk about people running C-Gate on a Raspberry Pi and that would seem a good option for a PC less 24/7 solution.

Kevin
(C-Bus Enabled Developer - Ethernet gateway)

Word of warning.

Found a couple of issues. I will attend to them this weekend, as i am away on business.

The main issue at the moment is that if cgate server is not available at time of the plugin initialising, like on reboot or lua engine restart, the existing devices are removed. This obviously sucks if like me you have renamed the devices and moved them to a different location.

So until i fix this, just be aware. Keep your cgate server up and runnng!!

Sent from my iPad using Tapatalk HD

[quote=“XAPPO”][quote=“tiaanv, post:13, topic:175506”]What it doesn’t do:

[ul][li]Does not talk directly to RS232. Have not even investigate this, would be nice, then you could eliminate CGATE server, but then, will have to figure out the CBUS protocol, and won’t have the management of CGATE[/li]
[li]Does not cater for any other devices except Lighting Application at this time[/li][/ul][/quote]

The C-Bus RS232 (PCI) or Ethernet interface (PCN) are obviously tidier in terms of the way you connect to C-Bus and the ability to remove the C-Gate dependence , and the associated PC that it is running on but it’s a huge change in terms of coding complexity. The raw C-Bus protocol is pretty complex and chatty and adding support for C-Bus applications that are different to the lighting application is very challenging. It can be done but it would put a lot of overhead on Vera which would be problematic and detrimental to the solution I feel.

C-Gate also does a great job of modelling the C-Bus networks ensuring that state information is well maintained even across bridges. So staying with C-Gate is probably the best option. I know there is some talk about people running C-Gate on a Raspberry Pi and that would seem a good option for a PC less 24/7 solution.

Kevin
(C-Bus Enabled Developer - Ethernet gateway)[/quote]

I agree with you completely Kevin. I actually like the cgate layer, but i thought i would investigate it. If you say the protocol is quite chatty, I think i will leave it altogether and spend effort elsewhere, as the veralite especially gets bogged down easily.

I like the cgate ras pi idea. In My house i always have a server running, but ill try it out just for experiment sake.

Thx for the great feedback guys!

Sent from my iPad using Tapatalk HD

[quote=“peteinau”]Hey tiaanv,

Loving your work!

So far seems pretty stable to me, and a lot less hassle than what I was using to get the update back. I’ve started using it as my main connection to the CBUS so I will let you know how the stability goes :slight_smile: Also is working fine with SimpleWave on my iPhone

I’m only using lighting (and exhaust fans that show up as lighting anyway!), so thats as far as mine goes. I think the only thing that would be nice if I could get the description for the group rather than the “C-Bus Group 11=REL” as the labels.

Thanks,
Pete[/quote]

Thx for the feedback. I can indeed get the group descriptions from cgate. I have written it, just need. To get it tested properly. The way i handle coms back from the cgate is completely async, so i just need to make sure that I time the label updates correctly. More importantly, I must make sure it does not overwrite the descriptions on the vera if they have been changed there.

Keep the feedback coming… Im a little pre-occupied with work at the moment and renovating the house I just moved into, so I apologize if the updates and fixes are a little slow. I promise I will not let the progress stop until we have a fully functional and reliable plugin.

T

Sent from my iPad using Tapatalk HD

Hey,

Appreciate all your hard work so far, you’ve definitely got more programming skills than me! :slight_smile: Particularly mid-renovation must be busy!

So am running it all the time now to ensure that I’m giving it a good work out. So some feedback:

  • The Lighting icons aren’t always updating. You turn the light off but the icon is still the lit globe.
  • The percentage for the light level doesn’t update either. Updates to 100% when you turn it on, but doesn’t change to 0 or whatever you change the light level to. Some testing revealed the % the light is changed to when it’s first turned on is what it stays at.
  • In both of the above cases the correct On or Off button is it lit up.
  • Is there any way to remove a device? We have a couple of groups in Cgate that are wired, but not actually connected to anything.

We just bought a rasberry pi, so been looking at moving c-gate to it off the windows VM off my server, I think it might be a bit more stable, and I’ve been trying to separate all of the home automation from the server. I’ll let you know how it goes.

[quote=“peteinau, post:19, topic:175506”]Hey,

Appreciate all your hard work so far, you’ve definitely got more programming skills than me! :slight_smile: Particularly mid-renovation must be busy!

So am running it all the time now to ensure that I’m giving it a good work out. So some feedback:

  • The Lighting icons aren’t always updating. You turn the light off but the icon is still the lit globe.[/quote]
    I will look into this… perhaps we are not catching all the events from cgate… take a look at the log, to see if it is catching the cgate event. The only additional thing I can think of doing is implementing polling functionality to routinely update the status, even if the event somehow was missed.
- The percentage for the light level doesn't update either. Updates to 100% when you turn it on, but doesn't change to 0 or whatever you change the light level to. Some testing revealed the % the light is changed to when it's first turned on is what it stays at.
You might need to send me your log file to look at this, as it updates with me?
- In both of the above cases the correct On or Off button is it lit up.
it should, as the button get's lit upon you pressing it..
- Is there any way to remove a device? We have a couple of groups in Cgate that are wired, but not actually connected to anything.
Perhaps I can include a variable where you can put a comma seperated list of group numbers you don't want the plugin to generate devices for
We just bought a rasberry pi, so been looking at moving c-gate to it off the windows VM off my server, I think it might be a bit more stable, and I've been trying to separate all of the home automation from the server. I'll let you know how it goes.
Let me know how it went.

Regards
Tiaan

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules