I’m trying to write a rule to turn a plug on if the temperature in our bedroom is below a certain value.
In the log, I see this:
NetatmoMainStation_Temperature changed from 16.1000003814697265625 °C to 16.200000762939453125 °C
My rule has this:
rule "Electric Blanket"
when
Item NetatmoMainStation_Temperature received update
then
if ( NetatmoMainStation_Temperature.state < 20 ) {
logInfo("Bedroom cold", "Bedroom below 20")
BedroomPlug_Switch.sendCommand(ON)
}
end
But the ‘if’ doesn’t seem to return true.
I also had this before the if statement:
val bedtemp = Integer::parseInt(NetatmoMainStation_Temperature.state.toString)
And changed my if accordingly but that didn’t seem to work either. I’m guessing it’s the fact that the temperature has the degrees C bit on the end so it’s not being seen as a number.
Is there a simple solution or do I need to strip off the first five characters, for example, to get 16.10?
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
2
This thread might help you remove the UoM from the State
You probably need to add .state as Number to your netamo temperature… I had this issue as well.
And then you might need to add |"°C" to the temperature setting.
This is a rule where I use netamo temperature reading… Hopefully it will help:
rule "Automatic control of all skylight windows"
when
Item NetamoIndendoersTemperature 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(!(NetamoIndendoersTemperature.state instanceof Number)) return;
// Calculate which velux to send the ON command to
val Number fTemp = NetamoIndendoersTemperature.state as Number
val Number lux = Node13_SensorLuminance.state as Number
val alarm = alarm_totalalarm.state
var velux = VeluxAlleLuk
// Third table
if(alarm == ON) {
logInfo("debug", "Third table clause. Alarm is ON")
velux = if(fTemp >= 23.0|"°C") 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 < 17){
logInfo("debug", "Second table clause. Lux < 17")
velux = if(fTemp >= 23.0|"°C") VeluxAlleVent else VeluxAlleLuk
}
// First table, we know that alarm isn't ON and we know lux >= 17 so we don't have to test for it here
else {
logInfo("debug", "First table clause")
switch fTemp
{
case fTemp >= 24.5|"°C": velux = VeluxAlleAaben100
case fTemp >= 24.0|"°C": velux = VeluxAlleAaben75
case fTemp >= 23.5|"°C": velux = VeluxAlleAaben50
case fTemp >= 23.0|"°C": velux = VeluxAlleVent
default: velux = VeluxAlleLuk
}
logInfo("debug", "Choose " + velux.name)
}
// Send the command
logInfo("skylight", "Sending ON command to " + velux.name + " because Netamo Temperatur = " + NetamoIndendoersTemperature.state + " Lux = " + Node13_SensorLuminance.state + " and Alarm = " + alarm_totalalarm.state)
velux.sendCommand(ON)
end