Event Watcher with PLEG - writing to the Log


I was hoping you might be able to help me solve a problem I am having. Event Watcher is installed and working well, writing its logs to the /dataMine/EventWatcher/ folder as described in your documentation. Where I am struggling is with writing events to the log. Your documentation uses this bit of code:

local function myEvent (text)
  local url = require "socket.url"
  luup.inet.wget ("" ..

which I believe may be a little outdated. I am on UI7 with a Vera Secure. (1.7.3233) The current code to access the data is on my machine ( is:

This works perfectly, but notice the difference in how the port is defined. All following code uses this basic approach.

What I want to do is to be able to write to the log from within PLEG, using the LUA code in the Logic Action. I can successfully write one line of data using this code:

luup.inet.wget ("")

but would like to expand on this with a function that includes URL encoding. I have placed the following code in the LUA startup section of the PLEG instance:

local function EWLogIt (text)
  local url = require "socket.url"
  local text = "HVAC PLEG" .. url.escape(text)
  luup.inet.wget ("" .. text)

and am calling the function in the LUA code of the associated action within that PLEG instance using:

EWLogIt "Something happened"

The ultimate goal is to add the start-up code to each of my 4 instances of PLEG, changing the prefixed text to reflect each PLEG, and log specific data to the Event Watcher log. Having a log written to USB allows all logged data to survive a restart, which is a huge advantage in my opinion. Using a function reduces code overhead, simplifies coding changes and makes the call to the function universal. As I understand it, each PLEG uses its own startup functions so calls to the function are local to that instance.

Unfortunately, this does not work. In my mind there are several possibilities; 1) The function is not being called correctly; 2) The function is not defined correctly (Global vs Local?); 3) There is a syntax error in the code or 4) What I am trying to do is simply not possible in this situation. I believe that the code is correct and that this should be possible so I am at a loss for why it does not work.

I thank you for all the work you have done with your plug-ins and hope that there is a simple solution to my problem

It sounds as though your issue is more to do with PLEG than EventWatcher?

Have you been able to test the code outside of the PLEG context (ie. in Lua Test or Startup?)

I?m not in the least familiar with PLEG, so I don?t know how it arranges its code, but if it is the same as usual then it’s quite possible that the function needs to be defined as a global (so simply remove the local from its definition.)

Perhaps RTS will be along to sort this out. If not, you may wish to repost of the PLEG sub-forum. However, my advice is certainly to check the code without PLEG before trying to embed it in the same.


Thanks for the quick response. I will check the forum for help calling a function within PLEG and may reach out to RTS if I still can’t get it figured out. I will also try testing the code outside PLEG but not sure if I can call a function using the Test Lua. Does not seem like it could hurt to try. Thanks again!!


OK, so if you want to log system actions to Event Watcher from PLEG and have the ability to retain data beyond system reboots this is my final working code. Place this part in the Start Up Lua section of PLEG.

function EWLogIt (var_txt)
  var_url = require "socket.url"
  var_txt = "System PLEG: " .. var_txt
  var_txt = var_url.escape(var_txt)
  luup.inet.wget ("" .. var_txt)

and this line goes in the LUA code section of the Action being logged:

EWLogIt "Text to get logged"

Each PLEG instance gets the startup code, and you can edit the prefix part to reflect the nature of that PLEG instance. In my system, with 4 instances running, the prefixes are Alarm PLEG, System PLEG, HVAC PLEG and Weather PLEG. You won’t need to add anything to Event Watcher, as the logged entries are displayed as category ‘E’ which is on by default. The function will URL encode the text, so there is no need to add underscores or manually encode it. Type the text you want logged and let it run. Do note that in order to retain the data beyond reboots, you must log the data to USB or other storage. The Event Watcher documentation is very clear on how to do this, especially if you are already using DataMine. Thank you to akbooer and RichardTSchaefer for their hard work on these great plug-ins. Without either my Vera would not be nearly as useful.

Below is a very small excerpt of the log files during testing:
2017-12-03 14:31:19.712, S, 81, Kit Motion Sensor, Tripped, 1,
2017-12-03 14:31:19.726, E, 0, , User, System PLEG: Kitchen Motion,