Slider value in Notifications

I am trying to use a slider value in as a timer value and also send that value in a notification, both of which I have seen done in examples but nothing will work for me. Could someone please assist with working examples or point me in the right direction.

I have these in a dsl rule and have tried many variants of data manipulation to get it to work as shown below, can some one help



//var duration = timer_length.state as DecimalType
//var duration = (timer_length.state as Number).intValue
//Number timerDuration
var Timer timer = null //Global variable

   // timerDuration = (timer_length.state as Number).intValue // transforms the Timer item value into an integer as timers only accept integers as arguments
 
Theatre_Lights.sendCommand(OFF)  
var duration = (timer_length.state as Number).intValue * 10
Thread::sleep(2000)
//sendNotification("xxx@xxxl.com", duration) //doesn't work
  //sendNotification("xxx@xxx.com" , 'Timer= ' +  String.format("%.3f", duration.state) + ' mm') //doesn't work
   Theatre_Lights.sendCommand(ON)     
   sendNotification("xxx@xxx.com", "Timer finished")


// the timer below also never works as the value is never parsed correctly either????
//var runtime = v_water_rf_timesilder.state as DecimalType
//var timerval = timer_length.state as DecimalType
//var duration = (timer_length.state as Number).intValue
  sendNotification("xxx@xxx.com", duration)
   Theatre_Lights.sendCommand(OFF)     
   sendNotification("xxx@xxx.com", "Timer finished")
    //MinutesRemainingOnTimer.postUpdate(TotalRuntime.state)
    //timer1 = createTimer(now.plusSeconds(runtime.timerval), [ |
    // timer1 = createTimer(now.plusSeconds(duration), [ |                                              
        //var remain = MinutesRemainingOnTimer.state - 1
       // if( remain < 0 ) remain = 0
        //MinutesRemainingOnTimer.postUpdate(remain)
       //if( remain > 0) timer1.reschedule(now.plusMinutes(1))
       //  Theatre_Lights.sendCommand(OFF)     
       //  sendNotification("xxx@xxx.com", "Timer finished")
  //  ]
///End

First things first: how did you create the rule?

I would expect something like this:

// global var is defined on top of the first rule in the file.
var Timer tTheatreLights = null

rule "timer notification"     // rule definition in file needs a header
when
    // something happend, e.g.
    Item StartScene received command ON
then
    var Integer iDuration = 10                                 // set a default value
    if(timer_length.state instanceof Number)                   // if item value is of typ Number
        iDuration = (timer_length.state as Number).intValue    // use that instead
    sendNotification("xxx@xxx.com", duration.toString)         // Message has to be a string
    Theatre_Lights.sendCommand(OFF)
    tTheatreLights = createTimer(now.plusSeconds(iDuration),[|
        sendNotification("xxx@xxx.com", "Timer finished!")
        Theatre_Lights.sendCommand(ON)
    ])
end

Please be aware that global vars can only be used in a *.rules file.

Hi,

Thanks for the info and I can see how much it hurt you to look at my layout…
I appreciate the help. I needed to better declare the variables and fetch the states as you have demonstrated