Re: The ITHO ECO-FAN 2P
Posted: Sat Jun 08, 2013 7:15 pm
Irritanterik, how did it go? I would like exactely the same!
Domotica - Home Automation Forum
https://www.domoticaforum.eu/
Code: Select all
'20140215 EvD Ventilation Control Script Version 2
'@TODO: Involve occupancy: if nobody home, then start with fanspeed 'away'
'Virtual Devices:
' V90 - Ventilation control type (Off: 0, Automatic: 1, Manual: 2)
' V91 - Automatic speed (Off: 0, Away: 1, Low: 2, Medium: 3, High: 4)
' V92 - Fan speed (Off: 0, Away: 1, Low: 2, Medium: 3, High: 4)
' V93 - Minutes temporary manual overrule (Off: 0, 1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60)
'Run once after creating virtual devices:
' &hs.DeviceValuesAdd "V90", "Uit" & chr(2) & "0" & chr(1) & "Automatisch" & chr(2) & "1" & chr(1) & "Handmatig" & chr(2) & "2", true
' &hs.DeviceValuesAdd "V91", "Uit" & chr(2) & "0" & chr(1) & "Afwezig" & chr(2) & "1" & chr(1) & "Laag" & chr(2) & "2" & chr(1) & "Middel" & chr(2) & "3" & chr(1) & "Hoog" & chr(2) & "4", false
' &hs.DeviceValuesAdd "V92", "Uit" & chr(2) & "0" & chr(1) & "Afwezig" & chr(2) & "1" & chr(1) & "Laag" & chr(2) & "2" & chr(1) & "Middel" & chr(2) & "3" & chr(1) & "Hoog" & chr(2) & "4", true
' &hs.DeviceValuesAdd "V93", "Uit" & chr(2) & "0" & chr(1) & "1" & chr(2) & "1" & chr(1) & "5" & chr(2) & "5" & chr(1) & "10" & chr(2) & "10" & chr(1) & "15" & chr(2) & "15" & chr(1) & "20" & chr(2) & "20" & chr(1) & "25" & chr(2) & "25" & chr(1) & "30" & chr(2) & "30" & chr(1) & "35" & chr(2) & "35" & chr(1) & "40" & chr(2) & "40" & chr(1) & "45" & chr(2) & "45" & chr(1) & "50" & chr(2) & "50" & chr(1) & "55" & chr(2) & "55" & chr(1) & "60" & chr(2) & "60", true
Const LogLevel As Integer = 0 '0 = no logging, 1 = normal logging, 2 = debug logging
Const ScriptName As String = "TON_FanUpdate"
Const cControlTypeDeviceCode As String = "V90"
Const cAutoDefaultDeviceCode As String = "V91"
Const cFanSpeedDeviceCode As String = "V92"
Const cTempOverruleDeviceCode As String = "V93"
Const cFanPowerDeviceCode As String = "^5" 'Plugwise Circle
Const cLowerAutoSpeedDelay As Integer = 10 'Minutes between last change autospeed and new lower speed
Const cFanDefaultSpeed = 2 'Off: 0, Away: 1, Low: 2, Medium: 3, High: 4
Public Sub Main(ByVal Parms As String)
Dim iTempOverruleMinutes As Integer
Dim iHumidityAvg As Integer
Dim iHumidityBath As Integer
Dim iAutoSpeed As Integer
Dim iTempSpeed As Integer
Dim iPreviousAutoSpeed As Integer
'1. Determinate control type based on manual overrule setting
iTempOverruleMinutes = hs.DeviceValue(cTempOverruleDeviceCode)
'Check temp setting is still valid
If iTempOverruleMinutes > 0 And DateAdd("n", iTempOverruleMinutes, hs.DeviceLastChange(cTempOverruleDeviceCode)) < Now Then
hs.SetDeviceValue(cTempOverruleDeviceCode, 0)
'Update controltype
If hs.DeviceValue(cControlTypeDeviceCode) = 2 Then
hs.SetDeviceValue(cControlTypeDeviceCode, 1)
Log("Controltype set back to automatic after temporary overrule.", 1)
End if
End If
'2. Calculate automatic fan speed based on humidity sensors and time
iPreviousAutoSpeed = hs.DeviceValue(cAutoDefaultDevicecode)
'Get (average) humidity from other rooms (now only livingroom) and bathroom
iHumidityAvg = Int(hs.DeviceValue("]4") / 1)
iHumidityBath = hs.DeviceValue("]7")
'Derive automatic status from low to high
iAutoSpeed = cFanDefaultSpeed
'Humidity bathroom above 50% and 5% higher than other rooms
If iHumidityBath > 50 _
And (iHumidityBath/iHumidityAvg-1)*100 > 5 _
Then iAutoSpeed = 3
'Humidity bathroom above 60% and 10% higher than other rooms and not night
If iHumidityBath > 60 _
And (iHumidityBath/iHumidityAvg-1)*100 > 10 _
And Not(Hour(Now()) >= 23) _
And Not(hour(Now()) < 6) _
Then iAutoSpeed = 4
Log("Calculated speed: " & iAutoSpeed & ", previous calculated speed: " & iPreviousAutoSpeed & ", previous change: " & hs.DeviceLastChange(cAutoDefaultDevicecode), 2)
'Update calculated speed if higher than previous calculated speed or
' if calculated speed is lower than previous speed and lastchange is 'cLowerAutoSpeedDelay' minues ago
If iPreviousAutoSpeed < iAutoSpeed _
Or (iPreviousAutoSpeed > iAutoSpeed _
And DateAdd("n", cLowerAutoSpeedDelay, hs.DeviceLastChange(cAutoDefaultDevicecode)) < Now) _
Then
hs.SetDeviceValue (cAutoDefaultDeviceCode, iAutoSpeed )
Log("Automatic speed changed and set to " & iAutoSpeed, 1)
Else
iAutoSpeed = iPreviousAutoSpeed
Log("Automatic speed not changed.", 2)
End If
'3. Update fan speed based on control type
Select Case hs.DeviceValue(cControlTypeDeviceCode)
Case 0
If hs.DeviceValue(cFanSpeedDeviceCode) <> 0 Then
hs.SetDeviceValue (cFanSpeedDeviceCode, 0)
Log("Fan speed set to 0 (off)", 1)
End If
If Not(hs.IsOff(cFanPowerDeviceCode)) Then
hs.ExecX10("^5", "off", 0, 0)
Log("Fan powered off", 2)
End If
Case 1
If hs.IsOff(cFanPowerDeviceCode) Then
Log("Power on fan", 1)
hs.ExecX10("^5", "on", 0, 0)
hs.WaitSecs(10)
End If
hs.SetDeviceValue (cFanSpeedDeviceCode, iAutoSpeed)
Log("Fan speed set to " & iAutoSpeed, 1)
Case Else
If hs.IsOff(cFanPowerDeviceCode) Then
Log("Power on fan", 1)
hs.ExecX10("^5", "on", 0, 0)
iTempSpeed = hs.DeviceValue(cFanSpeedDeviceCode)
if iTempSpeed = 0 Then iTempSpeed = iAutoSpeed
'Force retrigger manual fan speed
hs.SetDeviceValue (cFanSpeedDeviceCode, 0)
hs.WaitSecs(10)
hs.SetDeviceValue (cFanSpeedDeviceCode, iTempSpeed)
End If
End Select
End Sub
Private Sub Log(Message As String, Optional MessageLevel As Integer = 1)
If LogLevel >= MessageLevel Then
hs.WriteLog(ScriptName, Message)
End if
End Sub