Displaying timer on the panel

Hi
is there a way to display timer on the panel? I have a rule working with button where after i press the button, it waits for 5 mins to execute an actual command. I am wondering if there is a way to display this timer so that i know how much time i have left before the command gets executed.

Michal very kindly created me a set of rules for a holiday countdown timer, when I get a chance tomorrow (when I switch my laptop back on) I'll cut it out and paste it here for you.

thanks you! looking forward to it

Good morning.

I'm sure you can modify this batch of rules to do what you need.

The premise is that there is an In-Memory variable that stores the amount of holiday days left and this set of rules executes a command to switch on a "switch" when the holiday number is >0

Then turns off the switch when the value returns to 0

In the UI, I have 3 buttons that set the In-Memory value to : -
+ 3
+ 14
+ 99

There is also a slider to set any other value. :wink:

As well as a label to show the current value.

     // Block of Rules for Holiday away days
      
     rule "Holiday_mode_Off"
        timer (int: 1s)
    when
        Event( source == "Holiday_Days_Status", value == "0")
    then
        execute.command("HolidayVR_OFF");
    end
     
    rule "Holiday_Mode_On"
        timer (int: 1s)
    when
        Event( source == "Holiday_Days_Status", value > 0 )
    then
        execute.command("HolidayVR_ON");
    end
    
    rule "Holiday_Mode_dec"
        timer (int: 10s) // obviously change this value to 24h when you're happy with the operation
    
    when
        Event( source == "Holiday_Days_Status", $TimeLeft : value > 0 )
    then
        Integer iTl = Integer.parseInt($TimeLeft.toString()) ;
        iTl = iTl - 1 ;
        execute.command ("Holiday_Days_set", iTl );
    end

Thanks. The first 2 rules are clear.
I have some questions on the 3rd rule (Holiday_mode_dec)

a) what is this “$TimeLeft” with respect to OR component? is it an in-memory virtual command?
b) what does 'Integer.parseInt($TimeLeft.toString()) do?
c) are “Holiday_Days_Status” and “Holiday_Days_set” in-memory virtual command? if yes, is the command type “status” for both?

Appreciate your help and comments.

Hi

I should have added some more info.

a) what is this "$TimeLeft" with respect to OR component? is it an in-memory virtual command?

This is something that only the rules use, don't worry about it :wink:

b) what does 'Integer.parseInt($TimeLeft.toString()) do?

I'm not sure, I'm not the magician, only the assistant :wink:

I think it does something with the value?

c) are "Holiday_Days_Status" and "Holiday_Days_set" in-memory virtual command? if yes, is the command type "status" for both?

You have it in one :slight_smile:

However, the sensor being used is a level sensor, linked to the In-Memory command with the command type "status" - Holiday_Days_Status

The Holiday_Days_Set is an In-Memory command with any value in the command type.

It's the same command that I link to the UI slider :wink:

As I suggested, I also have other Holiday_Days_Set_xxxx commands that have preset values.

For example

Holiday_Days_Set_3

Holiday_Days_Set_5

I think the command Holiday_Days_Set holds the value of 99

so i tried this rule

rule “30 sec counter decrement”
timer (int: 0s 1s)
when
Event( source == “VS_Gdoor_timer”, $v: value > 0 )
then
Integer iTl = Integer.parseInt($v.toString());
iTl = iTl - 1;
execute.command (“VS_Gdoor_timer”, iTl );
end

The ERROR is get is java.lang.classNotFoundException

