I am stumped by this - I added a new rule that is supposed to turn on a light in our bathroom when my new presence sensor is active and turn it off when inactive but between certain times I want the light to be red (at night so it doesn’t wake me up). I am using a Zooz Zen 74 and a Orien RGBTW Smart Bulb that is being controlled by the Zooz. I have my system integrated with HomeKit. The rule seems to work perfectly exceept the one line that is skipped (see logs). I have also attached the rule configuration. Any ideas why this is happening?
My Hub model is C7 and my Platform version is 2.3.9.157
You have two time ranges, and only one will be true.. the "false" one is skipped. If it's false, there's nothing to do and skipping is the expected result.
At a minimum, you need an "End If" after the first "Refresh" line to complete that first "If", and depending on your intentions, you should use another one somewhere to complete that second If.
You could likely just use an ELSE instead of that second IF, but 2 complete IF statements should at least get it working.
Thank you for responding, it makes sense. I have been using Hubitat for 3 years and I have dozens of automations but none of them has ever required me to use any additional code outside of the GUI. At the risk of being chided for asking the obvious, how do you actual edit the code for a rule. I did look but I didn’t see anything like that. I occasionally write VBA (not well) so I am familiar with the concept, I just don’t know where I can pull up the code for my current rule and add those 2 “end if” statements. Apologies if this is a dumb question.
I'm at the office now, so can't provide a screenshot, but if you click on the Actions block, it will take you in to the editor.
There should be an option at the bottom of that table to add an End If, and you can then just move that up to the correct spot.
It looks like an End If is needed after each of the first 2 Refreshes.
Since the 2 timeframes look like they cover 24 hours, you could consider just using one of those conditions for an IF statement (and dumping the other), and then use a plain ELSE instead of the second IF, but using 2 complete IF statements should work fine too (what you have now plus the 2 End-Ifs).
ETA -- if you have just one IF stmt in a rule, you can often/sometimes get away with not using an End-If, but it's good practice/technique to always use an End-If to close out any IF stmt -- that way, you don't ever get burned by missing one.
You actually don't need (well, "can't use" really) END-IFs above--these are simple conditionals that apply only to that line. Perhaps that isn't intentional and they were meant to be regular conditionals, in which case you'd need to delete the line and replace it with an "IF (expression) THEN"?
It's hard to say more without knowing what you actually want the rule to do, other than that RM is correctly evaluating this condition and skipping the line based on your logs (and the current time) above--though making a guess based on your actions, I assume you really do what two "blocks" here, an IF THEN and an ELSE (or possibly ELSE-IF), closed out by an END-IF. That structure is more or less the same as VBA except slightly different keywords (and the fact that RM isn't "code" per se--you just select the option from the editor).
Omigosh... Good call, Robert - thank you for that correction! @Farris - I apologize for my misdirection there -- Robert is correct.
I am still not used to parsing that "simple conditional" option when I see it in the forums here -- it's not how I build my rules, so I obviously have some kind of blindness to seeing it!
Mea culpa all around -- my intentions were good, but most definitely not helpful here!
I failed to mention this but should have: I still think what you suggested is exactly what was likely intended, aside from the "wrong" kind of IF (the actions don't make much sense to me otherwise, hard as it is to guess without knowing the desired outcome). So, I'd certainly suggest those changes too!
I am working now as well but I understand much better after these comments, and I am going to redo this tonight when i get home but this very helpful to me and I appreciate it. I was thinking this was going to be like the VBA editor in Excel. Well that is not the case at all, this is much more structured. I would like to leave this open for a day or two so when I finish re-doing the automation, I can share a screenshot or two to help out others.
Okay, I think I got it this time,
thanks to you guys. Take a look...
Do you see any issues? I wasn't sure that the refresh(s) might be overkill, but when I was playing around with it, sometimes refresh would clear out an issue, so I stuck them in there.
Let me know what you think.
Well that didn’t work! Frustrated… what am I doing wrong?
I'm not familiar with the "Toggle color" option, and I'm wondering if that command is perhaps an issue for some reason... If you try just using the "Set color" option instead of "Toggle color", does that make a difference?
Not intending to compliacte this any further, but this overall motion-activated setup would be a really good candidate to do in the Room Lighting app too -- you can set up Time Periods within there.
ETA -- I should've asked this to begin with... What exactly isn't working -- is the rule not triggering at all, or lights not setting as desired, or something else?
As mentioned above, knowing what is actually happening would be the most helpful piece of information to figure this out. Also helpful would be logs from the rule, like you provided in your original post.
I'd second this advice. The "Toggle color" option will turn the bulb off if it's currently on (as reported on the device detail page, which ideally would match with the device, but this is all the hub "knows") or on to the specified color if it's off. Is that what you want?
I tried the set color and no luck. I am going to try the room lighting app.
Why are you using "refresh"? I don't think that should be necessary?
Does the light actually respond properly and do the States reflect those changes when controlled via the settings page for this bulb?
I have a similar rule that works fine, Rule Machine should be able to do what you want.
It's still not clear what's actually wrong. Can you look at "Logs" for the rule to get some clues, or provide them here so someone else can do the same?
Another thing that might help narrow things down: leave the rule out of the picture for a moment. Just try the commands directly on the device detail page, like Set Color. (Click the color box to select a color, click out of it to save, possibly depending on your browser/OS, then click the Set Color button itself to run the command.) If it doesn't work here, a rule won't work either, but you've narrowed the problem down to something with the device or driver.
But logs would be a bigger help with less guessing--that's just one possibility.
I think I may have figured out what the issue is. The bulb is a Orien RGBTW (Matter) Smart Bulb. In order to install you have to put it in HomeKit, then go into HomeKit and put the bulb in Pairing mode, copy a number down, go to Hubitat, add the bulb by clicking Mattter button, and enter code, once you do that, then you have to pick the matter RGBTW driver. That last piece is what i missed. Once I changed the driver, it stopped hanging up. It seems that. Was the issue. I am trying to use the room lighting program but it is a nightmare! I am deep into it so i kinda don’t want to give up but if I can’t figure it out, I will go back to the Rule Machine. I will post either way.
I had that in there because it was not responding. I removed it, it did not make a difference.
I have tried multiple ways and have not been successful, This is the latest iteration
After thinking about it, I decided to break this down to a series of small steps (Test Rules). The first one I tried was this:
This did not make sense to me because the command was to make the light 100% and Soft White and the logs show the command but nothing comes on.
So then I tried this:
This is when the lightbulb went off (no pun intended). I have a Zooz Zen 74 switch that I bought specifically because I wanted to control the Orien - RGBTW Smart Bulb, I didn’t want to spend the money on the Inovelli Red and the Zooz site said this switch would work provided I downloaded the driver, which I did. I am not controlling the switch, I am controlling the bulb but when I try and control the switch there is no provision for a color change. I am able to make it turn off and on but not make a condition that changes the color.
I did try this last test and it came on but still no way to conditionally vary the color.
I went back and read the documentation, I installed the correct driver that has advanced settings and I do not see any parameters that are incorrectly set. I am stumped. Did my being a tightwad (not buying the Novelli) cause all this trouble?
Anyone have any ideas?
A few posts up, Robert had good advice to start with basics first (before even getting into any rules)... Starting with the bulb, have you done this yet?