I almost all forums in here, i feel like i’m 3-4 years after everyone, so in case i’m not alone in this, I have a few questions:
Whats the best approach to scene programming? Right now i’m using the wizard in UI7, an no LUA code. If LUA is the best approach, do you still initiate the LUA from the scene wizard?
I’ve tried to make a state switch for lighting (combination of lights on) using virtual and combination switches, and the feeling is that the execution times is kind of random (the order of command execution). I tried to separate things using delays, but it makes each switch ridiculously slow… I Imagine LUA would be better for controlling state variables?
I know about PLEG, and i have tried it, but I see some limits to that too. If thats the next alternative, i’ll look more into LUA programming first, as that is still free.
I’m using 433 switches through RFXtrx. Not the best for precision, i know, but i would think the response time is consistent from these, as it comes from the RFX unit, not the switch?
Problem found, I had one scene i had forgot about that kicked in on cue from what happened in my new scene. I other words: User Error.
Question still stands though, is LUA the way to go in terms of flexible scene creation, and as an alternative to PLEG? I have some programming experience, mostly vb.net, but also VBA and C++…
Is it possible to declare globals that can be used across several scenes?
Check out http://lua.org for information on the LUA language and syntax.
Yes, you can declare global variables. Easiest is to put them in the global code section (also known as the LUA start up code section). You could also put global functions there as well.
In LUA, anything that does not have “local” in front of it becomes global. Which can trip you up if you are not careful.
Remember: Global variables are lost when the LUA engine reloads (such as when Vera reboots). Reboots happen more often than we would like.
You can program in LUA … all of the plugins are written in LUA including PLEG
However programming in LUA is like programming in assembly language as compared to programming in “C”
Advantages of PLEG
You do not need to know all of the details/case sensitive nature of Device Variables, Actions, and ServiceIDs. You use a menu to select. You focus on the LOGIC and not the SYNTAX of LUA and Veras use of a UPnP device model.
PLEG handles state management when your Vera reboots.
Vera and standard LUA is very poor when this involves timed events, you can loose all the timing and deferred things do not happen if Vera is restarted or rebooted.
In LUA you might need multiple scenes to accomplish a task. The LUA for this is spread out in different scenes. So it’s difficult to see the whole picture at one time … In PLEG you can see all of this, plus current and recent values for all of your inputs in the PLEG reports.
PLEG allows trigging for ANY device variable. Scenes do not support this. You have to do this outside the context of Scenes.
PLEG has some higher level constructs that make many automation tasks easiers.
a) Schedules that have both an ON and and OFF time.
b) Sequence Expressions that help trigger based on the order of events.
[hr]
Using Scenes with LUA is a poor alternative to PLEG.
Doing almost everything in LUA is much more useful … and there are a number of developer-users that do this.
In that case a scene is just one method for user initiated actions.
In that case you place all of your code in LUA files … and in the Vera LUA startup you just load it and side effects of it loading is it does all of it’s own initialization and registering for various events in the Vera Environment …
This is what a PLUGIN does. So you can think of this as a user defined plugin.
[hr]
My house is heavily automated … and the logic for this is almost entirely in PLEG.
I do have one function that manages state management for some 25 independent lights in my shop which are controlled from a single switch that is managed in LUA. The switch remembers the last pattern, and I control the pattern via voice commands in Google Home.
Ok, so it seems that the alternatives are LUA straight through or PLEG for more advanced automation. I will take a closer look at both… I tried PLEG a bit, but I didnt figure out how to use virtual variables the way i wanted, and got annoyed and deleted the thing. It probably deserves a bit more patience from my side.
Can you set up math there as well? like factors for linear equations between sensors and outputs? Example: I want the heater in my car to start earlier when its colder out in order to have a warm seat to get into at a certain time.
So theres no way around using LUA if you need math? That should have been a separate plugin, a math plugin with IF statement capability that returns a number or string (optional)…
[quote=“Forzaalfa, post:8, topic:197524”]Can you set up math there as well? like factors for linear equations between sensors and outputs? Example: I want the heater in my car to start earlier when its colder out in order to have a warm seat to get into at a certain time.
Thanks for all the input![/quote]
I have taken to LUA route … here is some tips
0.Backup always before you start developing anything new → you will do a restore if and when everything will collaps
Edit the code in separate editos I use notepad++
debugin is fell , use separate debug file and write debug info rom your code
add code in litle steps (eaven row By row) and test between edits
Put your global variables and fuctions to apps->develop apps->startup lua (that is excecuted in boot and restarts)
read the search examples from the forum 0 lua manual from the net
By the way “car heater” you can do it via multible scenes
scene at 06:00 heater on if outside temp is below -15 celcius
scene at 06:30 heater on if outside temp is below -10
scene at 07:00 heater off (and you leave the house to the car )
I suppose the heater issue can be solved, but if i could have some math capability behind a variable (virtual device), this variable can be used smarter control of ore than one thing. Theres always a way - right now i’m using a state switch made of 3 scenes and 3 combination (virtual) switches. this would be much more elegant (and less processor consuming) if i had a math function and a few globals available.
Global variables do exist. And math work also in Lua. Remember that wait or delay in scrips are not a good idea because Vera consider them as fauls and will terminate the execution.
So you need a schedule that fires at the SOONEST you would want to turn on the heat.
When that schedule happens.
Check the temperature … Based on the temperature use a function or condition logic to trip a self triggered timer in PLEG.
i.e. 1 Second later, 30 minutes later, 1 hour later.
When that timer expires … turn on the heat for your car seat.
Best Home Automation shopping experience. Shop at Ezlo!