Linking arbitrary channels with different units

  • Platform information:
    • Hardware: pi4
    • OS: openhabiab
    • openHAB version: 4

I have a set a dimmable LEDs that I want to link to the sun’s brightness during the day. I installed the Astro binding which has a sun irradiance channel that seems perfect as a source. I also have a simple dimmer channel for the LEDs that works fine on its own.

I figured I should be able to link these up in some way. I can create a Link between the two using the Follow profile (which I assumed would be the one I want), but that doesn’t do anything and the value just says “error”. I assume this is because the two channels are in different units, one is percent and the other is irradiance. I also figured that converting units of channels must be a common enough issue for there to be some facility to do it on a Link in the UI, but maybe I’m wrong about that?

  • Would this be a case for me to write a custom profile?
  • Should I just switch entirely to “file-based”, using openhab’s internal DSL to do all this stuff?
  • Is there actual documentation for this DSL anywhere? How would I go about starting to learn how it works?

I’m a programmer by trade, but I was hoping I could just get this thing up and running quickly and easily. If I need to, however, I’ll learn this DSL, but do I really need to comb through the source code to do it?

Well, not like that. “Convert a brightness measurement to a power setting” isn’t really a direct correlation.

That’s okay, that’s what rules are for, tailoring “if this, do that” to your very specific needs.
“file-based” has little to do with rules. You can use DSL rules out of files, you can use DSL rules entered in UI, you can use other rules languages from file or from UI.

Current docs are inherited from OH2 and so biased towards file-based, but equally valid in the main for UI entry.

Hey, thanks.

I guess I hadn’t figured out how exactly rules fit into all this stuff. The big picture of how openhab works is a bit difficult to conceptualize, but I ended up putting this script together which seems to do the basic thing when attached to my rule:

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);

var radiation = itemRegistry.getItem('TheSun_TotalRadiation').getState().toString().split(' ')[0];

// maximum intensity is around 500, so we're just gonna do this for now
var adjusted = Math.min(100, radiation / 5);'Setting kitchen LEDs to power level ' + adjusted + ' to represent total sun radiation of ' + radiation);

events.sendCommand('KitchenLEDs_Dimmer', adjusted);