Im trying to set up a Raspberry Pi with a few 1w-sensors (onboard 1w) and analog inputs.
I have made one bash-script for fetching the temp from the 1w and another python-script for the analog sensors. Both working and showing values in habpanel.
But how can I use my values with rules? I want to control the heating with a script comparing actual temp with a set_tempValue (I made a list-widget with a few temperature values).
I guess I have to write both values to two variables to be able to compare them but how do I do that?
You are comparing strings and that may cause errorsā¦
Do this:
rule "temperature"
when
Item onewiretemp1Value received update
then
var onewiretemp = onewiretemp1.state as Number
var set_temp = set_tempValue.state as Number
if (onewiretemp < set_temp) {
channel4.sendCommand(ON)
} else {
channel4.sendCommand(OFF)
}
end
You donāt need a second condition because if itās not < then it must be >=
Did not work, got an error.
2018-05-03 00:38:27.939 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ātemperatureā: Could not cast 21 to java.lang.Number; line 5, column 23, length 33
This is strange, it works for me
Ok, letās add the toString bits, then:
rule "temperature"
when
Item onewiretemp1Value received update
then
val onewiretemp = onewiretemp1.state.toString as Number
val set_temp = set_tempValue.state.toString as Number
if (onewiretemp < set_temp) {
channel4.sendCommand(ON)
} else {
channel4.sendCommand(OFF)
}
end
rule "temperature"
when
Item onewiretemp1Value received update
then
val onewiretemp = (onewiretemp1.state as DecimalType).intValue
val set_temp = (set_tempValue.state as DecimalType).intValue
if (onewiretemp < set_temp) {
channel4.sendCommand(ON)
} else {
channel4.sendCommand(OFF)
}
end
Still no luck with other than my script with string. I only get an error message that it canāt write 21 (the set_tempValue): Could not cast 21 to java.lang.Number
I changed the missing Value in onewiretemp1Value.state so it isnāt that.
Maybe it is because Iām fetching the temperature with a bash-script and my item is a String.
String onewiretemp1Value āIndoor temp is [%s Ā°C]ā {channel=āexec:command:onewiretemp1:outputā}
The system isnāt going to be big, only a small caravan so I donāt think I will run into any trouble.
rule "temperature"
when
Item onewiretemp1Value received update
then
val onewiretemp = Float.valueOf(onewiretemp1Value.state.toString)
val set_temp = Float.valueOf(set_tempValue.state.toString)
if (onewiretemp < set_temp) {
channel4.sendCommand(ON)
} else {
channel4.sendCommand(OFF)
}
end
This one works Just need to change (onewiretemp1.state.toString) to (onewiretemp1Value.state.toString)
rule "temperature"
when
Item onewiretemp1Value received update
then
val onewiretemp = Float.valueOf(onewiretemp1Value.state.toString)
val set_temp = Float.valueOf(set_tempValue.state.toString)
if (onewiretemp < set_temp) {
channel4.sendCommand(ON)
} else {
channel4.sendCommand(OFF)
}
end
I added the else statement again but only with (onewiretemp > set_temp) to avoid start/stop to often.
rule "temperature"
when
Item onewiretemp1Value received update
then
val onewiretemp = Float.valueOf(onewiretemp1Value.state.toString)
val set_temp = Float.valueOf(set_tempValue.state.toString)
if (onewiretemp < set_temp) {
channel4.sendCommand(ON)
} else if (onewiretemp > set_temp){
channel4.sendCommand(OFF)
}
end
You can add a little offset to prevent that:
The temperature will be within 1c
You can make the offset smaller if you want but I recommend you have one
or you will damage your equipment especially if itās a boiler
rule "temperature"
when
Item onewiretemp1Value received update
then
val onewiretemp = Float.valueOf(onewiretemp1Value.state.toString)
val set_temp = Float.valueOf(set_tempValue.state.toString)
if (onewiretemp < (set_temp - 0.5)) {
channel4.sendCommand(ON)
} else if (onewiretemp > (set_temp + 0.5)){
channel4.sendCommand(OFF)
}
end
That what I did (or thought I did ) with Ā±1 degree?
With set_temp + 0.5 I will have Ā±1,5 degrees?
It is a combination of gas or electric boiler (water) Im not sure what is minimum runtime for the gas boiler but maybe I need 1,5-2 degrees but the problem is that will be 3-4 degree difference and maybe not comfortable? I will try Ā±1 to start with, if runtime is to short I will add 0,5, if thats not enough I might try a ātimerā in my rules.