Using the flood sensor tamper detection to see if the laundry is done

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Using the flood sensor tamper detection to see if the laundry is done

Post by pgielen »

I read the thread about sensing wether a washing machine had finished by measuring the energy use. Since I don't have an energy meter in my Domoticz setup, but I do have a Z-Wave flood sensor on the washing machine that also has tamper (= vibration) detection sensor on board, I am looking into another option. I want to use it to detect whether the machine is spinning and, when it has finished, to send a signal that the machine should be emptied. No more stale laundry that stayed in the drum for too long! This seems useful to me, because my washing machine is in the attic and although it does a play a 'pocket calculator version' of 'Die Forelle' by Schubert when finished, I don't always hear that when the TV is on or when I am out.

So how to detect if the machine is spin drying? Here is a part of the vibration sensor log:

Code: Select all

2019-03-25 16:07:50	On
2019-03-25 16:07:47	Off
2019-03-25 16:07:43	On
2019-03-25 16:07:41	Off
2019-03-25 16:07:38	On
2019-03-25 16:07:35	Off
2019-03-25 16:07:11	On
2019-03-25 16:07:07	Off
2019-03-25 16:06:53	On
2019-03-25 16:06:49	Off
2019-03-25 16:06:45	On
2019-03-25 16:06:44	Off
2019-03-25 16:06:38	On
2019-03-25 16:06:37	Off
As you can see the 'centrifuge' pattern is easily recognizable by about 8 to 10 state changes per minute. The question now is how to implement this in dzvents. A timed routine that checks every second seems the easiest (just a matter of counting), but will put an unnecessary load on the system even if there are no device updates. It must therefore be a device trigger, but then the question is how I can check how many updates occur in a certain period (preferably a minute or 5 to prevent false positive if vibrations occur during filling the machine, or washing, or pumping water, etcetera).

I think I need something like this, in pseudo code:

Code: Select all

If (number_of_devicechanges_within_5_minutes >= 40) then
	print('Washing machine is spinning') 			-- only for testing
	Centrifuge = true
End
If (device.lastupdate.minutes > 5) && (Centrifuge == true) then
	Notify ('The washing machine is ready')
	Centrifuge = false
End
Of course the challenge is how to measure 'number_of_devicechanges_within_5_minutes'. I have some programming experience, but am a newbie in dzvents, which I find a strange language compared to C or Javascript or even assembler. So how do I use it to measure how many events (device notifications, E) have occurred in a certain time period (T)? Can this be implemented in dzvents? Can I even get a Unix date in dzvents?

Pierre
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Using the flood sensor tamper detection to see if the laundry is done

Post by waaren »

pgielen wrote: Wednesday 27 March 2019 23:05 I read the thread about sensing wether a washing machine had finished by measuring the energy use. Since I don't have an energy meter in my Domoticz setup, but I do have a Z-Wave flood sensor on the washing machine that also has tamper (= vibration) detection sensor on board, I am looking into another option. I want to use it to detect whether the machine is spinning and, when it has finished, to send a signal that the machine should be emptied.
So how to detect if the machine is spin drying? Here is a part of the vibration sensor log:
As you can see the 'centrifuge' pattern is easily recognizable by about 8 to 10 state changes per minute. The question now is how to implement this in dzvents. A timed routine that checks every second seems the easiest (just a matter of counting), but will put an unnecessary load on the system even if there are no device updates. It must therefore be a device trigger, but then the question is how I can check how many updates occur in a certain period (preferably a minute or 5 to prevent false positive if vibrations occur during filling the machine, or washing, or pumping water, etcetera).

I think I need something like this, in pseudo code:

Code: Select all

If (number_of_devicechanges_within_5_minutes >= 40) then
	print('Washing machine is spinning') 			-- only for testing
	Centrifuge = true
End
If (device.lastupdate.minutes > 5) && (Centrifuge == true) then
	Notify ('The washing machine is ready')
	Centrifuge = false
End
Of course the challenge is how to measure 'number_of_devicechanges_within_5_minutes'.
Using dzVents historical persistent variables feature (described here , you could implement counting of state updates of the vibration sensor like

Code: Select all

 return  {   on =    {  
                        devices     = { 'vibration sensor' }, -- Change to the name of your vibration sensor
                    },

        logging = 
                    {
                        level       = domoticz.LOG_DEBUG,  
                        marker      = 'Count vibration sensor state updates'
                    },
                    
        data = { vibrationStateUpdates = { history = true, maxMinutes = 5 } },

    execute = function(dz, item)
        dz.data.vibrationStateUpdates.add(item.state)
        dz.log("Number of state updates during the last 5 minutes: ".. dz.data.vibrationStateUpdates.size,dz.LOG_DEBUG)
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Re: Using the flood sensor tamper detection to see if the laundry is done

Post by pgielen »

I tried the script. Just noticed that the switch does not always detect all vibrations, so I changed the counter to 15 (for now). I also found out that checking device.lastUpdate does not work, since the script is only triggered by device changes. Because the laundry is always ready about 15 minutes after spin drying, I tried to send a notification with the afterMin(15) function, but for some reason, that doesn't work with dz.notify....

The code is now as follows:

Code: Select all

--
-- Is the laundry ready?
--
 
 return  {   on =    {  
                        devices     = { 'Floodsensor trillingen' }, -- name of my vibration sensor
                    },

    data = { vibrationStateUpdates = { history = true, maxMinutes = 5 } },

    execute = function(dz, item)
        dz.data.vibrationStateUpdates.add(item.state)
        local vibcnt = dz.data.vibrationStateUpdates.size
        print("Status changes in the last 5 minutes: ".. vibcnt)
	    if (vibcnt > 15) then
	        print("Spin drying") 
	        dz.notify('Washingmachine', 'The laundry is done', PRIORITY_LOW, dz.NSS_PUSHOVER).afterMin(15)
           end
   end
}
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest