Temperature does not trigger the rule

Hi all,

i set a rule that triggers if the temperature drops 21 degrees. But it only works if i give in the basic ui a value otherwise does not trigger.

rule "Temper above 20°"

when
    Item Temper received update
then
    if (Temper.state > 23) {
       pushover("Temper over 23°")
       }
else
    if (Temper.state < 23) {
       pushover("Temper aboves 23°")
       }
end

εικόνα
can anyone help me?

Try doing the comparison to 23.0 instead of 23.

Thanx for your reply. I changed but nothing happend.

try:

if ( (Temper.state as Number) > 23)
or
if ( (Temper.state as DecimalType) > 23)

how is the Temper Item defined? as a Number or a String type?

I get these two errors
16:18:03.127 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Temperature above 20°’: Could not cast 26.937 to java.lang.Number; line 6, column 10, length 27

16:17:15.858 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Temperature above 20°’: Could not cast 21.937 to org.eclipse.smarthome.core.library.types.DecimalType; line 6, column 10, length 32

It´s a String type.

Add .toString after state.

rule "Temper above 20°"

when
    Item Temper received update
then
    if (Temper.state.toString > 23) {
       pushover("Temper over 23°")
       }
else
    if (Temper.state.toString < 23) {
       pushover("Temper aboves 23°")
       }
end

Or check this post for other clues that might help.

again in log comes this error: Rule ‘Temperature above 20°’: java.lang.Integer cannot be cast to java.lang.String

@pahansen I managed it to work, from the post you mentioned. So my Rule is now like this:

rule "Temperature above 21.5°"

when
       Item Temperature changed
then
    if (Double::parseDouble(Temperature.state.toString) > 21.5) {
       pushover("Temperature above 21.5°")
              }
else if (Double::parseDouble(Temperature.state.toString) < 21.5) {
       pushover("Temperature under 21.5°")
       }
end

I don´t understand what the Double::parseDouble does but it defenetly solved my problem.

Many thanks to all for the help.

Well, easy enough…
A string is a string, not a number. A string can’t be more or less than another string, it can be equal or not equal.
Every item supports its state as a state. Depending on the item type, you can get the state in another form. At least you can get the state as a string by using the method .toString (this method is passed from parent object).
If the item is a number item or a dimmer item, the state is a number and therefor could be used as a number by type casting (MyItem.state as Number).
When the Item is of type string, there is only a String, but no number. If you want to use the string as a number, you will have to convert the string to a Number.

The function Double::parseDouble(string as string) is to parse a string to a double, so e.g. the string "123.456" will be parsed to the double number 123.456

3 Likes

What a perfect description! Now I know what my rule exactly does and so I can create more complex rules. Very helpful, thank You!

Hello,
I try to write a rule with a temperature trigger.
The situation is as follows.
I have a heating system which produces energy too.
The energy is produced as long as the water temperature in the heating system in below 60°C.
When the temperature reaches 60°C, the power production shuts down and will not begin the next 12h.
So I try to write a rule, which gives me a warning by Alexa (during the day, not at night) when the water temperature reaches 50°C. Great would be an other warning at 55°C.
The item for the temperature is “EG_Vi_spu”.
Another trigger are the items “EG_Vi_evrule” and “EG_Vi_nbrule”. If both are at 100, the production is not running and the rule can be skipped.
Well and than I think I need a timer which runs to avoid Alexa warning me every few seconds (every update of “EG_Vi_spu”) that the temperature is high. By the way - can 2 or more timers run parallel? When there is a “window open” timer for example already running?
I tried a bit of coding but I am still a noob - but learning :sweat_smile:

rule "Stromproduktion"
when
Item EG_Vi_spu changed
then
logInfo("Test","Stromproduktion Speichertemperatur geändert, Rule Triggered")
    if (Item EG_Vi_spu.state == NULL) return;
    if (Item EG_Vi_spu.state < 50) return; 
    if (Item EG_Vi_evrule == 100 && EG_Vi_nbrule ==100) return;
    var Number hour = now.getHourOfDay
    if (hour >= 7 && hour <= 23 ) {
    Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 50 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 30 Minuten ab.")
    hour = null
}
end

