Running Lua Code ? And watching device properties?
-
@cw-kid said in Running Lua Code ? And watching device properties?:
VeraController:ERR [VeraController:performOnEntity] action request failed
VeraController:CRIT Error: Request failed: 401 ErrorHave you looked at the Vera log corresponding to the time to see what it's logging? Also what happens when you run it via the Vera UI?
luvd_get_info_data_request starting /data_request?SceneNum=null&DeviceNum=86&id=action&serviceId=urn%3Amicasaverde-com%3AserviceId%3AHomeAutomationGateway1&action=RunScene&output_format=json&_r=1614868227818 pMem 0x3473000/54996992 diff: 39190528 <0x6cd27520> 08 03/04/21 14:30:27.829 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x6cd27520> 08 03/04/21 14:30:27.829 JobHandler_LuaUPnP::HandleActionRequest argument SceneNum=null <0x6cd27520> 08 03/04/21 14:30:27.829 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=86 <0x6cd27520> 08 03/04/21 14:30:27.830 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x6cd27520> 08 03/04/21 14:30:27.830 JobHandler_LuaUPnP::HandleActionRequest argument action=RunScene <0x6cd27520> 08 03/04/21 14:30:27.831 JobHandler_LuaUPnP::HandleActionRequest argument _r=1614868227818 <0x6cd27520> 02 03/04/21 14:30:27.831 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunScene failed with 401/Invalid Scene <0x6cd27520>
Strange it says its an invalid scene.
"Fan On" is scene number 86 in Vera and that is the scene I selected to run in my "Set Reaction" run script.
If I run the "Fan On" scene actually in Vera on the UI7 web GUI it works the scene runs OK.
Why does it have a device number and scene number is null ?
SceneNum=null&DeviceNum=86
-
@tarkus That helps. Open a PR. The scene ID isn't being passed correctly. That's a quick fix you can do in place in a minute. I'll post what you need on the PR.
-
@tarkus That helps. Open a PR. The scene ID isn't being passed correctly. That's a quick fix you can do in place in a minute. I'll post what you need on the PR.
@toggledbits said in Running Lua Code ? And watching device properties?:
The scene ID isn't being passed correctly
You talking to me ?
There is a PR open already.
-
@cw-kid yes 0.1.21062 but it seems that my scenes are not getting invoked by MSR today as well. I did test when I initially installed the other day and they did work.
-
Both, and yes, I see the PR. I hadn't looked at my email or Mantis yet this morning, still getting off the ground here, so I didn't see it get opened. All good and thank you. Discussion on that thread shortly.
-
FYI, I'm also trying to implement the "run lua" action for the (vera-specific) system device. That does not mean Lua will run in MSR -- it does not, can not, and will not. But Vera does give me the ability to pass it Lua and have it execute it. That fills me with dread, frankly, but if it's what you need, it can be done. It will also need a UI change to support it, since typing Lua into a small entry field won't due. If it works, it should make invoking functions in a Lua module (built as @therealdb has shown you to do) pretty easy.
-
Update, if you haven't already been notified by Mantis: patch is up on PR#80.
-
FYI, I'm also trying to implement the "run lua" action for the (vera-specific) system device. That does not mean Lua will run in MSR -- it does not, can not, and will not. But Vera does give me the ability to pass it Lua and have it execute it. That fills me with dread, frankly, but if it's what you need, it can be done. It will also need a UI change to support it, since typing Lua into a small entry field won't due. If it works, it should make invoking functions in a Lua module (built as @therealdb has shown you to do) pretty easy.
@toggledbits said in Running Lua Code ? And watching device properties?:
FYI, I'm also trying to implement the "run lua" action for the (vera-specific) system device. That does not mean Lua will run in MSR -- it does not, can not, and will not. But Vera does give me the ability to pass it Lua and have it execute it. That fills me with dread, frankly, but if it's what you need, it can be done. It will also need a UI change to support it, since typing Lua into a small entry field won't due. If it works, it should make invoking functions in a Lua module (built as @therealdb has shown you to do) pretty easy.
I'm sure this will be very handy for some users.
I am good at the moment however, using the method therealdb showed me. Its working currently.
-
Update, if you haven't already been notified by Mantis: patch is up on PR#80.
@toggledbits said in Running Lua Code ? And watching device properties?:
Update, if you haven't already been notified by Mantis: patch is up on PR#80.
Confirmed as working again thanks.
-
I have been running Lua within my Vera reactor pretty successfully. In some cases the reason was to have some conditional logic on the activity side. I found that this enabled me to keep the condition side a bit simpler and clean. I was also running lua to send Global Cache IR codes to my older Tv's. I now am trying the CG plugin that Patrick sorted out for me. The small issue with that is I need to convert all my Global Cache codes to pronto hex. I only mention so others know it does not support CG codes. There is also some lua that I use to turn off my computer. In preliminary testing the big issue I see with lua in Vera scenes is stability. I tried moving some of my lua into scenes and invoking the scenes thru MSR and everything just became real unstable with Luup restarts. I understand that this may be issues with my Vera, etc... . I also had lua in Vera reactor activities that preceded delays or other devices commands and by moving the lua into a Vera scene will that mess with the timing? Will there be a lag on the Vera side in invoking the scene while MSR continues with the reaction? The bottom line for me is I will try to make this work and eliminates much of the lua that I can. Having some legacy devices with IR contol does not help the situation I still have a lot of work to do so I can't say if everything will work out. It will be a matter of functionality and stability for me otherwise I will just stick with Vera reactor until I can't anymore. I will say that I do wish there was lua support in MSR.
@tarkus said in Running Lua Code ? And watching device properties?:
I now am trying the CG plugin that Patrick sorted out for me. The small issue with that is I need to convert all my Global Cache codes to pronto hex. I only mention so others know it does not support CG codes.
Were you not using the GC100 plugin before? Because if you were, it should not work any differently through MSR. MSR only passes the string in whatever format. If GC100 understood other code types before (even though the action has "Pronto" in the name), it would still now. MSR doesn't modify or interpret that data.
-
@tarkus said in Running Lua Code ? And watching device properties?:
I now am trying the CG plugin that Patrick sorted out for me. The small issue with that is I need to convert all my Global Cache codes to pronto hex. I only mention so others know it does not support CG codes.
Were you not using the GC100 plugin before? Because if you were, it should not work any differently through MSR. MSR only passes the string in whatever format. If GC100 understood other code types before (even though the action has "Pronto" in the name), it would still now. MSR doesn't modify or interpret that data.
@toggledbits No I was using Lua in Vera Reactor to pass the Global Cache codes. I have played around with the GC Plugin in the past but I have not used it in years up until MSR.
-
@toggledbits said in Running Lua Code ? And watching device properties?:
FYI, I'm also trying to implement the "run lua" action for the (vera-specific) system device. That does not mean Lua will run in MSR -- it does not, can not, and will not. But Vera does give me the ability to pass it Lua and have it execute it. That fills me with dread, frankly, but if it's what you need, it can be done. It will also need a UI change to support it, since typing Lua into a small entry field won't due. If it works, it should make invoking functions in a Lua module (built as @therealdb has shown you to do) pretty easy.
I'm sure this will be very handy for some users.
I am good at the moment however, using the method therealdb showed me. Its working currently.
@cw-kid said in Running Lua Code ? And watching device properties?:
I am good at the moment however, using the method therealdb showed me. Its working currently.
I think you're missing what I'm saying. You don't need change your library structure or not do what @therealdb has suggested. It's a good, clean way to go. But if you do this from MSR right now as a Request action (that's what I assume you are doing) to run the function:
http://ip-address:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=VeraScenes.turnLightsOn%28nil%29
You can (21063 and after) just do this, assuming you've loaded the library in startup Lua:
And if you haven't loaded it in startup Lua, you can just bring it in with the code, like this:
-
@toggledbits This looks great. So much easier then having to write out the http request.
-
@cw-kid said in Running Lua Code ? And watching device properties?:
I am good at the moment however, using the method therealdb showed me. Its working currently.
I think you're missing what I'm saying. You don't need change your library structure or not do what @therealdb has suggested. It's a good, clean way to go. But if you do this from MSR right now as a Request action (that's what I assume you are doing) to run the function:
http://ip-address:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=VeraScenes.turnLightsOn%28nil%29
You can (21063 and after) just do this, assuming you've loaded the library in startup Lua:
And if you haven't loaded it in startup Lua, you can just bring it in with the code, like this:
-
@cw-kid said in Running Lua Code ? And watching device properties?:
I am good at the moment however, using the method therealdb showed me. Its working currently.
I think you're missing what I'm saying. You don't need change your library structure or not do what @therealdb has suggested. It's a good, clean way to go. But if you do this from MSR right now as a Request action (that's what I assume you are doing) to run the function:
http://ip-address:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=VeraScenes.turnLightsOn%28nil%29
You can (21063 and after) just do this, assuming you've loaded the library in startup Lua:
And if you haven't loaded it in startup Lua, you can just bring it in with the code, like this:
I thought you meant we could actually put the LUA code itself in to a MSR action "Set Reaction" and some how you were going to pass that to Vera.
But I see what you meant now, so we still need to edit the VeraScenes.lua file and add our functions / LUA code etc.
I can confirm the Play button works and the code is executed on my Vera Plus
So instead of sending a HTTP Request to Vera to initiate the function we can now just specify the function in the MSR rule actions.
-
I thought you meant we could actually put the LUA code itself in to a MSR action "Set Reaction" and some how you were going to pass that to Vera.
But I see what you meant now, so we still need to edit the VeraScenes.lua file and add our functions / LUA code etc.
I can confirm the Play button works and the code is executed on my Vera Plus
So instead of sending a HTTP Request to Vera to initiate the function we can now just specify the function in the MSR rule actions.
@cw-kid said in Running Lua Code ? And watching device properties?:
I thought you meant we could actually put the LUA code itself in to a MSR action "Set Reaction" and some how you were going to pass that to Vera.
You can, and that's exactly what's happening. Your call to your preloaded function is Lua code. You can also put this in and it will run on the Vera:
function later() luup.log("I'm running five seconds later!", 2) end luup.log("I'm running now!") luup.call_delay( "later", 5 )
You can put in any Lua you want. You can open a socket, send data, and close it. You can reload Luup (intentionally). You can write a file. No limits.
The code structure proposed by @therealdb makes good sense and is just a better way to encapsulate those functions than to bury them in Reactor rules. It will make your maintenance easier to structure your code that way.
-
This is how it will go:
That said, this won't work today, because I haven't yet connected the expressions to the action parameters (the
{master_level}
value in the dimming action won't work yet). That's coming, but not yet. You can, however, do exactly this in Vera Reactor to see how it works. It will work the same way in MSR.Edit... let me explain how it works (on both Vera Reactor and MSR):
The expression keeps the current value of the master dimmer. So on my system,
vera>device_105
is named "Virtual Dimmer 18". The trigger condition looks for any change in the dimming level of that dimmer. When it changes, the set reaction sets the current value (from the expressionmaster_level
) on the slave dimmer "Virtual Dimmer 20". Bob's your uncle.@toggledbits said in Running Lua Code ? And watching device properties?:
That said, this won't work today, because I haven't yet connected the expressions to the action parameters (the {master_level} value in the dimming action won't work yet)
Hi
Is this related to PR 0000005 ? "Set Variable action not yet implemented" Which is now Closed.
Thanks