I have variable declared in the rules, and then changed during cron or Astro
In the rules I look for the variable “sun = true” to decide if I should turn lights on or not.
Sometimes, too much, the state is wrong, even during morning the lights turn on becuase the “sun” is true
How can I enhance this sun state ?
var boolean sun = false
rule "Sunset var"
Channel 'astro:sun:home:set#event' triggered START
Time cron "0 0 19 ? * *"
logInfo("home.rules", "Sun False")
sun = false
rule "Sunrise var"
Channel 'astro:sun:home:rise#event' triggered START
Time cron "0 0 6 ? * *"
logInfo("home.rules", "Sun True")
sun = true
Note that this approach requires that your .rules file not be touched or reloaded after the rise event or 06:00. When your file reloads sun gets reset to false. A better approach would be to use a Switch Item and implement restoreOnStartup on that Item so no matter when the .rules file reloads, it will retain the correct sun state.
If all you care about is whether the sun is up, Link an Item to the Elevation or Azimuth Channels and check to see if these are > 0 and you can do away with these Rules entirely.