after searching this forum and not finding any Wake Up script to suit my need I decided to write my own.
The script is a generic script that can support an unlimited number of Wake Up sequences. Configuration is done by creating devices, groups and user variables.
I named the Dzvents script "Wake Up" but it can be called anything. However, the devices, groups and user variables needs to follow a naming convention as follows: (<sequence> is a unique name for the specific Wake Up sequence)
Trigger device: "Wake Up <sequence>" Virtual device used to trigger the Wake Up sequence
Enabling device: "Wake Up <sequence>_Enabled" Virtual device that enables or disables the Wake Up sequence
Device group: "Wake Up <sequence>_Devices" Group that contains all the devices to be woken up by the sequence
User variable: "Wake Up <sequence>" Integer user variable used by the sequence
In addition you need to create a variable to hold the duration of wake up sequences. All sequences has the same duration.
This integer user variable needs to be named "Wake Up_Duration".
And finally, here's the script.
Code: Select all
-- Generic Wake Up script for domoticz
--
-- Set up:
-- Create the following entities in Domoticz:
-- 1. A user variable named "Wake Up_Duration" of type Integer containing the number of minutes in a Wake Up sequence. The duration is the same for all sequences.
-- 2. A Virtual Device to be used as the trigger for Wake Up
-- 3. A Virtual Device to enable/disable Wake Up named <trigger device> + the suffix "_Enabled".
-- 4. A group named <trigger device> + the suffix "_Devices". The group should contain all devices to be woken up.
-- 5. A user variable named <trigger device>.
--
-- Example: If the trigger device is called "Wake Up Bedroom" then the control device needs to be named
-- "Wake Up Bedroom_Enabled" and the device group should be named "Wake Up Bedroom_Devices".
--
-- Usage: Use a timer setting the trigger device to ON when the Wake Up sequence should begin
-- To stop an active Wake Up sequence, set the control device to OFF
-- To reset a stopped Wake Up sequence, set the trigger device to OFF
--
return {
on = {
devices = {
'Wake Up *'
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'Wake Up: '
},
execute = function(dz, d)
local duration = dz.variables('Wake Up_Duration').value -- Set Duration of Wake Up sequence
local enabled = d.name .. '_Enabled' -- Control device (Wake up enabled if this is ON)
local devicegroup = d.name .. '_Devices' -- Device group
local initvalue = 100 % duration -- Start value for sequence
local stepvalue = (100 - initvalue) / duration -- Increment per wake up step
local level = 0 -- Work variable, current level
-- If the changed device is a control device we just ignore the event
if (string.sub(d.name,-8) == "_Enabled") then
return
end
-- Make sure wakeuplevel is set
if dz.variables(d.name).value == nil then
dz.variables(d.name).set(0)
end
-- Is the trigger device turned ON?
if (d.state == 'On') then
d.switchOff().silent()
-- Is the control device turned ON?
if (dz.devices(enabled).state == 'On') then
-- Are we still in the wake up loop?
if (dz.variables(d.name).value < duration) then
level = dz.variables(d.name).value + 1
dz.variables(d.name).set(level)
local dimlevel = initvalue + (stepvalue * level)
dz.log('Set dimlevel for ' .. d.name .. ' to ' .. dimlevel .. '%')
dz.groups(devicegroup).devices().forEach(function(sd)
dz.log(sd.name .. ' dimmed to ' .. dimlevel .. '%')
sd.dimTo(dimlevel)
end)
-- Schedule next step in Wake Up sequence
d.switchOn().afterMin(1)
else
-- Wake Up loop completed
dz.log(d.name .. ' completed!')
dz.variables(d.name).set(0)
end
else
-- Control device is OFF
dz.log(d.name .. ' is not enabled')
dz.variables(d.name).set(0)
end
else
-- The trigger device was turned off so reset everything
dz.log(d.name .. ' turned off')
dz.variables(d.name).set(0)
dz.groups(devicegroup).switchOff()
end
end
}