"Nextcloud: update available" sensor

I´m thinking of a Nextcloud updater sensor which indicates there´s an update available. Nextcloud lacks of a functional notification feature for new versions, unfortunately that´s an “issue” from the beginning which lasts until today.

This is no plug’n’play manual, instead I´d like to know if maybe someone else already built something like that. Currently I use

In other areas there´s great progress in creating all kinds of update sensors, mainly for internal Home Assistant reasons: Update notifications! Core, HACS, Supervisor and Addons is a great inspiration for that.

Here´s my current approach (long story short: everything needed exists, it´s just not combined yet…):

What do we need? 3 things:

1) Current Nextcloud version.
1.a) Use Nextcloud - Home Assistant integration to get current version installed (sensor.nextcloud_system_version), looks like
1.b) SSH to Nextcloud server (see SSH'ing from a command line sensor or shell command for general notes) and grab current version remotely, e. g. by cat + grep + cut the config.php

2) Latest Nextcloud version available (advanced: for current release channel selected)
2.a) Grab this directly from GitHub like @Tomahawk provided for another software (related to Home Assistant) here: deConz Addon - deConz Firmware integration sensor - #6 by Tomahawk
2.b) Get it from Nextcloud updater feed (https://updates.nextcloud.org/updater_server/). For this some Nextcloud instance information (version, release channel etc. - all in a specific format) is needed. So I think getting it remotely once again by SSH-ing to Nextcloud server is necessary.
UPDATE: According to Mailbenachrichtigung bei verfügbaren Nextcloud Updates - xela's Linux Blog the “new” occ update:check also covers Nextcloud and is probably the easiest way to go. Output looks like:

pi@nextcloud-server:~$ sudo -u www-data php /var/www/nextcloud/occ update:check
Nextcloud 21.0.3 is available. Get more information on how to update at https://docs.nextcloud.com/server/21/admin_manual/maintenance/upgrade.html.
Update for news to version 16.0.0 is available.
2 updates available

So it seems to cover ALL available updates, not only apps (which can be detected by using occ app:update --showonly by the way).

3) Nextcloud Update Sensor
Finally we need to compare current (1) and latest (2) Nextcloud version and set sensor state accordingly.

Where I´m stuck currently: step 2.

I´m not sure which way - 2.a) or 2.b) - is the best to go. Both will probably need a bit of testing and tweaking until if finally works.

Currently I use an eMail based Nextcloud update notification based on Mailbenachrichtigung bei verfügbaren Nextcloud Updates - xela's Linux Blog.

Bringing Nextcloud and Home Assistant a bit closer would be awesome. Curious to see what others think about this.

For #2 did you try the github integration? It watches a repo and tracks metrics about it in a sensor. One of the available attributes is latest release tag

Hi, I’m looking for the same solution.
Did you manage to make the “update available” sensor for Nextcloud?
The official nexcloud integration only has nextcloud_system_apps_num_updates_available sensor, but that is only about the apps, not the Nextcloud itself.
Github doesn’t show the latest version unfortunately, for example right now it shows 22.1.1 as latest stable, however the nexclout updated itself to 22.2.0 at Stable channel.

Parsing the output of

sudo -u www-data php /var/www/nextcloud/occ update:check

seems the right sloution, but can’t get HA to run PHP script from command line. Can anyone with the right way to do it?

I didn´t continue to work on this yet, but as I´ve done this several times meanwhile I think I´ll go with 2.b). Will take me probably one hour to implement it including GUI and notification automation, maybe next weekend.

