Editing vera scripts?

I’ve got a Vera controller that I configure using the built-in web UI. It seems to do more advanced things (in my case, I want to ensure a scene is only triggered during a specific time window), that I need to edit Luup code directly.

But I don’t see where to get at the code for a scene. I can see where I can add some additional code that runs, but not code that executes when triggered.

Details: I have an electric water heater that is kept off unless the overhead lights are on (this is in my shop, and I don’t come here every day). During the most expensive time of day for electricity, I want to prevent it from turning on, and turn it off if it’s already on when that period starts. For that matter I kinda just want to turn it off at some hour of the day even if the lights are still on (a couple days ago I forgot to kill the lights when leaving, and the water heater was on for two days wasting money).

Hi
When you create the scene there is a a step 3 finish the scene- Also, execute the following Luup code:. below this you can add luup code. when the scene triggers this code is run before any actions are run. if this code returns true action follow. If false action do not run.

1 Like

Thank you, that works!

Just for info, In scene editor when you select your triggers there is an option to add luup code for the individual trigger. This code will only execute when that individual trigger has been activated, and runs before the othe luup code.

Thanks from my side as well, this helped me a lot

At the moment I am not capable of accessing the Vera GUI, but I can ssh into the Vera Plus command line. I wanted to check and possibly edit, using vi, the /etc/cmh/user_data.json file where I believe the lua_startup script is held. But I see that there are several of them with “.lzo” extensions. I am not sure what to do. Can anybody outline steps I can take to do that?

… … :roll_eyes:

they are compressed (lzo is in fact a compression format). the script should be base 64 encoded into the file, if I remember correctly.

EDIT: to uncompress, just write:

/etc/init.d/cmh stop
pluto-lzo d /etc/cmh/user_data.json.lzo /tmp/user_data.json

this will create a new file in /tmp/.

if you want to edit and do the opposite (so, compress it again), just do:

--  EDIT
pluto-lzo c /tmp/user_data.json /etc/cmh/user_data.json.lzo
/etc/init.d/cmh start
2 Likes

That’s great. Thanks!

So what I was looking for is the lua startup script in the json and I found it:

“StartupCode”: “b3MuZXh…”

The problem is that looks like bytecode of some kind. Is there a way to edit or create that other than through the GUI?

It should be base 64 encoded. So, just search for an online decoder and you should be good to go.

1 Like

That is very useful information. Thank you!

Sadly, you can’t enter luup code for a schedule trigger. I also want to turn one device on at a specified time if another device is on, but otherwise not.

Hi, the code does not need to be in the trigger.

trigger schedule time
luup code get device status if 1 return true, else return false
action turn on light.

Have you looked at Reactor, a sit logic engine is far superior.