Using an duration (Number:Time) to create timer

Hey,

I’m walking trough this community, reading lot’s of post but was unable to find an solution.
I’m using the astro-binding, which provides duration information about dusk duration and something like this.
What I like to do is to trigger an event after 1/3 of the dusk duration is over.

My items looks like this:

 DateTime  astroDuskStart  "astroDuskStart [%1$tH:%1$tM]"  { channel="astro:sun:home:astroDusk#start" }
 Number:Time  astroDuskDuration "astroDuskDuration"   { channel="astro:sun:home:astroDusk#duration" }

I’m not sore, if I understand right, but Number:Time means, that this item is from type number, formatted as Minutes, right? Example value, which is displayed in the visu is something like 32 min

My non-working role looks like that:

rule "duskStarter"
when
   //this trigger works perfect
    Channel "astro:sun:home:astroDusk#event" triggered START
then

    //the following stuff does not work:
     var dur = (astroDuskDuration.state as DecimalType).intValue)
     postDuskTimer = createTimer(now.plusMinutes(dur/3)) [|
          logWarn("mylog","30% of dusk is done")
          ]
end

This results in an error:
Could not cast 32.0 min to org.eclipse.smarthome.core.library.types.DecimalType;
If have tried different variation of reading and converting the state. But maybe the Number:Time thing is the reason, why I cannot apply the tutorials I found here?

Thank you.

QuantityTypes (e.g. Time) are not DecimalTypes so you cannot cast them as such. That is the source of the error.

I believe you need to cast it as follows:

var dur = (astroDuskDuration.state as QuantityType<Number>).intValue
1 Like

@B0rner
You have two options:

    var dur =astroDuskDuration.getStateAs(QuantityType).intValue

or

    var dur = (astroDuskDuration.state as QuantityType<Number>).intValue

@rlkoshak, there is an extraneous bracket at the end of your expression

Dumb copy and paste error. Thanks for catching it.