Need help to arrange the rule to be more orderly

My Version OH: openHAB 3.3.0 (openhabian)
The rule works but I think it can be arranged in a better way, so I would appreciate advice from the experts
Thanks in advance!

rule "Living Room Bulb"
  Item LivingRoomLight_Switch changed to ON
if ((now.getHour() >=21) && (now.getHour() <=00)) {
if ((now.getHour()) >=00 && (now.getHour() <=5)) {



sure especially about the following part of your rule ?

that newer will be TRUE.

Sorry but I don’t understand what you mean…

When will the hour be >= 21 and be <= 00 ? => never. That means the related tree never will be executed.
21 is greater than and equal to 21 but 21 is not less than or equal to 00 …
We say midnight is at 00 or at 24 but the returned value will be 00 and is 00 >= 21 ?

Your intention is clear but the code will not work as intended.

***edit, now i check the rule again end it really didn’t work which is strange because he was working yesterday…

The truth is, the rule works as expected, between 9 in the evening and midnight the bulb changes to what is set in the rule and the same between midnight to 5 in the morning, and from 5 in the morning to 9 at night the bulb changes to 100%.
But my question is if it can be done more simply?

You just need one if with an OR and an else. Change the if to:

if (now.getHour() <= 5 || now.getHour() >= 21) {

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.