This code gives me a lot of errors in the log…

2019-02-28 21:05:13.786 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'rules.rules' has errors, therefore ignoring it: [280,9]: no viable alternative at input 'Item'
[280,14]: missing ')' at 'EG_Vi_spu'
[280,37]: mismatched input ')' expecting 'end'

Nope. Don’t use Item there.
if (EG_Vi_spu.state == NULL) return;

Ok, nice. With this change, the rule works now.
Thanks!
But any idea how to insert a timer of 15 minutes into this rule. Alexa is talking now every few seconds…also ignoring it is already after 11 p.m. So also something with the code regarding the time is wrong…

rule "Stromproduktion"
when
Item EG_Vi_spu changed
then
logInfo("Test","Stromproduktion Speichertemperatur geändert, Rule Triggered")
    if (EG_Vi_spu.state == NULL) return;
    logInfo("Test","State NULL")
    if (EG_Vi_spu.state < 20) return; 
    logInfo("Test","State <50")
    if (EG_Vi_evrule == 100 && EG_Vi_nbrule == 100) return;
    logInfo("Test","State 100")
    var Number hour = now.getHourOfDay
    if (hour >= 7 && hour <= 23 )
    if (EG_Vi_spu.state>35) {
    Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 55 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 15 Minuten ab.")
    logInfo("Test","state >55")
    hour = null
    }
    else if (EG_Vi_spu.state>30) {
    Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 50 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 30 Minuten ab.")
    logInfo("Test","state >50")
    hour = null
    }
end

Example of this kind of thing. It’s not the only way to do it.

if (hour >= 7 && hour <= 23 )

You probably want some curly brackets associated with that, if it is supposed to control the following block of code.

  if (hour >= 7 && hour <= 23 ) {
      // lines of code
  }

OK, I changed that. Will see this evening if it works.
I tried now to introduce the timer and have some problems with that.
I created an Item for the timer:

Switch EG_Vi_spu_Timer {expire="1m,command=OFF"}

Now I try to introdce it into the rule:

rule "Stromproduktion"
when
Item EG_Vi_spu changed
then
logInfo("Test","Stromproduktion Speichertemperatur geändert, Rule Triggered")
    if (EG_Vi_spu.state == NULL) return;
    logInfo("Test","State NULL")
    if (EG_Vi_spu.state < 20) EG_Vi_spu_Timer.postUpdate(OFF)
    else 
    logInfo("Test","State <50")
    if (EG_Vi_evrule == 100 && EG_Vi_nbrule == 100) return;
    logInfo("Test","State 100")
    var Number hour = now.getHourOfDay
    if (hour >= 7 && hour <= 23 ){
    if (EG_Vi_spu.state>35) {
    Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 55 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 15 Minuten ab.")
    logInfo("Test","state >55")
    hour = null
    }
    else if (EG_Vi_spu.state>30) {
    Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 50 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 30 Minuten ab.")
    logInfo("Test","state >50")
    hour = null
    }}
end

For now, below 20 the timer is set to OFF.
But >35 I need the Alexa message first and than the timer set to ON. As long as the timer runs, the changes of EG_Vi_spu can be ignored.

Maybe something like this? If the timer is ON, return - no action. Set the timer ON after the TTS message in the +35 test?

rule "Stromproduktion"
when
    Item EG_Vi_spu changed
then
    logInfo("Test","Stromproduktion Speichertemperatur geändert, Rule Triggered")
    if (EG_Vi_spu.state == NULL) return;
    if (EG_Vi_spu_Timer.state == ON) return; // do nothing if timer is on
    logInfo("Test","State NULL")
    if (EG_Vi_spu.state < 20) EG_Vi_spu_Timer.postUpdate(OFF)
    else // do you need this else?
    logInfo("Test","State <50")
    if (EG_Vi_evrule == 100 && EG_Vi_nbrule == 100) return;
    logInfo("Test","State 100")
    var Number hour = now.getHourOfDay
    if (hour >= 7 && hour <= 23 ) {
        if (EG_Vi_spu.state > 35) {
            Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 55 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 15 Minuten ab.")
            logInfo("Test","state > 55")
            EG_Vi_spu_Timer.sendCommand(ON)
            hour = null // why set to null?
        }
        else if (EG_Vi_spu.state > 30) {
            Echo_TTS.sendCommand("Pufferspeicher Temperatur hat 50 Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 30 Minuten ab.")
            logInfo("Test","state > 50")
            hour = null
        }
    }
