Is the washing machine done?

Post Reply
User avatar
felix63
Posts: 121
Joined: Monday 07 December 2015 10:30
Target OS: Raspberry Pi
Domoticz version: 3.8275
Location: Gouda
Contact:

Is the washing machine done?

Post by felix63 » Monday 11 June 2018 22:55

A DzVents script inspired by other scripts - no claim to ownership but adapted for dzvents to check to see if various appliance are running and give a warning when they have finished again. Stuff like washing machines, tumble dryers and the likes. Typically these devices don't switch off completely but go into a standby mode. The basic assumption is that the device is connected to a power measuring socket ('SC-XXXX verbruik') and a virtual switch ('XXXX'). For each device you can set a time-out period giving the period the power usages has to remain below a variable threshold value in order to be considered finished. You can also let the script handle giving a notification when a device is finished.

Code: Select all

 -- create a lookup table that matches a usage
 -- device to the accompanying switch
 local USAGE_DEVICES = {
	['SC-Wasdroger verbruik'] = 'Wasdroger',		-- You need to have a inline wall plug that measures energy,
	['SC-Wasmachine verbruik'] = 'Wasmachine',	-- here you make the link between the energy device and the wall plug.
 }

 local USAGE_SwitchTimeOutMinutes = {
 	['Wasdroger'] = 6,		-- Here you define how long no power is used per device.
 	['Wasmachine'] = 6,		-- The period is in minutes. Adjust to your needs. Between every add a ",".
 }

 local USAGE_MaxWatt = {
 	['Wasdroger'] = 3,		-- Here you define the maximum amount of power a device uses when it is in standby.
 	['Wasmachine'] = 3,		-- Some devices uses a little amount of power. Test it and a slightly higher usage.
 }

 local USAGE_Notify = {
 	['Wasdroger'] = 'Yes',		-- In some cases you want to be notified when a device is turned on and off.
 	['Wasmachine'] = 'Yes',	-- Adjust to your needs. Between every line you need to add a ",".
 }

 return {
 	logging = {
-- 		level = domoticz.LOG_INFO,		-- Uncomment to override the dzVents global logging setting
 		marker = 'POW'
 	},

 	on = {
		timer = { 'every 5 minutes' },
 		devices = {		-- Make sure that the devices are the same as above
 			'SC-Wasdroger verbruik',
 			'SC-Wasmachine verbruik',
 		},
 	},
 	data = {		-- use exact device names to match USAGE_DEVICES
 		['SC-Wasdroger verbruik'] = { history = true, maxMinutes = 10 },
 		['SC-Wasmachine verbruik'] = { history = true, maxMinutes = 10 }
 	},

 	execute = function(domoticz, device)
         if (device.isTimer) then
 			-- we need to check for expiration of grace period
 			domoticz.log("timer trigger")
 			for i, machine in pairs(USAGE_DEVICES) do
				local usage = "SC-" .. machine.. " verbruik"
 				domoticz.log("device = " .. machine)
 				local actual = domoticz.devices(usage).WhActual
 				domoticz.log("actual = " .. actual)
				if actual == 0 then
					domoticz.log(machine .. " gebruikt geen energie, dus is uit")
					domoticz.devices(machine).switchOff().checkFirst()
				elseif actual < USAGE_MaxWatt[machine] then
					domoticz.log(machine .. " gebruikt weinig energie, is de machine klaar?")
					local history = domoticz.data[usage]
					local timeout = USAGE_SwitchTimeOutMinutes[machine]
					domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(history.avg))
					if (domoticz.devices(usage).lastUpdate.minutesAgo >= timeout) then
						domoticz.log(machine .. " lijkt standby te staan, we nemen aan klaar.")
						domoticz.devices(machine).switchOff().checkFirst()
					else
						domoticz.log(machine .. " maar nog te kort om klaar te zijn.")
						domoticz.devices(machine).switchOff().checkFirst()
					end
				else 
					domoticz.log(machine .. " gebruikt energie, dus is (nog) bezig.")
					domoticz.devices(machine).switchOn().checkFirst()
				end
 			end
 		elseif (USAGE_DEVICES[device.name] ~= nil) then
 			-- we have a usage sensor here
 			domoticz.log("usage trigger")
 			local switch = domoticz.devices(USAGE_DEVICES[device.name])
 			local history = domoticz.data[device.name]
 			local timeout = USAGE_SwitchTimeOutMinutes[USAGE_DEVICES[device.name]]
 			local watt = USAGE_MaxWatt[USAGE_DEVICES[device.name]]
 			domoticz.log("device = " .. device.name)
 			history.add(device.WhActual)
 			if (switch.active) then
				domoticz.log("Switch is active, check average use and last update")
				domoticz.log("usage last update: " .. tostring(switch.lastUpdate.minutesAgo))
				domoticz.log("average = " .. tostring(history.avg()))
				if (history.avg() <= watt and switch.lastUpdate.minutesAgo >= timeout) then
    			 		switch.switchOff().checkFirst()
					domoticz.log("Turn switch off")
     				end
			else
				domoticz.log("Switch not on")
				if (device.WhActual > watt) then
					domoticz.log("but power use is over treshold, turn switch on")
					switch.switchOn().checkFirst()
				end
			end
 		end
 	end
 }
 
Last edited by felix63 on Wednesday 13 June 2018 22:41, edited 1 time in total.

freijn
Posts: 299
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: Is the washing machine done?

Post by freijn » Tuesday 12 June 2018 8:57

My next item on the list. Will give it a try , many thanks for sharing!!
Frank

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests