Page 2 of 6

Re: Create a Event or Lua to get push notification when dish

Posted: Friday 17 April 2015 21:46
by ThinkPad
I took some time to rewrite it to a more 'logical' version:

script_time_washingmachine.lua

Code: Select all

-- The name of the virtual washing machine switch
local switch_washingmachine = 'virt_wasmachine'
commandArray = {}

--If actual consumption of measured by Z-Wave plug is higher than or equal to 4W, washingmachine is on
if (otherdevices_svalues['Actual_wasmachine'] >= '4' and otherdevices[switch_washingmachine] == 'Off') then
   commandArray[switch_washingmachine]='On'
   print('Wasmachine staat AAN')   
   commandArray['Variable:washingmachine_dummyCounter']='10' 
else 
	if (otherdevices_svalues['Actual_wasmachine'] < '3' and otherdevices[switch_washingmachine] == 'On') then
      commandArray['Variable:washingmachine_dummyCounter']=tostring(math.max(uservariables['washingmachine_dummyCounter'] - 1, 0))
  end
end  

if (otherdevices[switch_washingmachine] == 'On' and uservariables['washingmachine_dummyCounter'] == 0) then
   print('Wasmachine is KLAAR')
   commandArray['SendNotification']='Wasmachine#Wasmachine is klaar!#0'
   commandArray[switch_washingmachine]='Off'
end   

return commandArray
(Credits for the basic 'structure' of the script go to nickyb2, who is always great in helping me out)

What you need:
- A virtual switch ('virt_wasmachine')
- A user variable ('wasmachine_dummyCounter')

How it works:
It checks if the power usage is higher than or equal to 4W, if yes: washing machine is on. It will set the virtual switch to on and set the counter (user variable) to a defined value.
It will then check if the virtual switch is on and get the counter value and updates the counter with the value MINUS 1 (this is a sort of timer, because the script will be initiated every minute).
If the counter reaches zero and the virtual switch = on then send a pushmessage and turn switch off

First test with a lightbulb worked fine, after about 5 minutes after turning off the light i received a message.
The value (>10W) and the time (5 minutes) are values i have to measure in real life, and adjust the script to. I don't know how much Watt my washing machine uses when it is waiting (between spinning, heating and pumping). I also don't know how much time it will 'wait' while doing this. But i can just measure it :)

I also don't know if the 'if/elseif/else' structure is correct. I first left out the last 'else', but then i got errors.

Re: Create a Event or Lua to get push notification when dish

Posted: Friday 17 April 2015 22:44
by ropske
if your script is working fine for your application, i'm glad your you ;-)
mine is working ok for my application ;-)

if you need any help, please ask.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Saturday 25 April 2015 12:45
by ThinkPad
Today the washing machine is on, and i already received 8 pushnotifications... but the washing machine is still runing....
So my script is not good yet...

Will try and see if i can adjust it

Re: Pushnotification when dishwasher/washing machine is read

Posted: Saturday 25 April 2015 12:57
by tlpeter
I think it now has some data which you can look back on how much it used.
I guess the lowest usage will be when it is doing very little like letting out water.
You could measure the time if the usage is too low to use.
Then build a script which uses usage and time.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Saturday 25 April 2015 13:04
by ThinkPad
Downside is that the graphs in Domoticz accumulate data by every 5 minutes... So my graph jumps from 10:40 to 10:45. This makes it harder to determine what the washing machine was doing.

But it seems that when it is 'idle' (not pumping, heating water, or tumbling) it uses 3W. This always takes under a minute

Re: Create a Event or Lua to get push notification when dish

Posted: Saturday 30 May 2015 21:53
by matthijs
ThinkPad wrote:I took some time to rewrite it to a more 'logical' version:

script_time_washingmachine.lua

Code: Select all

-- The name of the virtual washing machine switch
local switch_washingmachine = 'virt_wasmachine'
commandArray = {}

--If actual consumption of measured by Z-Wave plug is higher than or equal to 4W, washingmachine is on
if (otherdevices_svalues['Actual_wasmachine'] >= '4' and otherdevices[switch_washingmachine] == 'Off') then
   commandArray[switch_washingmachine]='On'
   print('Wasmachine staat AAN')   
   commandArray['Variable:washingmachine_dummyCounter']='10' 
else 
	if (otherdevices_svalues['Actual_wasmachine'] < '3' and otherdevices[switch_washingmachine] == 'On') then
      commandArray['Variable:washingmachine_dummyCounter']=tostring(math.max(uservariables['washingmachine_dummyCounter'] - 1, 0))
  end
