Change 'sXX_kWh_Device' in the script to the corresponding kWh devices.
Create the user variables (integer) 'XX_Counter' and 'XX_Status' for every device you would like to use.
Change 'iXX_Counter_Uservar' and 'iXX_Status_Uservar' in the script to the names of the created user variables.
In the script 'iXX_idle_Minutes', 'iXX_Consumption_Upper' and 'iXX_Consumption_Lower' can be changed to make sure your device is finished before sending the notifications.
After a dryer program is finished, the machine often flips the laundry every couple of minutes to prevent wrinkling.
This creates a small peak in the usage of electricity and a reset of the user variables.
To prevent notifications are send every couple of minutes 'iNotification_Threshold' is used to make sure the notifications are only send 900 seconds after the program is started.
Code: Select all
--------------------------------------------------------------------------------------
-- Witgoed script (LUA-Time)
--
-- Send a notitication when a dishwasher, dryer or washing machine program is finished
--
--------------------------------------------------------------------------------------
-- DISHWASHER (vaatwasser) variables --------------------------------------------
local sVW_kWh_Device = 'Vaatwasser Tussensch. kWh Meter' -- Dishwasher kWh device
local iVW_Counter_Uservar = 'VW_Counter' -- Dishwasher counter user variable
local iVW_Status_Uservar = 'VW_Status' -- Dishwasher status user variable
local iVW_idle_Minutes = 2 -- Number of minutes that the consumption must remain below the value of 'iVW_Consumption_Lower'
local iVW_Consumption_Upper = 6 -- If the consumption is higher than this value, the dishwasher has started a program or is still in progress
local iVW_Consumption_Lower = 2 -- If the consumption is less than this value, the dishwasher is idle
local iVW_Past_Time = 0 -- Elapsed time in seconds since dishwasher program started
iVW_Usage = tonumber(otherdevices_utility[sVW_kWh_Device]) -- Current consumption to local variable
-- DRYER (wasdroger) variables --------------------------------------------
local sWD_kWh_Device = 'Wasdroger Tussensch. kWh Meter' -- Dryer kWh device
local iWD_Counter_Uservar = 'WD_Counter' -- Dryer counter user variable
local iWD_Status_Uservar = 'WD_Status' -- Dryer status user variable
local iWD_idle_Minutes = 2 -- Number of minutes that the consumption must remain below the value of 'iWD_Consumption_Lower'
local iWD_Consumption_Upper = 6 -- If the consumption is higher than this value, the dryer has started a program or is still in progress
local iWD_Consumption_Lower = 1.5 -- If the consumption is less than this value, the dryer is idle
local iWD_Past_Time = 0 -- Elapsed time in seconds since dryer program started
iWD_Usage = tonumber(otherdevices_utility[sWD_kWh_Device]) -- Current consumption to local variable
-- WASHING MACHINE (wasmachine) variables --------------------------------------------
local sWM_kWh_Device = 'Wasmachine Tussensch. kWh Meter' -- Washing machine kWh device
local iWM_Counter_Uservar = 'WM_Counter' -- Washing machine counter user variable
local iWM_Status_Uservar = 'WM_Status' -- Washing machine status user variable
local iWM_idle_Minutes = 2 -- Number of minutes that the consumption must remain below the value of 'iWM_Consumption_Lower'
local iWM_Consumption_Upper = 6 -- If the consumption is higher than this value, the washing machine has started a program or is still in progress
local iWM_Consumption_Lower = 1.5 -- If the consumption is less than this value, the washing machine is idle
local iWM_Past_Time = 0 -- Elapsed time in seconds since washing machine program started
iWM_Usage = tonumber(otherdevices_utility[sWM_kWh_Device]) -- Current consumption to local variable
-- COMMON variables -----------------------------------------------------------------------
local iNotification_Threshold = 900 -- Threshold in seconds before notification can be sent
local iDebug = false -- Enables / disables debugging
-- Function for converting seconds to a clock format (HH: MM)
function SecondsToClock(s)
s = tonumber(s)
if s <= 0 then
return '00:00';
else
hours = string.format("%02.f", math.floor(s / 3600));
minutes = string.format("%02.f", math.floor(s / 60 - (hours * 60)));
return hours..':'..minutes
end
end
-- Function for calculating the time difference between a specified time and the current time in seconds
function timeDifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
Difference = os.difftime (t1, t2)
return Difference
end
commandArray = {}
-- DISHWASHER (vaatwasser) handling --------------------------
-- Send a notification when the dishwasher program is finished
-- Current consumption is higher than 'iVW_Consumption_Upper' and user variable 'VW_Status' is 0 so dishwasher program has started
if (iVW_Usage > iVW_Consumption_Upper) and uservariables[iVW_Status_Uservar] == 0 then
commandArray['Variable:' .. iVW_Status_Uservar]='1'
commandArray['Variable:' .. iVW_Counter_Uservar]=tostring(iVW_idle_Minutes)
if iDebug == true then -- Print when debugging is enabled
print('Vaatwasser: Vaatwasser is gestart (keuken)')
print('iVW_Usage: '..iVW_Usage)
print('iVW_Consumption_Upper: '..iVW_Consumption_Upper)
end
end
-- Current consumption is lower than 'iVW_Consumption_Lower', check variable 'iVW_Counter_Uservar'
if (iVW_Usage < iVW_Consumption_Lower) and uservariables[iVW_Status_Uservar] == 1 then
commandArray['Variable:' .. iVW_Counter_Uservar]=tostring(math.max(tonumber(uservariables[iVW_Counter_Uservar]) - 1, 0))
if iDebug == true then -- Print when debugging is enabled
print('Vaatwasser: Vaatwasser is idle (keuken)')
print('iVW_Usage: '..iVW_Usage)
print('iVW_Consumption_Lower: '..iVW_Consumption_Lower)
end
elseif ((uservariables[iVW_Counter_Uservar] ~= iVW_idle_Minutes) and uservariables[iVW_Status_Uservar] == 1) then
commandArray['Variable:' .. iVW_Counter_Uservar]=tostring(iVW_idle_Minutes)
if iDebug == true then print('Vaatwasser: Timer reset') end -- Print when debugging is enabled
end
-- Dishwasher is ready
if ((uservariables[iVW_Status_Uservar] == 1) and uservariables[iVW_Counter_Uservar] == 0) then
iVW_Past_Time = (timeDifference(uservariables_lastupdate[iVW_Status_Uservar]) - ((iVW_idle_Minutes + 1) * 60)) -- Elapsed time in seconds since dishwasher program started
if (iVW_Past_Time >= iNotification_Threshold) then -- Check whether the threshold is sufficient and notification can be sent
commandArray[#commandArray + 1]={['SendNotification'] = 'Vaatwasser#Vaatwasser is klaar ('..SecondsToClock(iVW_Past_Time)..')#0#pushover##pushover'} -- Send Pushover notification
if (otherdevices['HK-MC01 Kodi'] ~= 'Off') then -- Device 'HK-MC01 Kodi' is active
commandArray['SendNotification'] = 'Vaatwasser#Vaatwasser is klaar ('..SecondsToClock(iVW_Past_Time)..')#0###kodi' -- Send Kodi notification
end
end
commandArray['Variable:' .. iVW_Counter_Uservar]='0'
commandArray['Variable:' .. iVW_Status_Uservar]='0'
if iDebug == true then -- Print when debugging is enabled
print('Vaatwasser: Vaatwasser is klaar ('..SecondsToClock(iVW_Past_Time)..')')
print('iVW_Usage: '..iVW_Usage)
end
end
-- DRYER (wasdroger) handling ---------------------------
-- Send a notification when the dryer program is finished
-- Current consumption is higher than 'iWD_Consumption_Upper' and user variable 'WD_Status' is 0 so dryer program has started
if (iWD_Usage > iWD_Consumption_Upper) and uservariables[iWD_Status_Uservar] == 0 then
commandArray['Variable:' .. iWD_Status_Uservar]='1'
commandArray['Variable:' .. iWD_Counter_Uservar]=tostring(iWD_idle_Minutes)
if iDebug == true then -- Print when debugging is enabled
print('Wasdroger: Wasdroger is gestart (salon)')
print('iWD_Usage: '..iWD_Usage)
print('iWD_Consumption_Upper: '..iWD_Consumption_Upper)
end
end
-- Current consumption is lower than 'iWD_Consumption_Lower', check variable 'iWD_Counter_Uservar'
if (iWD_Usage < iWD_Consumption_Lower) and uservariables[iWD_Status_Uservar] == 1 then
commandArray['Variable:' .. iWD_Counter_Uservar]=tostring(math.max(tonumber(uservariables[iWD_Counter_Uservar]) - 1, 0))
if iDebug == true then -- Print when debugging is enabled
print('Wasdroger: Wasdroger is idle (salon)')
print('iWD_Usage: '..iWD_Usage)
print('iWD_Consumption_Lower: '..iWD_Consumption_Lower)
end
elseif ((uservariables[iWD_Counter_Uservar] ~= iWD_idle_Minutes) and uservariables[iWD_Status_Uservar] == 1) then
commandArray['Variable:' .. iWD_Counter_Uservar]=tostring(iWD_idle_Minutes)
if iDebug == true then print('Wasdroger: Timer reset') end -- Print when debugging is enabled
end
-- Dryer is ready
if ((uservariables[iWD_Status_Uservar] == 1) and uservariables[iWD_Counter_Uservar] == 0) then
iWD_Past_Time = (timeDifference(uservariables_lastupdate[iWD_Status_Uservar]) - ((iWD_idle_Minutes + 1) * 60)) -- Elapsed time in seconds since dryer program started
if (iWD_Past_Time >= iNotification_Threshold) then -- Check whether the threshold is sufficient and notification can be sent
commandArray[#commandArray + 1]={['SendNotification'] = 'Wasdroger#Wasdroger is klaar ('..SecondsToClock(iWD_Past_Time)..')#0#pushover##pushover'} -- Send Pushover notification
if (otherdevices['HK-MC01 Kodi'] ~= 'Off') then -- Device 'HK-MC01 Kodi' is active
commandArray['SendNotification'] = 'Wasdroger#Wasdroger is klaar ('..SecondsToClock(iWD_Past_Time)..')#0###kodi' -- Send Kodi notification
end
end
commandArray['Variable:' .. iWD_Counter_Uservar]='0'
commandArray['Variable:' .. iWD_Status_Uservar]='0'
if iDebug == true then -- Print when debugging is enabled
print('Wasdroger: Wasdroger is klaar ('..SecondsToClock(iWD_Past_Time)..')')
print('iWD_Usage: '..iWD_Usage)
end
end
-- WASHING MACHINE (wasmachine) handling ----------------------
-- Send a notification when washing machine program is finished
-- Current consumption is higher than 'iWM_Consumption_Upper' and user variable 'WM_Status' is 0 so washing machine program has started
if (iWM_Usage > iWM_Consumption_Upper) and uservariables[iWM_Status_Uservar] == 0 then
commandArray['Variable:' .. iWM_Status_Uservar]='1'
commandArray['Variable:' .. iWM_Counter_Uservar]=tostring(iWM_idle_Minutes)
if iDebug == true then -- Print when debugging is enabled
print('Wasmachine: Wasmachine is gestart (salon)')
print('iWM_Usage: '..iWM_Usage)
print('iWM_Consumption_Upper: '..iWM_Consumption_Upper)
end
end
-- Current consumption is lower than 'iWM_Consumption_Lower', check variable 'iWM_Counter_Uservar'
if (iWM_Usage < iWM_Consumption_Lower) and uservariables[iWM_Status_Uservar] == 1 then
commandArray['Variable:' .. iWM_Counter_Uservar]=tostring(math.max(tonumber(uservariables[iWM_Counter_Uservar]) - 1, 0))
if iDebug == true then -- Print when debugging is enabled
print('Wasmachine: Wasmachine is idle (salon)')
print('iWM_Usage: '..iWM_Usage)
print('iWM_Consumption_Lower: '..iWM_Consumption_Lower)
end
elseif ((uservariables[iWM_Counter_Uservar] ~= iWM_idle_Minutes) and uservariables[iWM_Status_Uservar] == 1) then
commandArray['Variable:' .. iWM_Counter_Uservar]=tostring(iWM_idle_Minutes)
if iDebug == true then print('Wasmachine: Timer reset') end -- Print when debugging is enabled
end
-- Washing machine is ready
if ((uservariables[iWM_Status_Uservar] == 1) and uservariables[iWM_Counter_Uservar] == 0) then
iWM_Past_Time = (timeDifference(uservariables_lastupdate[iWM_Status_Uservar]) - ((iWM_idle_Minutes + 1) * 60)) -- Elapsed time in seconds since washing machine start
if (iWM_Past_Time >= iNotification_Threshold) then -- Check whether the threshold is sufficient and notification can be sent
commandArray[#commandArray + 1]={['SendNotification'] = 'Wasmachine#Wasmachine is klaar ('..SecondsToClock(iWM_Past_Time)..')#0#pushover##pushover'} -- Send Pushover notification
if (otherdevices['HK-MC01 Kodi'] ~= 'Off') then -- Device 'HK-MC01 Kodi' is active
commandArray['SendNotification'] = 'Wasmachine#Wasmachine is klaar ('..SecondsToClock(iWM_Past_Time)..')#0###kodi' -- Send Kodi notification
end
end
commandArray['Variable:' .. iWM_Counter_Uservar]='0'
commandArray['Variable:' .. iWM_Status_Uservar]='0'
if iDebug == true then -- Print when debugging is enabled
print('Wasmachine: Wasmachine is klaar ('..SecondsToClock(iWM_Past_Time)..')')
print('iWM_Usage: '..iWM_Usage)
end
end
return commandArray