Check: Has the sun set? if yes: Turn on hallway lights. If not: Do nothing.
This is my rule:
rule "Gang Lys"
when
Item FrontDoor_Switch changed from OFF to ON
then
if(LocalSun_Position_Elevation.state < 0) {
Sonoff_Gang.sendCommand(ON)
}
end
I’ve tried adding debug lines, but it seems they never fire at all. however, when I made a typo in the elevation state, and I tried to run the rule by opening my front door, OH logged an error, after fixing the typo, I haven’t gotten it to run.
Edit: The issue has been solved, For good measure here’s the complete and correct rule, should you find this by way of google and need a template:
rule "Gang Lys"
when
Item FrontDoor_Switch changed from OFF to ON
then
if(LocalSun_Position_Elevation.state < 0|°) {
GangLys.sendCommand(ON)
}
end
Does FrontDoor_Switch actually change from OFF to ON? If it changes from any other state or does not change at all the rule won’t trigger. Look in events.log to see the Item changing states.
Add back the logging to get evidence that rule is triggering or maybe just the if statement evaluates to false.
rule "Gang Lys"
when
Item FrontDoor_Switch changed from OFF to ON
then
if(LocalSun_Position_Elevation.state < 0) {
return;
}
GangLys.sendCommand(ON)
end
And that works, insofar that if the door opens, the switch goes from off to ON, then the if is basically disregarded, and the command is sent to the light which turns on.
I assume it’s something to do with LocalSun_Position_Elevation.state < 0 but I’m not sure what.
I get the value from the Astro binding, it’s entry in the databse looks like this:
I use the Astro binding with an Item that I call IsItDark .
That could work, but seems unnecessary to me.
The Astro binding already has a channel for the elevation of the sun, and when it’s positive, it’s daytime, and when it’s negative, it’s nighttime, giving basically the same functionality, no?
The item type of LocalSun_Position_Elevation is a String with a value of “-14.922239921456542 °”.
If you compare this with a integer (0 in your case) this won’t work.
You’ll have to strip the “°” symbol and convert the rest to a number (decimal) to compare it.
Better way: You can make an item and bind it to the the channel “astro:moon:home:phase#name” and use this to compare it with the desired phase (NIGHT for instance). See https://www.openhab.org/addons/bindings/astro/#channels
First, for sunset with the astro binding you should be able to use astro:sun:local:set#event to detect sunset. I did it differently based on something I found here.
I set up 2 Items for sunrise & sunset
For whether it is dark I set up an item Switch IsItDark <moon> Here are its rules
rule "Sunset"
when
Channel 'astro:sun:local:set#event' triggered START
then
IsItDark.postUpdate(ON)
end
rule "Sunrise"
when
Channel 'astro:sun:local:rise#event' triggered START
then
IsItDark.postUpdate(OFF)
end
For my motion sensor (for my son’s Papillon dogs), if it is dark motion turns the light on. If no motion has been detected for 5 minutes, the light is turned off. I use the expire binding.
5 minute Timer item : Switch MyTimer { expire="5m,command=OFF" }
rules
rule "Papillon Motion On"
when
Item Papillon_Motion changed from OFF to ON
then
if (IsItDark.state == ON) {
Papillon_Light.sendCommand(ON)
// start Timer
MyTimer.sendCommand(ON)
}
end
rule "Papillon Motion Off"
when
Item MyTimer changed from ON to OFF
then
Papillon_Light.sendCommand(OFF)
end
I’m not sure I follow, you’re still comparing an integer to a string, aren’t you?
Or is some conversion before the comparison implied?
Edit: Ah I see we established it’s not a string. However after reading the Eclipse docs I see why it should work, but it dosen’t seem to, when I change it to >0 (because it’s daytime here now, so testing with that).
Edit 2: My mistake, had 1 too many brackets, it works perfectly no, thanks!
Furiously jots down, Read the binding documentation dammit.