In your rules file did you have to include any other additional Java librabries or files at the beginning? I have the following in my rules file before starting the 1st rule (should i have any others in there for using the Integer.parseInt- it seems like it is causing this error0

package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;

Good morning,

I'm really not sure what the cause is, you'll need the assistance of a real wizard if this bit of information doesn't help.

This is exactly what my rules file contains ......

I really hope it helps you.

Cheers,
Stuart

package org.openremote.controller.protocol;

global org.openremote.controller.statuscache.CommandFacade execute;

import java.util.*;
import java.util.regex.*;

// Block of Rules for Holiday away days

rule "Holiday_mode_Off"
    timer (int: 1s)
when
    Event( source == "Holiday_Days_Status", value == "0")
then
    execute.command("HolidayVR_OFF");
end

rule "Holiday_Mode_On"
    timer (int: 1s)
when
    Event( source == "Holiday_Days_Status", value > 0 )
then
    execute.command("HolidayVR_ON");
end

rule "Holiday_Mode_dec"
    timer (int: 24h)
when
    Event( source == "Holiday_Days_Status", $TimeLeft : value > 0 )
then
    Integer iTl = Integer.parseInt($TimeLeft.toString()) ;
    iTl = iTl - 1 ;
    execute.command("Holiday_Days_set", iTl );
end

One observation...

Your sensor and command have the same name......

good point. I changed the rule as below but still getting
java.lang.RuntimeException: WRONG CLASS FORMAT and
ClassNotFound Exception errors.

I know its related to this specific rule because when i comment it out, everything else works fine.

rule “30 sec counter decrement”
timer (int: 0s 1s)
when
Event( source == “VS_Gdoor_timer_sensor”, $v : value > 0 )
then
Integer iTl = Integer.parseInt($v.toString());
iTl = iTl - 1;
execute.command (“VS_Gdoor_timer”, iTl );
end

hopefully someone expert in JAVA will be able to shed some light on this.

Hi

I'm no expert, but I spotted this....

timer (int: 0s 1s)

Should it be more like ......

timer (int: 1s)

This is a pure guess, but it's the only thing I can see that is different from the working rule I have.

Good luck.

Thanks Stuart- I dont think that is the issue. Timer allows 2 parameters

https://github.com/openremote/Documentation/wiki/Rules

I noticed you had the following in your rules file:

import java.util.;
import java.util.regex.
;

I tried to include those to see if it helps but no luck- do you remember why you had them?

a) can you confirm which version of OR and JAVA are you running on the machine that is successfully implementing this rule?

b) Also in your example is “Holiday_Days_Status” a sensor with Virtual in-memory command tied to it?

c) is Holiday_Days_set a virtual in-memory command tied to the sensor Holiday_Days_Status ?

Hi
I'm at the ends of a long day, with another hour to drive, so please excuse my short answer.

I'm still convinced your issue is with the timer, please humour me and just put it as timer (int: 1s)

I'm sure (int: 0s 1s) is confusing.

And..

FYI.

My machines run a mixture of configurations for testing.

This rule works on all of the machines.

And yes, the status / sensor looks at the same In-Memory variable as the In-Memory set command.

Still no luck with this :frowning:

Ummmm

How very frustrating.

The rule is fairly straightforward, so it must be something really basic.

Do you want to start from the beginning and double check everything.

Or your welcome to invite me to your online designer account and I'll have a quick look.

Assist (at) mdar . eu

Best wishes,

Stuart

Hi,

you are using Integer class which is a wrapper around the primitive int type. It is located in java.lang.Integer therefore you need to add this line in your code:

import java.lang.Integer

``

Alternatively, you can declare iTl variable as a primitive integer type, i.e.

int iTl = Integer.parseInt($v.toString());

``

Hope this helps.

Michal

thanks Michal- unfortunately still getting the errors. I have attached the complete error messages in the post.

I am using Raspberry Pi, OR2.5 with Java version 1_8_0_65-b17 if it has any impact (i saw in another post something about java version incompatibility with OR)

A couple of additional questions:

a) is it possible to declare an integer with an initial value in rules outside the "when’? something like this:

rule “30 sec counter decrement”

timer (int: 0s 1s)

int i=30;

when

Event( source == “VS_Gdoor_timer_sensor”, value > 0 )

then

i = i - 1;

execute.command (“VS_Gdoor_timer”, i );

end

b) is it possible to share variables between multiple rules?

i could possibly make this work with either of the two above options as a alternative,

currently my rules are as follows.

package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;

global org.openremote.controller.statuscache.SwitchFacade switches;

import java.util.*;

import java.lang.Integer;

//import java.util.regex.*;

//import java.lang.*;

//import java.lang.reflect.Method;

// 30 second timer display with virtual switch for garage door to insert delay in closing

rule “30 sec counter initialize”

when

Event( source == “VS_Gdoor_status”, value == “ON” )

then

execute.command( “VS_Gdoor_timer”, 30);

end

rule “30 sec counter decrement”

timer (int: 0s 1s)

when

Event( source == “VS_Gdoor_timer_sensor”, $v : value > 0 )

then

int i = Integer.parseInt($v.toString());

i = i - 1;

execute.command (“VS_Gdoor_timer”, i );

end

error (15.6 KB)

For controller 2.5 you need Java 1.6.
You can try controller 2.6 beta which runs with your current Java version.

a) it is possible with custom facts. See https://github.com/openremote/Documentation/wiki/Advanced-Rule-Examples

b) this is too possible. Even better if you want to display the timer in UI.

Kind regards,

Michal

Hi Michal

i downloaded 2.6 beta and loading my configs but it seems to give a whole new set of errors like mismatched input ‘event’ in the rule
i remember reading somewhere that moving to 2.6 could break all the rules- is it using some different format? if you have an example of working rules with 2.6 that you can share that would be great

The syntax is slightly different. Please show the offending rule and I'll tell you how to fix it.