Value from another item in bindingconfig

Tags: #<Tag:0x00007f616882d068> #<Tag:0x00007f616882cf28>

Is it possible to use a value from another value in an items bindingconfig? For example, I want to use a number item, set by user, to set offset in Astro bindings sunrise/sunset event.

Number Sunrise_Offset
Switch Sunrise_Event {astro=“planet=sun, type=rise, property=end, offset=Sunrise_Offset”}

I don’t know the answer to your question but I’m willing to bet you need to use Sunrise_Offset.state if it does work.

Rich

I assume that this is not possible, since items are loaded once as start-up or when the .items file change. At this point Sunrise_Offset may not have a valid value. However, I realized something similar using a timer:

rule closeRollerAtNight
when Item Sunset_Event changed to ON
then
    var timeToClose = now.plusMinutes((VAR_Roller_MinutesToCloseAfterSunset.state as DecimalType).intValue)
    
    createTimer(timeToClose) [|
        logInfo("Rules", "Closing Living Roller NOW.")
	sendCommand(LR_Roller_West, 0)
	sendCommand(LR_Roller_North, 0)	
    ]
end

Via the item VAR_Roller_MinutesToCloseAfterSunset.state the user is able to define an offset in minutes after the sunset. Maybe this helps.

Best,
Daniel

@ldaniel, a timer like that works well for a positive offset but not for a negative offset. I live in the mountains so it remains dark and gets dark considerably after sunrise and before sunset so negative offsets are pretty useful to me.

That got me to thinking and I believe you can handle the generic case (positive and negative offsets) through a very similar rule as well by triggering at System started, midnight, and when the offset changes and calculating the next time the timer should go off rather than setting a timer after the sunset event occurs. We have to do some book keeping though to cancel any previous timer when the offset is changed.

Here is some pseudo-rule code

val sunriseTimer = null

rule "Set Sunrise Timer"
when
    System started or
    Time cron "0 0 0 * * * ?" or
    Sunrise_Offset changed
then
    if(sunriseTimer != null) sunriseTimer.cancel
    var timeToClose = // Generate a DateTime for the next sunrise + Sunrise_Offset
    sunriseTimer = createTimer(timeToClose) [|
        // do stuff
        sunriseTimer = null
    ]
end

I always have a hard time working with datetime in OH so I’ll leave the calculation as an exercise for the student.

Rich