Automatic shutdown rule for an PI5, when an Item changes

Sure, but nothing about this prevents NUT from shutting down the RPi first.

If NUT handles everything, it will automatically send a shutdown command at 300 seconds. Instead, OH has to update the item to see that it’s under 300 seconds and then run a rule to shut down.

Thats why we’re all saying it’s better for NUT to do everything. Your solution works, but it is more complex by design.

1 Like

actions is the namespace
In the OP’s example he was passing this

script: executeCommandLine("sudo","poweroff") //OH3 version with new
        executeCommandLine syntax

and getting the error

2024-08-15 09:05:28.521 [ERROR] [omation.script.javascript.7a2ff73a12] - Failed to execute script: ReferenceError: "executeCommandLine" is not defined
        at <js>.:program(<eval>:1)

If you just passed the Exec class only

Exec.executeCommandLine(time.Duration.ofSeconds(3),"sudo","poweroff");

you would see this

2024-08-17 13:07:21.156 [ERROR] [omation.script.javascript.cd71d4fe5b] - Failed to execute script: ReferenceError: "Exec" is not defined
        at <js>.:program(<eval>:1)

so by adding the actions. namespace insures that the script resolves correctly and knows what and where to look for the class and method it needs to execute
as explained at the beginning of the github link you pointed too.

actions

Description:

  • Actions namespace.This namespace provides access to openHAB actions. [All available actions]
  • Hope that answers your question.

It is also considered best practice to keep the interaction with the actual Operating System as simple as possible when trying to manage a device activity such as the power cycling and not add additional points of failure for those critical actions such as shutting down or rebooting the entire server.
One other point to make

A power outage is always an extreme case of unknown and unexpected behaviors regardless. It is very possible that other devices that have lost power and now become unresponsive may cause Openhab to be slower to respond or worse hang as it polls device status’s depending on what bindings you have enabled and devices you have installed and how you have them configured.

This page documents how to use the JS Scripting helper library (i.e. openhab-js) in a rule. This is always going to be the documents you look at to write a rule/script.

This is the internal documentation of the helper library. These docs are only relevant if you are making changes to the helper library itself or if you want to do something that is not exposed directly by the helper library. If you are just writing standard rules these docs are never going to be relevant to you.