Set upper and lower limits for a variable

I want to calculate the charge rate for my solar battery with the logic card below. However, the result can be negative in some cases, and I also want to set an upper limit. What is the easiest way to do the following with the output:

  • If #charge_rate is lower than 100, set charge_rate to 100
  • If #charge_rate is higher than 2000, set charge_rate to 2000

This works
{{ min(max([value],100),2000) }}

So when I replace the example value 15000 with your calculation, it should be like this:

1 Like

Thanks, that’s amazing! I didn’t realize that the result could produce floats, but combined with the round(X,0) function the calculation works like a charm!

1 Like

YW! Yeah adding round() is the finishing touch :wink: