Guest User

ventilatiescript

a guest
Jan 23rd, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. -- script_time_ventilatie.lua
  2. local TempHumSensor = 'BG | Temp warmwater'
  3.  
  4. commandArray = {}
  5. if (devicechanged[TempHumSensor]) then -- Only run rest of script when above sensor is updated in Domoticz
  6.  
  7. local PipeTemperatureSensor = 'VIRT | Temp warmwater' --NAME of the virtual sensor that only contains temperature
  8. local TriggerTemperature = 45 --temperature of hotwater pipe where fan should start running
  9. local LowerTriggerTemperature = 35 --temperature of hotwater pipe where fan should STOP running
  10. local FanSwitch = 'FAN3' --name of switch that controls the fan
  11. local BathroomLightswitch = 'BadkamerLicht' --name of switch of bathroomlight
  12. local FanStandardRuntime = 1800 --time (seconds) that fan should run each shower session, 1800 seconds, half an hour
  13. local FanMaxRuntime = 7200 --time (seconds) that fan should run at max before it is stopped (to prevent running endlessly), 3600 seconds, 1 hour
  14. local TempOnlySensor = 536 --idx of the virtual temperature sensor where you want to store only temperature in
  15. DEBUG_MODE = false --set to 'true' (without quotes) if you want to see more messages in Domoticz log
  16.  
  17. print('<font color=#2E9AFE>=========== Ventilatiescript ============</font>')
  18.  
  19. sTemp, sHumidity = otherdevices_svalues[TempHumSensor]:match("([^;]+);([^;]+)")
  20. sTemp = tonumber(sTemp);
  21. sHumidity = tonumber(sHumidity);
  22. commandArray[1] = {['UpdateDevice'] = TempOnlySensor .. '|0|' .. sTemp}
  23.  
  24. --Function to get timedifference (in seconds) since fan has started
  25. function timedifference(s)
  26. year = string.sub(s, 1, 4)
  27. month = string.sub(s, 6, 7)
  28. day = string.sub(s, 9, 10)
  29. hour = string.sub(s, 12, 13)
  30. minutes = string.sub(s, 15, 16)
  31. seconds = string.sub(s, 18, 19)
  32. t1 = os.time()
  33. t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
  34. difference = os.difftime (t1, t2)
  35. return difference
  36. end
  37.  
  38. if DEBUG_MODE == true then
  39. print('<b style="color:Blue">=========== Ventilatiescript ============</b>')
  40. print('Sensorname: ' .. PipeTemperatureSensor)
  41. print('TriggerTemperature ' .. TriggerTemperature)
  42. print('Ondergrens ' .. LowerTriggerTemperature)
  43. print('Huidige leidingtemperatuur: ' .. sTemp)
  44. print('Naam fanschakelaar ' .. FanSwitch)
  45. print('Lichtschakelaar badkamer ' .. BathroomLightswitch)
  46. print('Nalooptijd ' .. FanStandardRuntime)
  47. print('Max looptijd fan ' .. FanMaxRuntime)
  48. --print('Fan ingeschakeld' ..difference 'sec geleden')
  49. end
  50.  
  51. difference = timedifference(otherdevices_lastupdate[FanSwitch])
  52.  
  53. --Turn fan off if someone is showering, turn fan off if conditions become valid
  54. if otherdevices[BathroomLightswitch] == 'On' and otherdevices[FanSwitch] == 'Off' and otherdevices_temperature[PipeTemperatureSensor] >= tonumber (TriggerTemperature) then --someone is showering, turn fan on
  55. commandArray[FanSwitch]='On'
  56. print('<b style="color:Blue">Badkamerlicht is aan, fan is uit, leiding warm genoeg ---> fan aanzetten</b>')
  57. elseif otherdevices[FanSwitch] == 'On' and otherdevices_temperature[PipeTemperatureSensor] <= tonumber (LowerTriggerTemperature) and (difference > FanStandardRuntime) then --fan is running but pipe has cooled down below minThreshold and fan has been running for 30min, turn fan off
  58. commandArray[FanSwitch]='Off'
  59. print('<b style="color:Blue">Fan is aan, maar warmwaterleiding afgekoeld en fan heeft nalooptijd erop zitten ---> Fan uitzetten</b>')
  60. elseif otherdevices[FanSwitch] == 'On' and (difference > FanMaxRuntime) then --Fan has exceeded max runtime, turn fan off
  61. commandArray[FanSwitch]='Off'
  62. print('<b style="color:Blue">Fan is aan, maar maximum draaitijd is verstreken ---> Fan uitzetten</b>')
  63. end
  64.  
  65. end --end of first 'if' line
  66.  
  67. return commandArray
Advertisement
Add Comment
Please, Sign In to add comment