Help getting first plugin working

Hi

I have started to put together a plugin to control another lighting system ‘unison’ using rs232.
I am very much at the start of learning how to put things like this together and started from the rs232 quad relay as a guide.

To start with I am trying to control in both directions 16 x switch circuits - once I have this working then I will want to add 16 x dimmable circuits.
So far I cam get my Vera lite to control the 16 x switch circuits and when the circuits are controlled by the other lighting system it will update the status ‘on’ and ‘off’ to match the operation of the light, but the problem comes if I then want to control it from Vera -

I am concentrating on switch ID 23 for the moment.

If I turn on the light from Unison I cannot turn it off from Vera unless I turn the Vera switch ‘off’ the ‘on’ then ‘off’ again then it will send the rs232 command.
If I turn the light on from Vera then turn it off from Unison the status does not update to ‘off’ and I have to turn it ‘off’ in Vera

I have attached the files I am using I hope someone can point me in the right direction to solving this.

Thanks
Martin

That’s a good start. I think you are close with the code you’ve already got.

Some things I noticed:

  • Customarily you don’t set the Status variable until you have received confirmation back from the device that its status has actually changed. Perhaps you don’t get confirmation with this particular serial protocol? That’d be a shame, but I’ve seen the same in other devices.

  • I wonder if the serial protocol is getting out of whack because Vera is sending a correct command, then some trailing garbage (perhaps a line feed?) that confuses the Unison device. It takes a couple of re-sends for the commands to get back in sync. Just a thought.

  • Log more. Lots more. Log every string that you luup.io.write() and every string that the Incoming function gets. Log your control flow and pay attention to any Lua errors that you see in the log, because a Lua error will stop your code cold.

Thanks for your suggestions.
I have been looking at it again and am thinking at starting again, but this time using the LutronradioRA plugin as my basis for a start as it looks like it already implements most of what I am looking for - I just need to change the commands to match my Unison system.

No doubt i will be back with more questions.

Thanks

Martin

Following on from my first attempt at creating a plugin for my lighting system I have since found that the LutronRadioRA plugin better matched my requirements and existing setup.
So far I have managed to get it to send commands from the Vera Lite to the lighting system using serial commands for the light switch devices, but after that I have run into a few problems I hope someone can point me in the right direction to solve.

To explain the protocol
The serial interface allows for 16 x light switch device(on off) and 16 dimmer devices.
the 16 light switch devices are numbered 1 - 16 and the dimmer devices are also numbered 1 - 16.
To send a command to the buttons I have to send SB1.1 which will turn the button on and SB1.0 will turn it off replacing the first number ‘1’ with the required button number.
To send a command to the dimmer I have to send Sf1.100 which will turn the dimmer on and SB1.0 will turn it off replacing the first number ‘1’ with the required dimmer number.

This is the first problem I have as the lutron plugin appears to work on individual numbered devices - in this case 1 - 32.
Is there an easy way to reassign the addressing of the dimmers?

The second problem I have is with the information coming back in from my lighting interface and updating the devices in vera if I operate the lights from the normal switches.
So far I see the data coming in in the logs, but I am having trouble splitting the data so I can do something with it.

The incoming data is as follows
If a button is activated it will send either UB1.1.1 or UB1.0.1 and deactivated UB1.0.0 - The most important is ‘UB’ which means update button then the following number is the number of the switch and then the very last number ‘1’ or ‘0’ to indicate the state - the middle number is not needed to be actioned in this case.
If a dimmer is activated it will send UL1.100 and deactivated UL1.0 - the fist number being the dimmer number and the second number being the level 0 - 100.

I attach my work so far - it still has a lot of reference to the lutron plugin at this stage until I can find the code to get it to work properly I do not want to make too big changes.

Thanks
Martin

[quote=“msavage045, post:4, topic:176673”]This is the first problem I have as the lutron plugin appears to work on individual numbered devices - in this case 1 - 32.
Is there an easy way to reassign the addressing of the dimmers?[/quote]

It’s not clear to me what you mean by “reassign the addressing”. Perhaps you can explain the specific problem that you have encountered.

The second problem I have is with the information coming back in from my lighting interface and updating the devices in vera if I operate the lights from the normal switches. So far I see the data coming in in the logs, but I am having trouble splitting the data so I can do something with it.

You’ll need to brush up on your Lua string operations (Lua 5.1 Reference Manual). There are two general approaches: one is to use string.sub(the_string, start, end) and string.find(the_string, substring) to break the string into pieces and compare with the == operator; the other is to use string.match(the_string, pattern) to use Lua string matching and capture parts of the string into a list which you can assign to variables.

Which Lutron plugin did you start with? There are two of them in the app store. One from 2011, and one from 2012.

I need to do something similar with an old LiteTouch system.