Checking for openHAB updates - simple rule

I have identified this part of my rule, which is causing the error:
(rest of the rule is running without errors)

if (Integer.parseInt(currentBuildString) < Integer.parseInt(lastBuildNumber)) {
            OH_Status.postUpdate("neues Update vorhanden: #" + lastBuildNumber)
    }

And this:

2018-05-28 11:44:05.674 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currentBuild' on rule file 'oh_update.rules' cannot be initialized with value 'org.eclipse.xtext.xbase.impl.XConstructorCallImplCustom@51a0072b (invalidFeatureIssueCode: null, validFeature: false, explicitConstructorCall: true, anonymousClassConstructorCall: false)': For input string: "Release Build"
#!/bin/bash
sed -n 's/build-no\s*: //p' /var/lib/openhab2/etc/version.properties | cut -d '#' -f 2

currentBuildString contains “Release Build” and thus it cannot be parsed into Integer.
You need to make sure contains any number before you proceed with comparing it with lastBuildNumber:

if (currentBuildString.matches(".*\\d+.*") && Integer.parseInt(currentBuildString) < Integer.parseInt(lastBuildNumber)) {
   ...
}

Didn’t test it!

But what has changed since the last few weeks? I was on a snapshot maybe 2 weegs ago and all worked, today i made an update and now it doen´t work anymore…

This is the version.properties-file:

openHAB Distribution Version Information
----------------------------------------
build-no        : Release Build
online-repo     : https://dl.bintray.com/openhab/mvn/online-repo/2.3

Repository        Version
----------------------------------------
openhab-distro  : 2.3.0
smarthome       : 0.10.0.oh230
openhab-core    : 2.3.0
openhab1-addons : 1.12.0
openhab2-addons : 2.3.0
karaf           : 4.1.5

So when the release 2.3 is out and the new 2.4 snapshots are running, it will probably work again without any changes?

In the last couple of weeks there was some release candidates for 2.3 being published and that maybe what “broke” it. My guess is that it should get back to normal after the first 2.4 snapshot is released

Which has already happened :wink:

1 Like

But it´s not online yet… :blush:

https://openhab.ci.cloudbees.com/job/openHAB-Distribution/api/json?

Yes it is, I just have updated to openHAB 2.4.0 Build #1292

Ok, i can see it now. I made a snapshot update about 2 hours ago and in this version i couldn´t see, which build it was. I only could se release build…

Now i made another apt-get update / upgrade and there is a new update again… Now i can see #1292 in paper UI and in the versions-file too.

I am just building up the snapshot rules new and have some questions. From the properties file i could get the installed buzild and the distro. From cloudbees i get the latest build (json). Now my question: Is it possible to get the distro online?

Thanks

Has someone recognized that the build number from cloudbees has not changed since #1392?

So the rules are more or lesse useless.

Thomas

The location has changed. It now is at https://ci.openhab.org/.

1 Like

I will check that - Now it is working again.

Thanks

My rule worked fine the last couple of months. Since a few days I receive the following error:

2019-02-10 21:30:31.653 [ERROR] [ntime.internal.engine.RuleEngineImpl] 
- Error during the execution of startup rule 'Check for openHAB distro updates': For input string: "
{"_class":"hudson.maven.MavenModuleSet","lastSuccessfulBuild":
{"_class":"hudson.maven.MavenModuleSetBuild","number":1519}}"

Anybody an idea?

I’ve just updated the post with the proper REST API endpoint:

https://ci.openhab.org/job/openHAB-Distribution/api/json?tree=lastSuccessfulBuild[number]

1 Like

I guess the brackets should be replaced by %5B and %5D in the URL

1 Like

My fault was: I had to reinstall all bindings because of the snapshot bug in #1518 and forgot to re-install the JSONPath Transformation. I am very sorry - thanks @kubawolanin for your kind help.

Hey @Dibbler42: Where do you get the build version from? My version.properties file just says:

build-no: Release Build

So I don’t know where to get the release build no. from…?

Since the current script is not working anymore I’ve created a new one with the help of the first post. I’m a newbie in openhab and linux so bare with me for the strange coding…
Maybe someone is still interested:

in the script folder I have one script. It first gets the current core version of openhab from the version.properties file.
Then it gets the newest released version from the GitHub page of openhab-core. I don’t include the M Builds so I stay with the official released ones:

checkForUpdate.sh

curVers=$(sed -n 's/openhab-core\s*: //p' /var/lib/openhab/etc/version.properties | cut -d '#' -f 2)

