Openhab JRuby Rule Conversation

Thank you, I was hoping to get some help

I was wondering that myself because a lot of the examples have methods

agreed, thanks for the tip, in fact, looking at my rule, it seems dsl-ish version of jRuby, I need to take advantage of the simplicity of jRuby

Is it ok to post more rule conversions in this thread or should I start a new thread?

Iā€™ve just tested it, indeed you can have methods inside UI rules.

Hereā€™s another version of your script:

# convert a value from_range to to_range
def convert_scale(value, from:, to:)
  (value.to_f - from.begin) / (from.end - from.begin) * (to.end - to.begin) + to.begin
end

logger.info("Outside light level: #{OutsideLuxNum}")

dimmer = convert_scale(OutsideLuxNum, from: 900..10_000, to: 100..10).clamp(10, 100)
if CurrentDimmer.ensure.command(dimmer) # Item.ensure.command returns nil when it already had the same value
  gDimmerLux.ensure << dimmer
  logger.info("Dimmer set to: #{dimmer}")
else
  logger.info('Dimmer unchanged')
end

Itā€™s probably up to @broconne - but if you have a specific rule for a specific functionality, it might be a good idea to post a new topic.

1 Like