Variable setting Max/Min

On the road and doing a quick search didn’t show any info on this and wondering if this could be a feature request.

Say, in hub variables you define a number for humidity level in a room for a humidifier to turn on and off. I’d want to give buttons on a dashboard to adjust the number up and down a bit, but obviously you don’t want to allow the humidifier to run until the room is at 100%. Is there the ability to frame the hub variable so the initial number could be 40, and could only go down to say, 35 and up to 45. Any adjustment past those would not make a change.

I would expect that the button that I make to adjust the variable up and down can be framed by an if /then rule that does this, but I think the frame at the variable would be more consistent/easier. Thoughts/comments? Did I miss something?


There might be a better approach, but I'm thinking a simple Rule could effectively do what you want:

Trigger: Variable X *changed*

Actions to Run:

IF (Variable X < 35) THEN
  Set Variable X to 35
ELSE-IF (Variable X > 45) THEN
  Set Variable X to 45

This doesn't prevent it from getting set outside the range, exactly, but it will set it back within the range if it gets set outside it, which sounds like it should still meet your goal.

1 Like

I thought of that too and did what @bertabcd1234 suggested but in the actual rule. @bertabcd1234, wouldn't having this as a separate rule create a situation where the rule that uses the value would get triggered twice? Once with the 'bad' value and one with the capped value?

Regardless, @krzes, I like your suggestion for a built in min/max function; that would be cleaner,

I don’t have hub access so I will steel your starting point. I was considering something like;

Trigger: `Button +’ pressed

Actions to Run:

IF (Variable X < 45) THEN
  Set Variable X to Variable X +1

Either could do. And I guess not that big of a deal to do, but thought I’d check before going down a rabbit hole.

1 Like

Yeah--didn't really consider that since I wasn't sure how the variable was actually being used. A cheap workaround would be to just add a "Wait for event: elapsed time --> 0:00:02" or something at the beginning of the other Rule so it waits a couple seconds before doing anything; then nothing should really happen if the first value was outside the range. A cleaner workaround might be to only do something if the actual value is within the range in the other Rule, whether with a conditional action or predicate rule. A third approach would be to add another variable to the mix and only set the "fake" variable but use the "real" one in the actyak Rule, tying them together with a Rule that sets one based on the other.

And probably lots of other possibilities depending on how the actual automation is set up!

1 Like