Compare two temperatures and send telegram message

Hello,

I wanna compare two temperatures with a rule and send me a message over telegram. The telegram part works, but the comparing not. I changed the code from this topic [SOLVED] Simple Rule comparing a temperature value not working like this:

    var Temp.Aussen = Aussentemperatur_Temperature.state as Number
    var Temp.Wohn = ThermostatWohnzimmer1OG_Temperature.state as Number
if(Temp.Aussen > Temp.Wohn) {
   val telegramAction = getActions("telegram","telegram:telegramBot:1337263e00")
   telegramAction.sendTelegram("TEST")

}
end

But it doesn’t work. Can anybody see my mistake?

Try removing the dot so instead of temp.something, use tempsomething.

Nice idea :blush: But it doesn’t change anything :persevere:

Additionally can you try to declare TempAussen and TempWohn as Number?

var Number TempAussen = Aussentemperatur_Temperature.state as Number
var Number TempWohn = ThermostatWohnzimmer1OG_Temperature.state as Number

After the declaration you can also log the values with:

logInfo("TempComparison", "Aussen: " + TempAussen + " / Wohn: " + TempWohn)

Have a look at the logviewer and check

Find out if you are comparing two temperatures, two numbers, or maybe one of each.

2 Likes

I don’t now how I can find the logviewer. I don’t use openhabian. I installed openhab on debian itself. Where can I find the log?

It doesn’t change the problem. But the log can maybe help me.

I found this in the log file. But it does not help me. Is this helpful for you?

2022-07-29 18:33:27.128 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'b61402e0ba' failed:         var Number TempAussen = Aussentemperatur_Temperature.state as Number
        var Number TempWohn = ThermostatWohnzimmer1OG_Temperature.state as Number
        if(TempAussen > TempWohn) {
       val telegramAction = getActions("telegram","telegram:telegramBot:1337263e00")
telegramAction.sendTelegram("Temp Check")
logInfo("TempComparison", "Aussen: " + TempAussen + " / Wohn: " + TempWohn)
}
end
   The method or field end is undefined; line 8, column 393, length 3

I found the problem. The “end” of the end on my script was the problem.

Now I want disable the rule at the end and enable a other rule. Is this possible?

I tasted this but I doesn’t worked:

ruleEngine.setEnabled(ruleUID, True)# enable rule
ruleEngine.setEnabled(ruleUID, False)# disable rule

Sounds like you copied a rule example intended for xxx.rules file based usage, into a GUI rule environment. You have to be careful about that.

Sure, see various options at

Depends what you did with it. It’s not DSL rules language, so it wouldn’t work if you just copy/pasted into the same rule type you used for the other stuff.
You have to pay attention to which language you are trying to use.

I must disable the rule and enable a other rule inside the script. It does only happen when the telegram message was send. But I can’t find that way to disable/enable a rule in your linked post. I am stupid? :see_no_evil:

How to disable/enable rules is shown in the section marked “Scripted Automation

It looks like you found that before, and tried to copy-paste part of into a DSL rule.
That won’t work, because the example is not using DSL rules language.
It’s in “scripted automation” or Jython. You need to take care to use the same rules language.

There is just no way to enable/disable in DSL, but there are alternative approaches to get the same effect. Also described in that post.

There’s also the built-in action in the UI rules editor

but I think you’ll have to make a separate rule for that and call it from your first rule.