parameters are: function_name (string), service (string), variable (string or nil), device (string or number)
If variable is nil, function_name will be called whenever any variable in the service is changed. It’s not said in this doc, but it’s the same when device is nil.
Yes, that’s absolutely true, and documented in the source code file luup.lua
-- Whenever the UPnP variable is changed for the specified device,
-- which if a string is interpreted as a UDN [NOT IMPLEMENTED]
-- and if a number as a device ID, function_name will be called
-- with parameters: device, service, variable, value_old, value_new.
-- If variable is nil, function_name will be called whenever any variable in the service is changed. [NOT IMPLEMENTED]
local function variable_watch (global_function_name, service, variable, device)
In truth, I never imagined anyone would use this. But what do I know?
It can be implemented, but as a matter of interest… why?
It’s more the feature when device is nil that I need.
I have a plugin (RulesEngine) that does a lot of luup.variable_watch.
As luup engine does not allow to un-watch, unless to do a reload, the plugin just watches service and variable.
When an event occurs, it checks if the device which has triggered is one of the devices it watches.
Doing this way, it allows to stop the watch if needed without a luup reload.
If variable is nil, function_name will be called whenever any variable in the service is changed.
If device is nil, function_name will be called as soon as the variable in the service for any device is changed.
If device and variable are nil, function_name will be called for any device and variable as soon as there’s a change on the service (for a device).
If several variables have been changed in the service, or several devices have a service variables changed, then are there multiple callbacks (one for each device, service, and variable?)
I’m rather hoping that a watch call with all parameters nil does not do the callback for every variable change in the system?
Either way, this more general application of variable watch is an interesting opportunity for race conditions - if the callback routine changes any variable that it’s watching…
…so I do allow a nil serviceId in the specific case of a defined device, but undefined variable: it simply makes the callback for all changes to that device. It was, essentially, a side-effect of the other changes I made, so it’s there in openLuup, even if it’s not there in Vera. (Without adequate documentation, who could tell? - except for @vosmont with, presumably, extensive testing!) You don’t have to use it.