I have a simple rule that was working in OH2 that I can’t really figure out how to get to work the same way in OH3. What I was is that if my light sensor reports a value below a specified limit and if the clock is between specific points in time in the afternoon, it should light up my house (ie a specific Item group). However this should only do this if it’s the first time today that this happens (so if it gets above the limit and then below it again nothing should happen).
In OH2 I did this using a global variable in the rules file to keep track on whether this was the first time (and then another rule to reset that variable at noon), but that option is gone now.
I guess this is really simple, I just need a nudge in the right direction
You can use either a dummy item with expire addon. Then define that the item should expire e.g. after 6 hours. So when the item was used it will stay on fo 6 hours and goes OFF again. Set the item on the first run to ON and check on each run if it is already ON, if yes do not run the rule.
If you don’t like the expire binding or need to define a specific time to reset the item you can build this with two rules. One with your current logic. This sets the dummy item to ON. another rule triggered by a cron timer. Set this cron timer e.g. to 21:00 and in the rule just set the item to OFF.
A variable won’t survive restarts and a switch item is readable and can trigger other rules. You can also turn it on or off manually for testing purposes.
Consider looking at getHourOfDay which could work with some sound logic.
Many years ago, before I could afford my first light sensor, I based the lighting on calculations like this. In my opinion it was completely worthless, the lamps always turned on too early or too late, depending on the weather. No, nothing I would want to get back to
Yes, that was my understanding as well, but it doesn’t seem that way. None of my rules involving global variables actually seem to work anymore. My plan is to go over all rules and make them using the new UI instead though, so it doesn’t matter in the long run, I just hoped that I wouldn’t need to do it in a hurry
I am using V3 with .rules files and the global variables work just like normal. I use global variables to do time stamps. I have not tried the rules in a script stored in the json DB yet as I like doing multiple rules in the same file.
If your using the new ‘create equipment from thing’ feature to auto create the items, you need to go into the rules files and update what the items are now called in V3 as they are probably not the same as V2. That could be why they dont work for you?
That is weird. Must be something else that didn’t work then. I didn’t dig any deeper, just assumed that this was the problem when I didn’t see anything apparent. All the Things and Items are just upgraded from OH2, not being created in any fancy new way.
Actually, now I have completely re-made those rules, using a dedicated Item to keep track on whether the lights have already been turned on. Seemed like a good idea to go through all my rules and do them using the new shiny UI