end
1 Like

Good idea - but the rule does not bring the Alexa message any more.
The Item EG_Vi_spu changes, the rule begins but thats it.
Look at the logs

2019-03-01 21:40:20.145 [INFO ] [.eclipse.smarthome.model.script.Test] - Stromproduktion Speichertemperatur geändert, Rule Triggered
2019-03-01 21:40:20.159 [INFO ] [.eclipse.smarthome.model.script.Test] - State NULL
2019-03-01 21:40:20.168 [INFO ] [.eclipse.smarthome.model.script.Test] - State <50
2019-03-01 21:40:20.178 [INFO ] [.eclipse.smarthome.model.script.Test] - State 100
2019-03-01 21:40:32.062 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 10 Std. / 34 Min.
2019-03-01 21:41:30.367 [INFO ] [.eclipse.smarthome.model.script.Test] - Stromproduktion Speichertemperatur geändert, Rule Triggered
2019-03-01 21:41:30.376 [INFO ] [.eclipse.smarthome.model.script.Test] - State NULL
2019-03-01 21:41:30.381 [INFO ] [.eclipse.smarthome.model.script.Test] - State <50
2019-03-01 21:41:30.390 [INFO ] [.eclipse.smarthome.model.script.Test] - State 100
2019-03-01 21:45:32.065 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 10 Std. / 39 Min.
2019-03-01 21:45:47.417 [INFO ] [.eclipse.smarthome.model.script.Test] - Stromproduktion Speichertemperatur geändert, Rule Triggered
2019-03-01 21:45:47.434 [INFO ] [.eclipse.smarthome.model.script.Test] - State NULL
2019-03-01 21:45:47.445 [INFO ] [.eclipse.smarthome.model.script.Test] - State <50
2019-03-01 21:45:47.455 [INFO ] [.eclipse.smarthome.model.script.Test] - State 100
2019-03-01 21:50:32.099 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 10 Std. / 44 Min.
2019-03-01 21:52:07.083 [INFO ] [.eclipse.smarthome.model.script.Test] - Stromproduktion Speichertemperatur geändert, Rule Triggered
2019-03-01 21:52:07.103 [INFO ] [.eclipse.smarthome.model.script.Test] - State NULL
2019-03-01 21:52:07.116 [INFO ] [.eclipse.smarthome.model.script.Test] - State <50
2019-03-01 21:52:07.130 [INFO ] [.eclipse.smarthome.model.script.Test] - State 100
2019-03-01 21:55:32.127 [INFO ] [.smarthome.model.script.system.rules] - Uptime updated to 10 Std. / 49 Min.
2019-03-01 21:55:43.802 [INFO ] [.eclipse.smarthome.model.script.Test] - Stromproduktion Speichertemperatur geändert, Rule Triggered
2019-03-01 21:55:43.812 [INFO ] [.eclipse.smarthome.model.script.Test] - State NULL
2019-03-01 21:55:43.822 [INFO ] [.eclipse.smarthome.model.script.Test] - State <50
2019-03-01 21:55:43.828 [INFO ] [.eclipse.smarthome.model.script.Test] - State 100

You have installed the expire binding, right?

So … what is the value? It’s important. If it lies between 0 and 30, no message.

You probably want to start the “blocking” timer from both places where you might send a message?

Oh sorry, you are right. It was at 29.5. My fault. Now it is at 30. I give a new try now.
Edit:
Now it works as supposed to.
Nice would be to bring the real temeperature of Item EG_Vi_spu into the message. Now it is like “temperature exceeded 50 °C”.
How is this possible?
Like this?

Echo_TTS.sendCommand("Pufferspeicher Temperatur hat" + EG_Vi_spu.state + "Grad erreicht. Ohne Wärmeabfuhr schaltet die Stromproduktion in circa 15 Minuten ab.")