newesrVers=$(curl https://api.github.com/repos/openhab/openhab-core/tags -s | jq -r .[].name | grep -v '[a-z,A-Z]' | sort -r | head -n 1)

if [ "$newesrVers" = "$curVers" ]; then
	# no update
    echo "no"
else
	# new update
    echo "yes"
fi

rule in openhab:

rule "Check for openHAB core update"
when
    Time is midnight or
then
    OH_Status.postUpdate("Checking...")
	
	OpenHabCheckforUpdate_Ausfuhrung.sendCommand(ON)
end



rule "evaluate update request"
when
    Item OpenHabCheckforUpdate_erg received update
then        		
    if (OpenHabCheckforUpdate_erg.state == "yes") {
        OH_Status.postUpdate("Update available!")
    } else {
        OH_Status.postUpdate("No update")
    }
	
end

I made a new exec thing which executes the script “/etc/openhab/scripts/checkForUpdate.sh”
I have a run Item (OpenHabCheckforUpdate_Ausfuhrung) and a result Item (OpenHabCheckforUpdate_erg )

Thats it. Once every Midnight the script checks for a new release and for my part does notify me via a push notification (not shown here)

1 Like

Hi,
i tested your rule, but i think, it is not working for me?

error log:

2022-12-27 13:12:53.772 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'oh_update.rules'

2022-12-27 13:13:01.486 [INFO ] [ab.core.model.script.update-rule OH3] - Status --> Checking... --- OpenHabCheckforUpdate_erg (Type=StringItem, State=yes

/etc/openhab/scripts/checkForUpdate_OH3.sh: 3: jq: not found

(23) Failed writing body

/etc/openhab/scripts/checkForUpdate_OH3.sh: 3: jq: not found

(23) Failed writing body, Label=Check openHAB Update Ergebnis, Category=time, Groups=[gSystem])

Output of the rule is “yes” but i get “no updates”.

Is there a problem with jq? Is this a linux command? I´m on debian bullseye, maybe i have to install this first? How can i check this?

When i do a sudo apt-get update on my linux, there is no new update for openhab. Currently i´m on 3.4.0.

How can i get your Script-results into openhab to show me the raw output of the curl command?

UPDATE: I installed jq and now it works.

But one last question, is there a way to not only get yes or no from the script, i also want the given version-string from the rule too? Is the only way to make a second sxcript with the same curl command and there give the version to openhab or can i make this inside one script file with only one curl execution?

I want to share a http thing config, which checks the latests version of openhab.
The cannels can be linked with items. You should see the latest stable version.

Code for httb Binding.

UID: http:url:c38e5a34c5
label: OHVersion
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: https://api.github.com/repos/openhab/openhab-core/tags
  delay: 0
  stateMethod: GET
  refresh: 3600
  commandMethod: GET
  contentType: application/json
  timeout: 3000
  bufferSize: 2048
channels:
  - id: ohversionjsonrawdata
    channelTypeUID: http:string
    label: OH Version RAW
    description: ""
    configuration:
      mode: READONLY
  - id: ohversionlatest
    channelTypeUID: http:string
    label: OH Version Latest
    description: ""
    configuration:
      mode: READONLY
      stateTransformation: JS:latest.js

and the contet for the file latest.js :

(function(input) {
    try {
        // Versuche, den JSON-String in ein JavaScript-Objekt umzuwandeln
        var inputData = JSON.parse(input);

        // Überprüfe, ob inputData ein Array ist
        if (!Array.isArray(inputData)) {
            return "Invalid input: inputData must be an array";
        }

        // Filtere die Objekte mit gültigen Zahlen im "name"-Eigenschaft
        var numbersOnly = inputData
            .filter(function(obj) {
                return typeof obj.name === "string" && !isNaN(parseFloat(obj.name));
            })
            .map(function(obj) {
                return obj.name;
            });

        // Überprüfe, ob numbersOnly leer ist
        if (numbersOnly.length === 0) {
            return "No valid numbers found in the inputData";
        }

        // Sortiere das numbersOnly-Array in absteigender Reihenfolge (höchste Zahl zuerst)
        numbersOnly.sort(function(a, b) {
            return b.localeCompare(a, undefined, { numeric: true, sensitivity: 'base' });
        });

        // Gib die höchste Zahl als Ergebnis zurück
        return numbersOnly[0];
    } catch (error) {
        return "Error parsing input: " + error.message;
    }
})(input);

2 Likes