Hello!
I add boiler control to a smart home. Temperature sensor d18b20 is connected to GPIO pin4, relay is connected to GPIO pin6. The temperature is shown, the relay is manually switched. But the rules don’t work.
//Settings
Number Temperature_min “Min temp[%2.1f °C]”
Number Temperature_max “Max temp[%2.1f °C]”
rules file:
rule “Controll boiler”
when
Item TempBoiler changed
or
Item Temperature_min changed
or
Item Temperature_max changed
then
if (TempBoiler.state >= Temperature_max.state) channel1.sendCommand(OFF)
else if (TempBoiler.state <= Temperature_min.state) channel1.sendCommand(ON)
end
05:11:00.412 [WARN ] [.sitemap.internal.SitemapProviderImpl] - Filename onewire .sitemap does not match the name Home of the sitemap - please fix this as you might see unexpected behavior otherwise.
05:11:00.611 [WARN ] [.sitemap.internal.SitemapProviderImpl] - Filename onewire .sitemap does not match the name Home of the sitemap - please fix this as you might see unexpected behavior otherwise.
05:11:02.281 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘channel1’ r eceived command ON
05:11:02.288 [INFO ] [smarthome.event.ItemStateChangedEvent] - channel1 changed from OFF to ON
05:11:02.651 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘channel1’ r eceived command OFF
05:11:02.659 [INFO ] [smarthome.event.ItemStateChangedEvent] - channel1 changed from ON to OFF
05:11:07.022 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler change d from 30.187 °C to 30.250 °C
05:19:27.526 [WARN ] [.sitemap.internal.SitemapProviderImpl] - Filename onewire.sitemap does not match the name Home of the sitemap - please fix this as you might see unexpected behavior otherwise.
05:19:28.361 [WARN ] [.sitemap.internal.SitemapProviderImpl] - Filename onewire.sitemap does not match the name Home of the sitemap - please fix this as you might see unexpected behavior otherwise.
05:19:29.173 [WARN ] [.sitemap.internal.SitemapProviderImpl] - Filename onewire.sitemap does not match the name Home of the sitemap - please fix this as you might see unexpected behavior otherwise.
05:19:29.338 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.312 °C to 30.250 °C
05:19:29.339 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Upravlenie rele po temperature’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_greaterEqualsThan(org.eclipse.smarthome.core.types.Type,java.lang.Number) on instance: null
05:19:36.376 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Temperature_max’ received command 85.0
05:19:36.384 [INFO ] [smarthome.event.ItemStateChangedEvent] - Temperature_max changed from NULL to 85.0
05:19:36.389 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Upravlenie rele po temperature’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_lessEqualsThan(org.eclipse.smarthome.core.types.Type,java.lang.Number) on instance: null
05:19:38.513 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Temperature_min’ received command 10.0
05:19:38.527 [INFO ] [smarthome.event.ItemStateChangedEvent] - Temperature_min changed from NULL to 10.0
05:19:41.021 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.250 °C to 30.312 °C
Fixed all errors in the Log. But the problem remained. The rules don’t understand that the relay needs to be switched.
06:31:30.098 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model ‘home.rules’
06:31:37.878 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.937 °C to 31.000 °C
06:31:49.558 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 31.000 °C to 30.937 °C
06:32:11.636 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Temperature_max’ received command 28.0
06:32:11.653 [INFO ] [smarthome.event.ItemStateChangedEvent] - Temperature_max changed from 33.0 to 28.0
06:32:18.838 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.937 °C to 30.875 °C
06:32:36.359 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.875 °C to 30.937 °C
06:32:42.199 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.937 °C to 30.875 °C
06:32:48.119 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.875 °C to 30.937 °C
06:32:59.798 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.937 °C to 30.875 °C
06:33:29.077 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.875 °C to 30.812 °C
06:33:34.918 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.812 °C to 30.875 °C
06:33:58.278 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.875 °C to 30.812 °C
06:34:04.123 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.812 °C to 30.875 °C
06:34:45.080 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.875 °C to 30.812 °C
06:34:50.999 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.812 °C to 30.875 °C
06:35:31.961 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.875 °C to 30.812 °C
06:35:31.992 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Temperature_min’ received command 33.0
06:35:32.006 [INFO ] [smarthome.event.ItemStateChangedEvent] - Temperature_min changed from 10 to 33.0
06:35:36.431 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Temperature_max’ received command 39.0
06:35:36.447 [INFO ] [smarthome.event.ItemStateChangedEvent] - Temperature_max changed from 28.0 to 39.0
06:35:37.799 [INFO ] [smarthome.event.ItemStateChangedEvent] - TempBoiler changed from 30.812 °C to 30.875 °C
06:35:50.970 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Temperature_min’ received command 10.0
06:35:50.985 [INFO ] [smarthome.event.ItemStateChangedEvent] - Temperature_min changed from 33.0 to 10.0
I think the problem is that TempBoiler is of type Number:Temperature, but Temperature_min and Temperature_max is just Number type. Try changing the rule to:
rule “Controll boiler”
when
Item TempBoiler changed
or
Item Temperature_min changed
or
Item Temperature_max changed
then
if (TempBoiler.state.floatValue >= Temperature_max.state.floatValue)
channel1.sendCommand(OFF)
else if (TempBoiler.state.floatValue <= Temperature_min.state.floatValue)
channel1.sendCommand(ON)
end
07:45:50.838 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Controll boiler’: ‘floatValue’ is not a member of ‘org.eclipse.smarthome.core.types.State’; line 10, column 8, length 27
if ((TempBoiler.state as Number).floatValue >= (Temperature_max.state as Number).floatValue)
channel1.sendCommand(OFF)
else if ((TempBoiler.state as Number).floatValue <= (Temperature_min.state as Number).floatValue)
channel1.sendCommand(ON)
end
You could create a Boiler_Master_Switch Switch Item and check whether it’s OFF at the beginning of the rule:
if (Boiler_Master_Switch.state == OFF) {
return;
}
The return keyword makes the rule exit immediately, so the rest of it only executes if the master switch is not off. What you need to think about is how to handle if the switch is NULL or UNDEF. In this case the boiler works as normal if OH is restarted unexpectedly. If you change to:
if (Boiler_Master_Switch.state != ON) {
return;
}
It will always appear as off until the item gets a valid state, which could prevent your heating from working in case of a restart, unless you create startup rules to handle that (or use persistence with RestoreOnStartup).
Then you might also want another rule to make the channel1 switch turn off immediately when the master switch is turned off.
I’ll leave most of the writing up to you however, it’s the best way to learn, but just ask if you encounter any problems.
add another item type Switch (eg. BoilerPower) and add a check in the rule if this is ON or OFF
if (BoilerPower.state == ON) {
// __ your curernt IF statement __
} else {
if (channel1.state != OFF) channel1.sendCommand(OFF) // turn off boiler
}
You can also go further and instead of using it as Switch, you can change it to Number and set different states:
Items:
Number BoilerPower
Rules:
switch BoilerPower.state.toString {
case "0" :{ // OFF Manual
if (channel1.state != OFF) channel1.sendCommand(OFF)
}
case "1" :{ // ON Manual
if (channel1.state != ON) channel1.sendCommand(ON)
}
case "2" :{ // Automatic controll
// __Your IF block __
}
default :{ // If the value is unknown, set the mode to Auto
BoilerPower.postUpdate(2)
}
}
Problem! When the boiler is turned off, it turns off, but it is turned on by the temperature rule.
Sorry, but I’m still a beginner.))
Rules:
rule “Controll boiler”
when
Item TempBoiler changed
or
Item Temperature_min changed
or
Item Temperature_max changed
then
if ((TempBoiler.state as Number).floatValue >=(Temperature_max.state as Number).floatValue) channel1.sendCommand(OFF)
else if ((TempBoiler.state as Number).floatValue <=(Temperature_min.state as Number).floatValue) channel1.sendCommand(ON)
end
rule “Boiler power”
when
Item BoilerPower changed
then
switch BoilerPower.state.toString {
case “0” :{
if (channel1.state != OFF) channel1.sendCommand(OFF)
}
case “1” :{
if (channel1.state != ON) channel1.sendCommand(ON)
}
}
end
With your setup it is expected behavior. You have one rule that will change the state of the boiler and another rule that automatically turns the boiler on/off based ONLY on temperature and doesn’t rely on the state setting.
I would combine it all into one rule.
rule "Boiler control"
when
Item TempBoiler changed or
Item Temperature_min changed or
Item Temperature_max changed or
Item BoilerPower changed
then
switch BoilerPower.state.toString {
case "0" :{
if (channel1.state != OFF) channel1.sendCommand(OFF)
}
case "1" :{
if (channel1.state != ON) channel1.sendCommand(ON)
}
case "2" :{
if ((TempBoiler.state as Number).floatValue >=(Temperature_max.state as Number).floatValue) {
if (channel1.state != OFF) channel1.sendCommand(OFF)
} else if ((TempBoiler.state as Number).floatValue <=(Temperature_min.state as Number).floatValue) {
if (channel1.state != ON) channel1.sendCommand(ON)
}
default :{
BoilerPower.postUpdate(2)
}
}
end
Ready option. Maybe someone will come in handy. Of course, there may still be something to improve, but it does its own thing. In the future, I will add a water pressure sensor for emergency shutdown.
//Settings
Switch channel1 “Boiler” { gpio=“pin:6 activelow:yes initialValue:high” }
Number Temperature_min “Min temperature[%2.1f °C]”
Number Temperature_max “Max temperature[%2.1f °C]”
Rules:
rule “Boiler control”
when
Item TempBoiler changed or
Item Temperature_min changed or
Item Temperature_max changed or
Item BoilerPower changed
then
switch BoilerPower.state.toString {
case “0” :{
if (channel1.state != OFF) channel1.sendCommand(OFF)
}
case “1” :{
if ((TempBoiler.state as Number).floatValue >=(Temperature_max.state as Number).floatValue) {
if (channel1.state != OFF) channel1.sendCommand(OFF)
} else if ((TempBoiler.state as Number).floatValue <=(Temperature_min.state as Number).floatValue) {
if (channel1.state != ON) channel1.sendCommand(ON)
}
//default :{
BoilerPower.postUpdate(1)
}
}
end