Running Script with a Switch

You could run a cron job that runs a script that polls the state of an item through the REST API, and depending on the state, could power off the NAS.

1 Like

It depends on your needs and requirements. For you and many it may not be a good choice. For me and others it’s perfect for our needs. For still others it’s their only option.

There are over 330 bindings. If only 329 of them work in the Docker container does that negate it’s utility entirely? Not in my opinion.

1 Like

Hello,
I am pretty new to the topic of openHAB2, so I got some questions concerning your script.
Just to test with my Synology I tried to copy/paste everything to a fresh install of openHABian.
Bindings used were WOL, NETWORK, EXEC.
The WOL function and Status function work without issues, but I have issues with the shutdown.

My items file is like this:

Switch DS215j "Diskstation DS-215j" {	
	channel="network:pingdevice:192_168_178_xx:online",		
	exec=">[OFF:sudo ssh USERNAME@192.168.178.xx shutdown -p now]",
	wol="192.168.178.255#MAC-ADRESS"
									}

The errorlog always gives an error that it cannot run script “error=33”.
My assumption is that the openhab user does not have the rights to run the script. I also tried changing user and group in /vusr/lib/systemd/system/openhab2.service to root:root but it did not work.

Basically what I want to do is, have a Sitemap-switch that gives status of NAS and can WOL the NAS, as well as shut it down.

SSH commands I cannot get working because I dont want to mess with my NAS (ssh.key login).
Is there any other way? I mean the DS Finder app on my phone can shut the Synology down without issue/messing with ssh keys and so on.

Help would be greatly appreciated.

Sadly my setup stopped working.
Starting the NAS still works but stopping it doesn’t.

When I run the script directly on the command line, it works without any issue.

When I use the switch via openhab, it does not work.Noting happens.

The Log says it runs the script, but also runs the start command directly after.

2020-09-12 12:43:43.572 [INFO ] [lipse.smarthome.model.script.Network] - Switching NAS OFF: ON
2020-09-12 12:43:43.644 [INFO ] [lipse.smarthome.model.script.Network] - Switching NAS OFF: ON
2020-09-12 12:44:02.157 [INFO ] [lipse.smarthome.model.script.Network] - Switching NAS ON: ON
2020-09-12 12:44:02.194 [INFO ] [lipse.smarthome.model.script.Network] - Switching NAS ON: ON

Sadly noting happens.

Any idea?

Have you looked at other postings, like this one?

I’d start by using executeCommandLine in a rule so that you can examine the result.

Is there already a rule involved here? Maybe you ought to share that.