I just gave the rule a try, and as soon as Netamo updated, windows closed for Ventilation. (they were still open).
2018-08-16 23:24:58.383 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleVent because Temp = 20.3999996185302734375 ℃ Lux = 0 and Alarm = OFF
But I wonder why it closed for ventilation (VeluxAllVent).
I suspect its the second table. But it says fTemp has to be above or equal to 22, VeluxAllVent, else VeluxAllLuk. But fTemp is 20.3 (according to the log above).
OK, so we look and alarm is OFF and lux is under 100 so it should be executing the second table. The temp is under 22 so VelusAlleLuk should have been chosen.
So now is the time to add some logging to figure out what if statement actually executed.
// Third table
if(alarm == ON) {
logInfo("debug", "Third table clause")
velux = if(fTemp >= 22) VeluxAlleLuk else VeluxAlleLuk
}
// Second table, we already know alarm isn't ON so we don't have to test it for OFF here
else if(lux < 100){
logInfo("debug", "Second table clause")
velux = if(fTemp >= 22) VeluxAlleVent else VelusAlleLuk
}
// First table, we know that alarm isn't ON and we know lux >= 100 so we don't have to test for it here
else {
logInfo("debug", "First table clause")
switch fTemp {
case fTemp >= 25: velux = VelusAlleAaben100
case fTemp >= 24: velux = VeluxAlleAaben75
case fTemp >= 23: velux = VeluxAlleAaben50
case fTemp >= 22: velux = VeluxAlleVent
default: velux = VeluxAlleLuk
}
logInfo("debug", "Choose " + velux.name)
}
OK, so we know it is executing the second table. We know it isn’t falling into any of the other tables.
I would have expected to see errors in the log because of the typo. I’m not sure what is going on there, but that wouldn’t be the cause of the error.
So either there is a problem with the if statement or something is not as it seems.
Lets make sure that everything has the value we think it does.
Before all the “tables” add a log statement to log out the values of fTemp, lux and alarm. the log statement at the end is logging the states of the Items but we are using the these variables and there may be something going on between the time we set the variables and when that last log statement runs. We should be logging out the variables in that last log statement anyway but leave it unchanged for now because knowing what fTemp is in particular before the tables and what the Item state is after could be informative (i.e. if they are different we know that the state of NetamoUdendoersTemperature is changing while the Rule is Running.
I don´t know how to insert a log statement for an item like this. I tried many combinations now, but end up with either an error or nothing:
2018-08-17 01:44:01.646 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Automatic control of all skylight windows': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
This is how the rule looks like and given the error above:
rule "Automatic control of all skylight windows"
when
Item NetamoUdendoersTemperature changed or
Item Node13_SensorLuminance changed or
Item alarm_totalalarm changed or
Item dummy1 changed
then
// Exit the rule when there is nothing to do
if(Override.state == ON) return;
if(alarm_totalalarm.state instanceof Switch ) return;
if(!(Node13_SensorLuminance.state instanceof Number)) return;
if(!(NetamoUdendoersTemperature.state instanceof Number)) return;
// Calculate which velux to send the ON command to
val Number fTemp = NetamoUdendoersTemperature.state as Number
val Number lux = Node13_SensorLuminance.state as Number
val alarm = alarm_totalalarm.state
var velux = VeluxAlleLuk
logInfo("NetamoTemp", NetamoUdendoersTemperature)
logInfo("Lux", Node13_SensorLuminance)
logInfo("Alarm", alarm_totalalarm)
// Third table
if(alarm == ON) {
logInfo("debug", "Third table clause")
velux = if(fTemp >= 22) VeluxAlleVent else VeluxAlleLuk
}
// Second table, we already know alarm isn't ON so we don't have to test it for OFF here
else if(lux < 100){
logInfo("debug", "Second table clause")
velux = if(fTemp >= 22) VeluxAlleVent else VeluxAlleLuk
}
// First table, we know that alarm isn't ON and we know lux >= 100 so we don't have to test for it here
else {
logInfo("debug", "First table clause")
switch fTemp {
case fTemp >= 25: velux = VeluxAlleAaben100
case fTemp >= 24: velux = VeluxAlleAaben75
case fTemp >= 23: velux = VeluxAlleAaben50
case fTemp >= 22: velux = VeluxAlleVent
default: velux = VeluxAlleLuk
}
logInfo("debug", "Choose " + velux.name)
}
// Send the command
logInfo("skylight", "Sending ON command to " + velux.name + " because Temp = " + NetamoUdendoersTemperature.state + " Lux = " + Node13_SensorLuminance.state + " and Alarm = " + alarm_totalalarm.state)
velux.sendCommand(ON)
end
Hmmmmm. I wonder if the temperature units is causing problems with the comparison. I’ve not used them in my setup yet. @vzorglub, do we need to do anything special when testing a temperature to a regular old number?
Agree, it seems like when lux is below 100, temperature value does not have any influence. It´s just strange that is does now.
The sun will soon go down now here, so I suspect the temperature will drop within the next few hours while Lux is still above 100. If things are working with the temperature, the windows will start to close in steps (cases from the rule).
Btw whenever this rule is working I will remove the Lux evaluation. This Neo Coolcam sensor is pulling some tricks on the Lux. A few minutes ago it said 0 lux, and few seconds after, it was 499…
I have another solution using a dawn/dusk sensor (I think thats the name in english, but I´m not sure). Its a simple ON/OFF switch.
But I dont want to change anything in the rule right now… Better wait untill the rule is working. From the loginfo it´s easy to tell if the Neo Coolcam is pulling tricks again.
2018-08-17 20:20:49.630 [INFO ] [se.smarthome.model.script.NetamoTemp] - 26.1000003814697265625 ℃
2018-08-17 20:20:49.636 [INFO ] [g.eclipse.smarthome.model.script.Lux] - 53
2018-08-17 20:20:49.641 [INFO ] [eclipse.smarthome.model.script.Alarm] - OFF
2018-08-17 20:20:49.650 [INFO ] [eclipse.smarthome.model.script.debug] - Second table clause
2018-08-17 20:20:49.678 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleVent because Temp = 26.1000003814697265625 ℃ Lux = 53 and Alarm = OFF
2018-08-17 20:20:49.684 [ome.event.ItemCommandEvent] - Item 'VeluxAlleVent' received command ON
The above log does actually as it should, due to fTemp beeing above 25…
I gave it a few thoughts, and changed the criteria of Lux to <1 in second table.
// Second table, we already know alarm isn't ON so we don't have to test it for OFF here
else if(lux < 1){
logInfo("debug", "Second table clause")
velux = if(fTemp >= 22) VeluxAlleVent else VeluxAlleLuk
}
The fTemp is now way below 25 degree, and I triggered the rule from the Dummy1 switch…
Now this happened:
2018-08-17 21:02:04.988 [ome.event.ItemCommandEvent] - Item 'dummy1' received command ON
2018-08-17 21:02:05.018 [vent.ItemStateChangedEvent] - dummy1 changed from OFF to ON
2018-08-17 21:02:07.801 [INFO ] [se.smarthome.model.script.NetamoTemp] - 21.299999237060546875 ℃
2018-08-17 21:02:07.807 [INFO ] [g.eclipse.smarthome.model.script.Lux] - 2
2018-08-17 21:02:07.812 [INFO ] [eclipse.smarthome.model.script.Alarm] - OFF
2018-08-17 21:02:07.818 [INFO ] [eclipse.smarthome.model.script.debug] - First table clause
2018-08-17 21:02:07.827 [INFO ] [eclipse.smarthome.model.script.debug] - Choose VeluxAlleAaben100
2018-08-17 21:02:07.838 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleAaben100 because Temp = 21.299999237060546875 ℃ Lux = 2 and Alarm = OFF
2018-08-17 21:02:07.844 [ome.event.ItemCommandEvent] - Item 'VeluxAlleAaben100' received command ON
This tells me, there is nothing happning from the temperature. It runs from the first table, as it should. But it shouldn´t have executed VeluxAlleAaben100 when the temperature is 21 degrees. It should have send VeluxAlleLuk when temperature is below 22.
Maybe I´m on deep water here, but I´m just thinking. Could this problem be due to the value of the fTemp is not only a number, It also contain the meassuring unit… (degrees), and therefore a string as well? And then Openhab gets confused or something, and ignores it?