You need to remote SSH to your Nextcloud server from HA server to run the occ update:check command. See step 1.b) (SSH'ing from a command line sensor or shell command) for this.
OR you store this peace of information on a storage readable by your HA server:

  • Nextcloud server: export current and latest NC version information → store as file on [shared storage] → HA server: read that information from file in sensor.

I´ll postpone my NC update to major 22 release until I implemented and tested the NC update sensor in HA. Will report back.

1 Like

Okay, i’ve got the output of this in HA via command line sensor:

sudo -u www-data php /var/www/nextcloud/occ update:check

Now all is left is to interprete it correctly.

There is a sensor already named sensor.nextcloud_system_apps_num_updates_available, I guess it’s value the same as the number in this line of output:

2 updates available

Do you know if this value includes only apps updates or adds +1 if there is also an update for server itself? Will it be “1” if only server has an update?

  • sensor.nextcloud_system_apps_num_updates_available = 2
  • occ update:check = 3 updates available

But I don´t care of sensor.nextcloud_system_apps_num_updates_available as I´ll be string-cutting the occ update:check output and if there´s a “Nextcloud XX.X.X is available” (probably with RegEx to make it bullet-proof) or “Get more information on…” in one line I´ll read that version as string to my command line sensor sensor.nextcloud_core_version_available.


  • As long as they don´t change the syntax of the occ update:check output, this should reliably work.
  • First class and rock solid solution would of course be to have the “available release version” information available via existing API (which is where the Nextcloud - Home Assistant grabs its information from). But I´ll better go with what´s available today, not maybe in future :wink:

Done. I already had the app update section below, only the upper server part is new.

Update available:

No update available:

For command line sensor I used this: :warning: OLD :warning:

  - platform: command_line
    name: Nextcloud Version latest
    scan_interval: 21600
    command_timeout: 60
    command: "ssh [email protected] -i /config/.ssh/id_rsa -o UserKnownHostsFile=/config/.ssh/known_hosts ''sudo -u www-data php /var/www/nextcloud/occ update:check | grep -oP '(?<=\\Nextcloud )(\\d*\\.)+(\\d*)(?= is available.)'''"
    value_template: "{{ value }}"

Update 2021-11-07:
I discovered HA shell has some issues with the Perl based RegEx of grep (grep -oP '...') which lead to latest sensor becoming unavailable. Therefore I decided to create the latest version information on the NC server (which can run the grep command without any issues) and HA just pulls that version information via SSH.

1. Script /home/user/tools/Nextcloud_GetLatestVersion.sh' on NC server


LVERSION=$(sudo -u www-data php /var/www/nextcloud/occ update:check | grep -oP "(?<=\\Nextcloud )(\\d*\\.)+(\\d*)(?= is available.)")

echo "$(date +%F\ %T\ %Z) - Script 'Nextcloud_GetLatestVersion.sh' has been started" >> $LOG

if [ -z "$LVERSION" ]; then
  echo "noupdate"
  echo "noupdate" >> $LOG
  echo $LVERSION
  echo $LVERSION >> $LOG

echo "$(date +%F\ %T\ %Z) - Script 'Nextcloud_GetLatestVersion.sh' has been finished" >> $LOG

exit 0

2. New command line sensor definition in HA for latest version

  - platform: command_line
    name: Nextcloud Version latest
    scan_interval: 3600
    command_timeout: 60
    command: "ssh [email protected] -i /config/.ssh/id_rsa -o UserKnownHostsFile=/config/.ssh/known_hosts ''/home/user/tools/Nextcloud_GetLatestVersion.sh''"
    value_template: "{{ value }}"

3. New updater sensor definition in HA

  - platform: template
    scan_interval: 3600
        friendly_name: "Updater - Nextcloud"
        icon_template: "mdi:update"
        value_template: >-
          {% set current = states('sensor.nextcloud_system_version') %}
          {% set latest = states('sensor.nextcloud_version_latest') %}
          {% if (latest == 'noupdate') %}
          {% else %}
            {% if (current != latest) %}
            {% else %}
            {% endif %}
          {% endif %}

If no update is available, sensor.nextcloud_version_latest shows noupdate which the updater sensor checks first. Hint: using none is not possible because it seems to be magical in HA.

As mentioned still not a perfect solution (basically I implemented option 2.b) from my original post) because it requires remote SSH-ing to Nextcloud server, but still the best option as long as latest available version - for that particular server with selected release channel, big improvement compared to option 2.a)! - is not made available via API.

1 Like

Updated solution post (further optimization of sensors, added ‘no update available’ screenshot).