Openhab-cli console +cron

  • Platform information:
    • Hardware: Pi 3
    • OS: openhabian
    • openHAB version: 2.5

Hi,

I have issue with homekit where is loses connection; while I’m working the root cause of the issue, I’m using the command

openhab-cli console -p xxxxxx bundle:refresh org.openhab.io.homekit

Which works; so I thought I’d automate it in cron (every hour or so) to make sure I’m never without connectivity too long.

However, it does not work from cron. I presumed it was a path/env variable that was the issue so I created a shell script (which works) and called that from cron (which didn’t work).

!/usr/bin/env bash

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

export OPENHAB_HOME=/usr/share/openhab2
export OPENHAB_USERDATA=/var/lib/openhab2
export OPENHAB_CONF=/etc/openhab2
export OPENHAB_HTTPS_PORT=8443
export OPENHAB_BACKUPS=/var/lib/openhab2/backups
export OPENHAB_HTTP_PORT=8080
export OPENHAB_LOGDIR=/var/log/openhab2
export OPENHAB_GROUP=openhab
export PENHAB_RUNTIME=/usr/share/openhab2/runtime
export OPENHAB_USER=openhab

openhab-cli console -p habopen bundle:refresh org.openhab.io.homekit

Nothing obvious in the logs, and redirecting output doesn’t reveal anything useful.

Any tips would be helpful (until I resolve the underlying issue).

Thanks.

Instead of

openhab-cli console -p habopen bundle:refresh org.openhab.io.homekit

try this

echo bundle:refresh org.openhab.io.homekit | openhab-cli console -p habopen

I did a trial with another command and that seemed to work.

Thank you. I will try that and report back.

For me, this works, but only as part of the external shell script, not directly from cron.

Thank you again.

shall we have a look into and check why it does not work from cron and try to find a solution ?
Background just in case that you are not aware of it: not all environment settings like PATH are the same as in your users account.
It could be that just a few envonrment variables are missing.

Check openhab-cli to see it calls ${OPENHAB_RUNTIME}/bin/client when you provide the console argument

Hi,

Sorry, I explained that poorly. It does work from cron, but only as part of the shell script (with the PATH and other environment settings set)

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

export OPENHAB_HOME=/usr/share/openhab2
export OPENHAB_USERDATA=/var/lib/openhab2
export OPENHAB_CONF=/etc/openhab2
export OPENHAB_HTTPS_PORT=8443
export OPENHAB_BACKUPS=/var/lib/openhab2/backups
export OPENHAB_HTTP_PORT=8080
export OPENHAB_LOGDIR=/var/log/openhab2
export OPENHAB_GROUP=openhab
export PENHAB_RUNTIME=/usr/share/openhab2/runtime
export OPENHAB_USER=openhab

echo bundle:refresh org.openhab.io.homekit | openhab-cli console -p habopen

1 Like

Hi,
this is correct and normal, expected behavior of cron.
There is one typo in the list of environment variables - the O for OPENHAB_RUNTIME is missing.

To close the loop, I no longer need the clii.

I had two issues causing the HomeKit connection to be lost.

  1. The Raspberry PI was running slowly. I haven’t 100% confirmed this, but from observation it appears the connection was timing out. I fixed this with zram config.

  2. The firewall was blocking avahi ports. The firewall allowed the initial connection (to the homekit binding) but it would block some mdns. Opening the ports fixed this.

Thank you again for your help.