Hi All,
I’ve been experimenting with openHAB 2.4 on Windows 10 for a while now, and am starting to have some success controlling things and running rules. I’m not a programmer so I’ve progressed very slowly mostly by hacking around examples from the forums to do what I want. Simple syntax mistakes frequently get me bogged down for ages though and there seems to be some inconsistency between lots of the examples online.
For instance should I use
myTimer.cancel
or
myTimer.cancel()
or or doesn’t it matter?
How about
if(Presence_Status_Away.state == ON){
or
if(Presence_Status_Away.state==ON){
My key confusion at the moment though is to do with testing the state of switch items. I have a bunch of items that I set on or off using the Alexa integration which works fine.
Switch Presence_Status_Home "Home" {alexa="Switchable"}
Switch Presence_Status_Out "Out" {alexa="Switchable"}
Switch Presence_Status_Away "Away" {alexa="Switchable"}
Switch Presence_Status_Bedtime "Bedtime" {alexa="Switchable"}
Home, Out, and Away each have a change rule when they’re turned on that turns the others off.
I then have some time triggered rules that try to do some stuff based on the state of the switches:
if(Presence_Status_Bedtime.state. == ON){
logInfo("PAL", "Night Colour Triggered")
HallLight_Color.sendCommand("320,80,40")
}
else {
HallLight_Color.sendCommand("320,0,80")
logInfo("PAL", "Day Colour Triggered")
} }
This never triggers the night colour, however it will if I do it like this:
if(Presence_Status_Bedtime.state.toString == "ON"){
logInfo("PAL", "Night Colour Triggered")
HallLight_Color.sendCommand("320,80,40")
}
else {
HallLight_Color.sendCommand("320,0,80")
logInfo("PAL", "Day Colour Triggered")
}
I thought the native state of a switch is ON or OFF so I don’t understand why I have to do a string comparison to make this work.
Similarly the Philips Hue light sensor supposedly reports a number for light level and illuminance so why doesn’t this work
if(HallLightSensor_Illuminance.state < 60) {
do stuff
}
Sorry for a really long first post. but any help greatly appreciated.