Convert Scene action

@akbooer not sure if it’s you or @amg0 but it would be cool to have an option in Scene EDIT that can convert all the action in LUA code.

Not quite understanding this… you mean convert the Vera scene defined actions into plain Lua…?

Including delayed actions?

Why?

yeah exactly. convert the vera scene defined action into plain Lua including delayed…

Why, 'cause I’m having some big scene and when I’m having some bug changes, like right now, some devices that changed to a new ID, I need to click, click and click to change all of them.

So for some huge scene like that I will prefer having them in LUA directly…

OK, it’s an openLuup addition, although I dare say that @amg0 could make AltUI do this too.

This is because I haven’t yet made the previous change that you asked for… retaining deleted device actions/triggers in scenes?

Nah it’s not related but it will be a very nice to have too :wink:

In my actual case, I migrated temp. the DSC plugin to another Vera and I needed to change all device ID in all my scene that are handling DSC devices.

So I did the one in Rules Engine by manually editing the config file but in openLuup I did it one by one by Scene Edit → edit trigger and/or actions.

You could, of course, edit the user_data.json file directly.

In openLuup, it’s not compressed and it’s nicely formatted… :wink:

No promise but I ll have a look

yeah I know, already checked that and it’s nice :wink:

But I think that having a way to “convert” a regular scene into a “LUA based” scene will give some custom option that we can put in the code while still being able to have delayed actions.

I’m having more and more scene that handle a bunch of “same kind” of devices and using the “convert” I will be able to use some custom function I have that handle devices with a “find_by_name” in a loop!

The alternative, of course, would simply be to lift the Lua code from the openLuup scene module which actually runs the JSON-defined scene structure directly…

Although the details are quite involved (do you want to include dependence on House mode, time of day, enabled/disabled timers, additional Lua code…) the basics are simply:

  1. loop through the delays
  2. execute all the actions in that delay group

I would say that “version 1” can be only the actions and delays, nothing else.

Like, convert action/delay into the add. Lua Code box

I have committed a version in ALTUI GitHub doing that.
in the scene editor, open the action tab, then the LUA button gives you that piece of code as displayed herebelow. it just takes into account delays and actions

2 Likes

Works perfectly. Thanks @amg0, nice job :wink:

@amg0

Can you do a little update…

when converting the scene to LUA, can you add a comment at the end of each line with the “device name”

Like:

function delay_0()
luup.call_action(“urn:upnp-org:serviceId:TemperatureSetpoint1”, “SetCurrentSetpoint”, {[“NewCurrentSetpoint”]=“22.0”}, 10303) – DeviceName
end
luup.call_delay(“delay_0”, 0, “”)

I Posted an update on github

1 Like