Need help with rule (Velux windows controlled from outside temp, alarm and Lumiance), now optimizing

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).

Probably.

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)
    }

Inserted into the rule… But I just discovered a typo mistake in second table:

else if(lux < 100) velux = if(fTemp >= 22) VeluxAlleVent else VelusAlleLuk

Last command, it says 'VelusAlleLuk (should have been VeluxAlleLuk)…

But that should not be a reason for executing the VeluxAlleVent, or??

I´ll leave it there for now (the typo mistake) just to see how the debug logging tells us.

Hmm… Netamo just updated, so we have a debugging:

2018-08-16 23:45:14.858 [INFO ] [eclipse.smarthome.model.script.debug] - Second table clause
2018-08-16 23:45:14.877 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleVent because Temp = 20 ℃  Lux = 0 and Alarm = OFF

2018-08-16 23:45:14.883 [ome.event.ItemCommandEvent] - Item 'VeluxAlleVent' received command ON

I guess it does execute second table, and choose the “wrong” command, due to the typo mistake…

I´ll change the typo mistake now, and then lets see again in aprox 8 minutes:

Now I´m confused. I edited the typo mistake. But it still execute VeluxAlleVent, second table.

2018-08-16 23:55:15.791 [INFO ] [eclipse.smarthome.model.script.debug] - Second table clause
2018-08-16 23:55:15.810 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleVent because Temp = 19.8999996185302734375 ℃  Lux = 0 and Alarm = OFF
2018-08-16 23:55:20.052 [INFO ] [ding.velux.bridge.VeluxBridgeExecute] - execute() finished successfully.

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
logInfo("NetamoTemp", NetamoUdendoersTemperature.state.toString)

Ahh, so close :slight_smile:

Could you please post your items definition for

  • NetamoUdendoersTemperature
  • Node13_SensorLuminance
  • alarm_totalalarm
  • dummy1
  • Override
  • VeluxAlleAaben100
  • VeluxAlleAaben75
  • VeluxAlleAaben50
  • VeluxAlleVent
  • VeluxAlleLuk
    (or in other words, all Items, which are used in the rule)?

This is the result after adding the loginfo…

2018-08-17 18:59:45.600 [INFO ] [se.smarthome.model.script.NetamoTemp] - 25.8999996185302734375 ℃
2018-08-17 18:59:45.609 [INFO ] [g.eclipse.smarthome.model.script.Lux] - 499
2018-08-17 18:59:45.615 [INFO ] [eclipse.smarthome.model.script.Alarm] - OFF
2018-08-17 18:59:45.622 [INFO ] [eclipse.smarthome.model.script.debug] - First table clause
2018-08-17 18:59:45.634 [INFO ] [eclipse.smarthome.model.script.debug] - Choose VeluxAlleAaben100
2018-08-17 18:59:45.651 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleAaben100 because Temp = 25.8999996185302734375 ℃  Lux = 499 and Alarm = OFF

2018-08-17 18:59:45.656 [ome.event.ItemCommandEvent] - Item 'VeluxAlleAaben100' received command ON

This seems to be correct. Lux above 100, fTemp above 25, Alarm is OFF, all windows open 100%.

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?

Sure, no problem:

Number:Temperature 	NetamoUdendoersTemperature		"Netamo Udendørs Temperatur"								<cu_heating> 	(Temperatur)	{ channel="netatmo:NAModule1:16451b76:0200002741f4:Temperature" }
Number  ZWaveNode5ZW100MultiSensor6_SensorLuminance 				"Multisensor6 Lumiance Sensor [%.0f Lux]"   				<Light>  	(gLumiance)		{channel="zwave:device:fef78fef:node5:sensor_luminance"} 
Switch alarm_totalalarm "IHC Total alarm tilkoblet"							<switch> 	(alarm) 				 		 {ihc="3144722"} 
Switch dummy1	"Dummy switch for triggering automatic windows rule" (WallSwitch)
Switch Override	"Override switch for turning automatic windows rule ON/OFF. ON = Override " (WallSwitch)
Switch  VeluxAlleLuk "Luk alle vinduer"   (gV) 				{ channel="velux:scene:9b47bbbd:Alle_vinduer_luk:action", autoupdate="false" }
Switch  VeluxAlleAaben50 "Åben alle vinduer 50%" (gV) 			{ channel="velux:scene:9b47bbbd:Alle_vinduer__bne_50:action", autoupdate="false" }
Switch  VeluxAlleAaben75 "Åben alle vinduer 75%" (gV) 			{ channel="velux:scene:9b47bbbd:Alle_vinduer_75:action", autoupdate="false" }
Switch  VeluxAlleAaben100 "Åben alle vinduer 100%" (gV) 		{ channel="velux:scene:9b47bbbd:Alle_vinduer_aaben_100:action", autoupdate="false" }
Switch  VeluxAlleVent "Sæt alle vinduer på ventilation" (gV) 		{ channel="velux:scene:9b47bbbd:Alle_vinduer_vent:action", autoupdate="false" }

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.

