Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team

Question
konbaasiang 0
Hi!
Although I am a programmer by profession, I am new to LUA and HC2 scene/VD scripting.
Being new to the platform, I'm noticing several limitations that are working together to make simple tasks extremely complex, and making it difficult to manage and reuse code, in a way that one might not as one gets used to the platform and accepts things as they are. That said, I could also be missing something, or multiple somethings.
Here's what I'm trying to do.
I have an 8-channel "web relay" connected to the lights on the wall surrounding my house. See the attached picture of a web relay. They're $30 on aliexpress so they offer very good value for the money, so to speak.
The lights on the inside of the wall are connected alternately to three circuits, like so: 1-2-3-1-2-3-1-2-3-1-2-3 etc
The lights on the outside of the wall (facing the street) are connected the same way: 4-5-6-4-5-6-4-5-6 ...
The last two remaining ones are connected to other lights but they're easy and can be ignored for the purpose of this discussion.
I would like to implement the following modes:
Off
On, meaning 1 of 3 circuits on, alternating daily
Bright - All 3 circuits on. For yard work in the evening, or security.
Chase - this is the fun one, for parties or just to show off. Circuit 1 for 300ms, Circuit 2 for 300ms, Circuit 3 for 300ms, repeat. The lights will chase each other around the property.
The Web Relay is controlled by TCP. You open a connection, send a text string. Easy as pie.
So, what's the problem?
In a Virtual Device, the main loop only runs once every 3 seconds. This is too slow. Even once per second (like it claims) is too slow.
This is easily solved with setTimeout but setTimeout is not available in a VD.
Okay, fine. We can make the VD trigger a scene to handle the Chase mode. The scene can use setTimeout to reliably get a 300ms timer.
But, in a scene, net.FTcpSocket is again missing, so it cannot send the command to a web relay in the first place!
So then, do we make the scene trigger a different VD button to send the command each time?
I guess we could, in theory, but then this is becoming a hot mess. How would we keep track of all that without making a mess in the HC2 gui, with all these extra VD buttons and scenes we had to create just to work around limitations? Not to mention all the global variables I would need to handle "communication" between the VD and the scenes..
and even if I manage to do all that -- likely hours of work, for flashing some lights ... how would I reuse it for the three circuits on the outside wall?
I must be missing something, I think. It cannot possibly be this hard.
I would love to hear your suggestions about how to accomplish the task with HC2 scripting.
At this point it will be a lot quicker and easier for me to implement this in C++ on another machine and just have a HC2 VD trigger the different modes by HTTP, so I'm going to do that, but I would still like to learn how others would have solved the problem, and perhaps suggest that these limitations are unnecessary and that it could save a lot of development headache if they were simply addressed.
As it is, there seem to be just the right amount of limitations in just the right places to make simple things very, very difficult. I have to believe that Fibaro wants to improve their product and make it easier to use and develop for, so here are my suggestions. I'm sure many of these have been requested before, but here goes:
setTimeout would be preferable though, because the main loop likely does not need to run periodically in all modes, so this way it could be left up to the script writer, which would save CPU resources.
Again, I'm sure I'm missing some things, would be glad to receive some pointers. Thank you for reading!
Please login or register to see this spoiler.
15 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.