Thanks for all for all the tips.
I have not seen the tip from @Oliver2 with the “actions.Exec.”
Added this, now it work, perfectly.
I will now do a short summery what I have had do that it works:
Precondition:
A: “Network UPS Tools Binding” is installed
B: An Thing is created with the active NUT server, which is my case is my local NAS Server
C: All the channels are created, e.g. the channel “Battery Runtime”
The configuation starts:
- Install the “exec Binding” (—> Not needed anymore, see comment down)
- Created a file under cd /etc/sudoers.d/ called accessrights
sudo visudo -f /etc/sudoers.d/accessrights
Content of the file is:
# Allow openhab user to execute shutdown, poweroff, and systemctl commands
openhab ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/poweroff, /sbin/systemctl, /sbin/reboot
- Open the file with
sudo visudo
and added here:
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
openhabian ALL= NOPASSWD: /sbin/poweroff, /sbin/reboot
- Edit the next file under /etc/openhab/misc
sudo nano /etc/openhab/misc/exec.whitelist
and added to the file “exec.whitelist”
/sbin/poweroff
/sbin/poweroff -i
/sbin/reboot
# For security reasons all commands that are used by the exec binding or transformation need to be whitelisted.
# Every command needs to be listed on a separate line below.
5.Final I have created a rule which looks like this:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: NetworkUPSTool_BatteryRuntime
state: < 300 s
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: actions.Exec.executeCommandLine("sudo","poweroff")
type: script.ScriptAction
Thats all, I hope I have nothing forgotten.
So, the rule start when my UPS (the NUT server is installed on my NAS), has less that 300 sec
livetime and then it shutdown my PI5 and my PI4 (prod and test system), that I do not have a data lost when the power would be away. Normal lifetime from all attched clients conneted via the UPS is ~ 25min.
One more thanks to all, and I hope some other can participate from this.