Calculate

Hello group

I am looking for a solution on this matter since my skills in math doesn’t cover

I want the value from a lux meter converted to a bulb setting like this:

Lux is 200, bulb value should be 1 (light strenght)
Lux is 100, bulb value should be 15
Lux is 0 (1), bulb value should be 30

The values described is only examples

But how to convert the values, will there be an app for it?


What language? Groovy app? Rule Manager?
So Lux can be between 0 and 200?
Bulb can be between 1 and 30?
And they are inversely related?

I think you would need to know the min and max values of both the Lux and the Bulb in order to do the math.

1 Like

Hello
Thank you for your time and answer
Lux will be from 6000 to zero but should first kick in at 200 (tusk, dusk or twilight, whatever you call it :smiley:.
Bulb will be from 0 to 100, I would like it to run 0 to 30 and yes they are inversely connected

Language whatever can do the task, rulemachine however will be fine.

My pleasure.
This should do the trick:

def LUX = 1000
def BULB = 0

// If LUX is less than or equal to 200, always set BULB to 1
if( LUX <= 200 ) 
  BULB = 1

// Else if LUX is equal to 6000, always set bulb to 30
else if( LUX == 6000 )
  BULB = 30
  
// Else, the LUX is between 201 and 5999. 
// LUX divided by 200 will always give us a value between 1 and 30, but we need the inverse
// Just subtract the quotient from 30, and it will invert the relationship.
// Now, LUX of 5000 yields BULB of 5, while LUX of 1000 yields BULB of 25
else
  BULB = 30 - ( LUX / 200 )

println BULB

EDIT: I may have still misunderstood.
You want the bulb to range from 1 to 30 ONLY while lux is between 0 and 200? If this is the case, I'll have to edit. If you are wanting the bulb to range from 1 to 30 while lux is between 200 and 6000, the code above will work fine.

Yes exactly, sorry if I have not been prezise enough

The idea is that my light levels should slowly kick in when darkness apears
However, in winter tusk is shorter than in summer, as well as a thunder or heavy rain would change light conditions

def LUX = 200
def BULB = 0

// Only execute if LUX is between 0 and 200
if( LUX >= 0 && LUX <= 200 ) {
  
  BULB = 30 - ( LUX * 0.15 )
}

println BULB
1 Like

Thanks a lot, tried a few values, seems to be carrect.
I will test it in the weekend, and ofcause report back here.

:+1::+1::+1:

1 Like

Is just working, use it for setting a varible.
Problem solved, thanks again👍

1 Like

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