end  

if (otherdevices[switch_washingmachine] == 'On' and uservariables['washingmachine_dummyCounter'] == 0) then
   print('Wasmachine is KLAAR')
   commandArray['SendNotification']='Wasmachine#Wasmachine is klaar!#0'
   commandArray[switch_washingmachine]='Off'
end   

return commandArray
(Credits for the basic 'structure' of the script go to nickyb2, who is always great in helping me out)

What you need:
- A virtual switch ('virt_wasmachine')
- A user variable ('wasmachine_dummyCounter')

How it works:
It checks if the power usage is higher than or equal to 4W, if yes: washing machine is on. It will set the virtual switch to on and set the counter (user variable) to a defined value.
It will then check if the virtual switch is on and get the counter value and updates the counter with the value MINUS 1 (this is a sort of timer, because the script will be initiated every minute).
If the counter reaches zero and the virtual switch = on then send a pushmessage and turn switch off

First test with a lightbulb worked fine, after about 5 minutes after turning off the light i received a message.
The value (>10W) and the time (5 minutes) are values i have to measure in real life, and adjust the script to. I don't know how much Watt my washing machine uses when it is waiting (between spinning, heating and pumping). I also don't know how much time it will 'wait' while doing this. But i can just measure it :)

I also don't know if the 'if/elseif/else' structure is correct. I first left out the last 'else', but then i got errors.
I tried this script with my washing machine, but I got also a lot of notifications. After checking the lua documentation (I'm not a real scripter) I discovered the function tonumber(). This converts a string to a number. I think the script was not converting the string correctly to a number (something lua tries to do automatically). Now it's working like a charm. My washing machine has a maximum value of 2 watt when it's on but not in a program and when a program is running the lowest value is 3 watt which is easy to program. I added the code with tonumber() added.

Code: Select all

local switch_washingmachine = 'virt_wasmachine'
commandArray = {}

--If actual consumption of measured by Z-Wave plug is higher than 2W, washingmachine is on
if (tonumber(otherdevices_svalues['Wasmachine'])) > 2.0 and otherdevices[switch_washingmachine] == 'Off' then
   commandArray[switch_washingmachine]='On'
   print('Wasmachine staat AAN')   
   else 
   if (tonumber(otherdevices_svalues['Wasmachine'])) <= 2.0 and otherdevices[switch_washingmachine] == 'On' then
      print('Wasmachine is KLAAR')
	  commandArray['SendNotification']='Wasmachine#Wasmachine is klaar!#0'
	  commandArray[switch_washingmachine]='Off'
  end
end  

return commandArray

Re: Pushnotification when dishwasher/washing machine is read

Posted: Sunday 31 May 2015 10:58
by ThinkPad
Thanks, will try it again soon.

Script has a high WAF (Wife Acceptance Factor) so would be nice if i could get it working reliable.

But i'm not sure, because it seems you don't use the counter part. I think i need that, because the washing machine has the same low usage when it is waiting between rotating the other way round as when it is done with everything.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Sunday 31 May 2015 14:33
by matthijs
I suppose you can just use your script and add the tonumber() function and use the timer. I noticed that that right values where there, but the equation was not always done right. If lua can't read the value as a number it is nill. That is always lower than 2 or 3 watt so the script thinks the washing machine is ready. It's strange because lua normally transforms this automatically but in this case it doesn't.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Monday 01 June 2015 20:59
by Plaagje
Thanks for the script,

i changed it a bit,,, check it out:

Code: Select all

commandArray = {}

sWasmachine = otherdevices_svalues['Wasmachine']:match("([^;]+)")
sWasmachine = tonumber(sWasmachine);
print("Wasmachine: Wasmachine load is: " .. sWasmachine .. " ");

--If actual consumption of measured by Z-Wave plug is higher than 2W, washingmachine is on
if sWasmachine > 2.0 and otherdevices['switch_washingmachine'] == 'Off' then
	commandArray['switch_washingmachine']='On'
	print('Wasmachine staat AAN')   
   
   elseif sWasmachine <= 2.0 and otherdevices['switch_washingmachine'] == 'On' then
		print('Wasmachine is KLAAR')
		commandArray['SendNotification']='Wasmachine#Wasmachine is klaar!#0'
		commandArray['switch_washingmachine']='Off'
end

return commandArray
name is script_device_Wasmachine.lua

I have a Fibaro wall switch (the small one with the led ring), and it gives me 3 devices, 1 switch and 2 energy devices,,, i named the energy device that showed the power usage Wasmachine and i created the virtual switch as mentioned above.

Re: Create a Event or Lua to get push notification when dish

Posted: Monday 01 June 2015 21:04
by Plaagje
matthijs wrote: commandArray[switch_washingmachine]=
should be:

commandArray['switch_washingmachine']=

dont forget the quotes ;-)

