Checking for openHAB updates - simple rule

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