Not if it is cast as a Number into a variable as it is the case here.
Add a logInfo for fTemp just to check.

This is very weird…

First, nothing happened untill Lux reached below 100:

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.

As Vincent suggested, log out the value of fTemp. This is the value that is actually being compared to.

I´m not sure what you or Vincent mean. But isn´t this, what Vincent suggested ??

logInfo("NetamoTemp", NetamoUdendoersTemperature.state.toString)

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?

2018-08-17 21:58:51.708 [INFO ] [se.smarthome.model.script.NetamoTemp] - 18 ℃

Since this is the Netamo binding doing this, I don´t see how I can remove it. But I have quite a few other temperature sensors I can give a try.

I just changed the rule to use the temperature sensor in our living room insted.

This is what happened, (had to set lux to less than 0, because its dark outside now).

2018-08-17 22:08:38.764 [ome.event.ItemCommandEvent] - Item 'dummy1' received command OFF
2018-08-17 22:08:38.773 [vent.ItemStateChangedEvent] - dummy1 changed from ON to OFF
2018-08-17 22:08:43.184 [INFO ] [pse.smarthome.model.script.StuenTemp] - 25.00
2018-08-17 22:08:43.190 [INFO ] [g.eclipse.smarthome.model.script.Lux] - 0
2018-08-17 22:08:43.195 [INFO ] [eclipse.smarthome.model.script.Alarm] - OFF
2018-08-17 22:08:43.201 [INFO ] [eclipse.smarthome.model.script.debug] - First table clause
2018-08-17 22:08:43.208 [INFO ] [eclipse.smarthome.model.script.debug] - Choose VeluxAlleAaben100
2018-08-17 22:08:43.220 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleAaben100 because Temp = 25.00  Lux = 0 and Alarm = OFF

2018-08-17 22:08:43.226 [ome.event.ItemCommandEvent] - Item 'VeluxAlleAaben100' received command ON
2018-08-17 22:08:47.303 [INFO ] [ding.velux.bridge.VeluxBridgeExecute] - execute() finished successfully.

This looks right… And while writing this message… This happened:

2018-08-17 22:11:05.473 [vent.ItemStateChangedEvent] - stue_Temperature changed from 25.00 to 24.90
2018-08-17 22:11:05.504 [INFO ] [pse.smarthome.model.script.StuenTemp] - 24.90
2018-08-17 22:11:05.510 [INFO ] [g.eclipse.smarthome.model.script.Lux] - 0
2018-08-17 22:11:05.514 [INFO ] [eclipse.smarthome.model.script.Alarm] - OFF
2018-08-17 22:11:05.522 [INFO ] [eclipse.smarthome.model.script.debug] - First table clause
2018-08-17 22:11:05.532 [INFO ] [eclipse.smarthome.model.script.debug] - Choose VeluxAlleAaben75
2018-08-17 22:11:05.548 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleAaben75 because Temp = 24.90  Lux = 0 and Alarm = OFF
2018-08-17 22:11:05.553 [ome.event.ItemCommandEvent] - Item 'VeluxAlleAaben75' received command ON
2018-08-17 22:11:09.644 [INFO ] [ding.velux.bridge.VeluxBridgeExecute] - execute() finished successfully.

VeluxAlleAaben75… Due to temperature beeing below 25 degrees. This seems to be working just as it should…

So I´m pretty sure, using the Netamo value is NOT a good idea.

EDIT:
just to make sure… I changed the criteria of Lux to < 30. And then triggered the rule manually again… This happened:

2018-08-17 22:16:47.147 [ome.event.ItemCommandEvent] - Item 'dummy1' received command ON
2018-08-17 22:16:47.171 [vent.ItemStateChangedEvent] - dummy1 changed from OFF to ON
2018-08-17 22:16:49.338 [INFO ] [pse.smarthome.model.script.StuenTemp] - 24.70
2018-08-17 22:16:49.344 [INFO ] [g.eclipse.smarthome.model.script.Lux] - 0
2018-08-17 22:16:49.348 [INFO ] [eclipse.smarthome.model.script.Alarm] - OFF
2018-08-17 22:16:49.353 [INFO ] [eclipse.smarthome.model.script.debug] - Second table clause
2018-08-17 22:16:49.369 [INFO ] [ipse.smarthome.model.script.skylight] - Sending ON command to VeluxAlleVent because Temp = 24.70  Lux = 0 and Alarm = OFF
2018-08-17 22:16:49.374 [ome.event.ItemCommandEvent] - Item 'VeluxAlleVent' received command ON
2018-08-17 22:16:53.484 [INFO ] [ding.velux.bridge.VeluxBridgeExecute] - execute() finished successfully.

I´m convinced… Don´t use Netamo temperature values in a rule.