Has anyone setup PiJuice with Openhab 3?

I’ve assembled the PiJuice HAT and installed openhabian & pijuice_cli. I’ve created a py script to create a log file (time stamps of when power goes out, shut down, etc). But I can’t get it to execute as ‘USER FUNC1’. I can run the script as user ‘openhabian’. I’ve tried making user ‘pijuice’ owner of the logfile and python file, but nothing seems to happen.

Any tips on how to get this to work?

Platform information:

  • Hardware: pi3B+ & PiJuice
  • OS: openhabian-pi-raspios32-v1.6.2.img.xz
  • Java Runtime Environment: openjdk 11.0.9 2020-10-20 LTS
  • openHAB version: 3.0.0

As a wider question, how do you setup your PiJuice to back up your system (in case you’ve thought of something I’ve overlooked)?
Thanks
Steve

Just in case it helps anyone else, here are a few things I discovered!

  • For the user script to be executed by the pijuice service, pijuice must be the owner of the script chown pijuice:pijuice <script.py>. Using chmod 777 is not enough if the script requires sudo privileges.

  • You can not pass arguments to the script from the User_Func option. However, pijuice automatically passes several arguments than can be used by the script, the first argument is the type of system event (e.g. no_power), and I think the 2nd one might be the battery charge level.

  • The ‘wakeup on charge’ setting is only copied to the PiJuice when it is shut down due to a ‘low_charge’, ‘low_battery_voltage’ or ‘no_power’ event which then triggers a SYS_FUNC_HALT or SYS_FUNC_HALT_POW_OFF. If you execute the shutdown yourself, the ‘wakeup on charge’ setting is not copied to the PiJuice. If you want to set this parameter in your own python script, use:
    from pijuice import PiJuice
    pijuice = PiJuice(1, 0x14)
    pijuice.power.SetWakeUpOnCharge(xx)
    where xx is the % of charge.

  • As soon as the PiJuice starts the RPi (e.g by a SW1 button press) the ‘wakeup_on_charge’ setting in the PiJuice MCU is cleared. The value is not stored in non-volatile memory. So if the battery is completely empty, i.e. the PiJuice MCU is completely off (No slow weak blinking LEDs) then ‘wakeup on charge’ will not work.

  • It seems best to use SYS_FUNC_HALT_POW_OFF which turns off the 5V to the RPi. WIth the PiJuice in low power mode (weak blinking low frequency LED) it should last several days.

Otherwise, the PiJuice seems like a good option for safely shutting down the pi in the event of a power outage.

1 Like