I would agree with you if I was able to understand how the stock driver sends preference changes when the device wakes up. Maybe I’m missing something, which I don’t see in the default libraries, that calls the update_preferences function when the device wakes up.
In the driver I don’t see anywhere that the update_preferences function is called to send the changes that have been produced by the user.
The only time update_preferences function is called for devices that support c.c.wakeUp is in the init lifecycle, with the function:
local function device_init(self, device)
device:set_update_preferences_fn(preferences.update_preferences)
end
This function from the default libraries would execute preferences.update_preferences for the device only in the init lifecycle.
This means that the changes in preferences in devices with wakeUp will never be updated, except during the installation or when the driver or the hub is restarted…, but if the driver or the hub is restarted I do not think it guarantees that the device will wake up, but I may be wrong.
The function preferences.update_preferences already has a filter to only send parameter values that have been changed in the preferences from the last value saved in permanent memory, but the driver never really knows what value the device has for each parameter since driver is not read device parameters to save them in permanent memory. Well, except in the Fibaro door-window sensor subdriver, which has a specific infoChanged function to synchronize the value of the parameter saved in the device and the value in user preferences.
That’s why I think the best way to do it is to wake up the device and try to send the new value of the parameter as fast as possible.
This is how I do it with my fibaro button and the Z-Wave Device Config Mc driver and it works perfectly.
UPDATE:
I have retested with CLI the function that is saved in the lifecycle device_init function and now I see that it calls the update.preferences function when the WAKE_UP NOTIFICATION is received from the device.
At the time I changed the infoChanged function code I didn’t see that it worked well and that’s why I changed it.
I will put the preferences an option for the user to choose to send the new parameters values immediately or automatically when he wakes up
Thank you @philh30