Guest User

Untitled

a guest
Dec 24th, 2015
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. --script_time_washingmachine.lua
  2.  
  3. --Change the values below to reflect to your own setup
  4. local washer_status_uservar   = 'washingmachine_status'
  5. local energy_consumption      = 'Clothes Washer Status'         --Name of Z-Wave plug that contains actual consumption of washingmachine (in Watts)
  6. local washer_counter_uservar  = 'washingmachine_counter'        --Name of the uservariable that will contain the counter that is needed
  7. local idle_minutes            = 5                               --The amount of minutes the consumption has to stay below the 'consumption_lower' value
  8. local consumption_upper       = 20                              --If usage is higher than this value (Watts), the washingmachine has started
  9. local consumption_lower       = 4.3                             --If usage is lower than this value (Watts), the washingmachine is idle for a moment/done washing
  10.  
  11. -- sWatt, sTotalkWh              = otherdevices_svalues['Clothes Washer Power Usage']:match("([^;]+);([^;]+)")
  12. -- washer_usage                  = tonumber(sWatt)
  13. washer_usage                  = tonumber(otherdevices_svalues[energy_consumption])
  14.  
  15. commandArray = {}
  16.  
  17. --Virtual switch is off, but consumption is higher than configured level, so washing has started
  18. if (washer_usage > consumption_upper) and uservariables[washer_status_uservar] == 0 then
  19.   commandArray['Variable:' .. washer_status_uservar]='1'
  20.   print('Current power usage (' ..washer_usage.. 'W) is above upper boundary (' ..consumption_upper.. 'W), so washing has started!')
  21.   commandArray['Variable:' .. washer_counter_uservar]=tostring(idle_minutes)
  22. end
  23.  
  24. --Washing machine is not using a lot of energy, check the counter
  25. if (washer_usage < consumption_lower) and uservariables[washer_status_uservar] == 1 then
  26.   commandArray['Variable:' .. washer_counter_uservar]=tostring(math.max(tonumber(uservariables[washer_counter_uservar]) - 1, 0))
  27.   print('Current power usage (' ..washer_usage.. 'W) is below lower boundary (' ..consumption_lower.. 'W), washer is idle or almost ready')
  28.   print('Subtracting counter, old value: ' ..uservariables[washer_counter_uservar].. ' minutes')
  29. elseif ((uservariables[washer_counter_uservar] ~= idle_minutes) and uservariables[washer_status_uservar] == 1) then
  30.   commandArray['Variable:' .. washer_counter_uservar]=tostring(idle_minutes)
  31.   print('Resetting Washing Machine Timer')
  32. end
  33.  
  34. --Washingmachine is done
  35. if ((uservariables[washer_status_uservar] == 1) and uservariables[washer_counter_uservar] == 0) then
  36.   print('Washingmachine is DONE')
  37.   print('Current power usage washingmachine ' ..washer_usage.. 'W')
  38.   print('Washingmachine is done, please go empty it!')
  39.   commandArray['SendNotification']='Cycle Ended: Washing Machine#The load in the washing machine has finsihed, please move it to the dryer!#0'                                        
  40.   commandArray['Variable:' .. washer_status_uservar]='0'
  41. end
  42.  
  43. return commandArray
Advertisement
Add Comment
Please, Sign In to add comment