Re: Pushnotification when dishwasher/washing machine is read

Posted: Wednesday 03 June 2015 9:48
by matthijs
Plaagje wrote:dont forget the quotes
Thank you for cleaning up the script. My coding skills aren't that good but I try and learn. I made switch_washingmachine local, because my real switch is called virt_wasmachine ( I used the script Thinkpad provided and edited it after I got the same problem with the push notifications). I thought you don't need the quotes when you make it local, but your script is much cleaner.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Friday 19 June 2015 11:17
by ivom74
Which energy reading device you used ?

Re: Pushnotification when dishwasher/washing machine is read

Posted: Sunday 28 June 2015 12:15
by ThinkPad

Re: Pushnotification when dishwasher/washing machine is read

Posted: Tuesday 25 August 2015 23:06
by NiklasO
This is my solution using Blockly. Works every time and no dual notifications.
blockly.png
blockly.png (58.37 KiB) Viewed 6941 times
I use a virtual device to see if the machine is running a program or not, great for visible confirmation:
Namnlös.png
Namnlös.png (19.52 KiB) Viewed 6941 times
Over 2,2W: washing machine running a program.
1,8W or less: washing machine not running a program or off/stand-by.

You mileage may vary. ;)

Re: Pushnotification when dishwasher/washing machine is read

Posted: Wednesday 26 August 2015 8:05
by ThinkPad
My washingmachine uses the same when it is waiting before reversing spinning direction as when it is totally done. So a solution like your Blockly isn't going to work for me :(

Re: Pushnotification when dishwasher/washing machine is read

Posted: Monday 02 November 2015 14:19
by djoeney
ThinkPad wrote:My washingmachine uses the same when it is waiting before reversing spinning direction as when it is totally done. So a solution like your Blockly isn't going to work for me :(
Thinkpad can you confirm the script is running stable? with the version you applied above?

Re: Pushnotification when dishwasher/washing machine is read

Posted: Monday 02 November 2015 14:23
by ThinkPad
I am not using it, couldn't get this working because of the reason you quoted in your post.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Monday 02 November 2015 14:53
by djoeney
To bad, is has a high WAF. Like you mentioned. I'm hoping to get this stable with my wash machine.

Re: Pushnotification when dishwasher/washing machine is read

Posted: Monday 02 November 2015 16:14
by D'rMorris
You can still use the script, you just would need to add a timeout to it.
I assume the washing machine needs perhaps 10 seconds or so to go into reverse spinning mode, so if you add another clause to the script, you can circumvent that issue.
For example, create a uservariable called "dishwasher_timeout" and fill in the timeout that the dishwasher needs to reverse.
Then, in your code check whether this timeout has passed with a function, like this:

Code: Select all

print('<b style="color:Blue">>   Monitoring Dishwasher</b>')

------------- Begin time functions -------------

function timedifference_dishwasher (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_dishwasher = os.difftime (t1, t2)
  return difference_dishwasher
end

------------- End time functions -------------


------------- Begin local variables -------------

-- Debug variables:
debug                   = uservariables["debug_general"]
dishwasher_timeout      = uservariables["dishwasher_timeout"]
difference_dishwasher   = timedifference_dishwasher(otherdevices_lastupdate['dishwasher_on_off_switch'])

------------- End local variables -------------


------------- Begin debug statements -------------

if debug=="Y" 
  then
  print('<b style="color:Red">>> Debug is set to: ' .. debug .. '</b>')
  print('<b style="color:Red">>> Dishwasher timeout is set to: ' .. dishwasher_timeout .. '</b>')
end

------------- End debug statements -------------


------------- Begin code -------------

if (otherdevices['PowerUsageDishwasher'] >= '2' and 
    difference_dishwasher > dishwasher_timeout)
    then
        action
    else
        print('<b style="color:Red">>> Dishwasher still running. Dishwasher last seen: ' .. difference_dishwasher .. ' seconds ago</b>')
    end

------------- End code -------------

Re: Pushnotification when dishwasher/washing machine is read

Posted: Monday 02 November 2015 16:28
by djoeney
Thanks Can't wait for my order to get delivered. Will post the outcome when done!