(Another) rule not executed

Moin,

I struggle quite a while looking around everywhere, but I did not find the solution for my (simple?) problem.

I would like to run a script on a regular basis to update the status of my sony TV.
Running the script in a shell works well.
but not in my rule, which looks like this:

rule “Ist TV an?”
when
Time cron “0 0/3 * * * ?” // every 3 minutes
then
executeCommandLine( “/etc/openhab/configurations/scripts/sonyTVcheck.sh” )
end

I read a lot about substituting spaces with @@, but this is obviously not the problem here.
By the way: Would Habmin find the right syntax for this kind of work?
Would this solve all my syntax issues (there are a lot more, I guess).
Thanks.

NCO

When you run the script from the command line, are you running it as root?

With a default install of openHAB (i.e. apt-get install) openHAB runs as openhab:openhab and may not have permission to access or run that script

Habmin wouldn’t help with this problem. If you are having syntax problems, openHAB-Designer was created to help with that.

Actually I runs it as pi.
I have placed the script (using curl, if this is relevant) in the openhab home folder:
/usr/share/openhab/configurations/scripts (yes, it’s an apt-get installation),
Furthermore I changed the permissions to 755 and are able to run it as pi (no duso).
So, if openhab runs as openhab, this user should be able to run it as well.
And obviously it’s executed:
2015-10-18 05:03:00.014 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘/etc/openhab/configurations/scripts/sonyTVcheck.sh’

Change this:

To this:

executeCommandLine( “curl@@/etc/openhab/configurations/scripts/sonyTVcheck.sh” )

That’s how I have all of my command calls formatted.

Hopefully @p912s 's advice will help. But just for clarity:

That just means that the ExecUtil didn’t run into any problems. Try the following so you can see what the script actually outputs:

var results = executeCommandLint("/etc/openhab/configurations/scripts/sonyTVcheck.sh", 5000)
logInfo("SonyExec", results)

The new argument is a timeout. Without that it executes the command line off in another thread and you never see any of the outputs from the script. This may reveal an error or give other clues as to why the script isn’t running.

Woke up this morning and realized you were running a shell script and not executing a command…

Change this:

To this:

executeCommandLine( “./etc/openhab/configurations/scripts/sonyTVcheck.sh” )

What you enter between the quotes in the command to execute needs to be the same as what you type manually at the command prompt.

Thanks for even dreaming about my problem :wink:
Sorry for that.

but between the quotes is EXACTLY what works for me in the command prompt.

Your suggestion
./etc/openhab/configurations/scripts/sonyTVcheck.sh
does not work in the command prompt. :frowning:

I am really frustrated.
It shouldn’t be so difficult to run a single script.

Pls post the content of your sh script!
Maybe the Problem can be located there!
Did you tested it in the shell?

Hi Peter,

My script looks like this:
#!/bin/bash
RESULT_SO=echo pow 0 | cec-client -d 1 -s | grep "power status:" | awk '{ print $3; }'
echo $RESULT_SO

In the shell it returns “on” or “standby” depending on my TV’s state.
The rule looks like this (I changed it after I created a different functional rule:

rule “request Sony TV status”
when
Time cron “0 0/3 * * * ?” // every 3 minutes -> works as expected !!!
then
var result_TV = executeCommandLine("/etc/openhab/configurations/scripts/readTVstate.sh", 5000)
logInfo(“BLABLA sony.rules - TV Status”, result_TV)
if(result_TV == “on”) {
postUpdate(Sonne_TV, ON) }
else {
postUpdate(Sonne_TV, OFF) }
end

The returned value (e.g. “on” is not shown in the log (logInfo …), so the issue must be somewhere where the result is handed over to the openhab rule.

Actually I get an error message in the openhab supporting my guess that there is no hand over from the script to the rule.

2015-10-22 20:33:00.362 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn’t post update for ‘Sonne_TV’

However the same combination works with a different pair of rule / script.

Are you sure the script finished in 5 seconds? If it took longer you would get a null back. Try upping the timeout.

I thought about that but found out that the response from the script in the shell came within 2-3 seconds.
However, I tried a timeout of 20000 (20 seconds), but it didn’t help.

I have the same problem with another script using the cec-client for starting up or shutting down my TV. It looks like this:
#!/bin/bash
echo ‘on 0’ | cec-client -s >> /tmp/sonyTVon.log

Very simple!
It works in the shell and starts my Sony TV.
When I do an exec like this:
Switch Sonne_TV_2 “TV script” { exec=">[ON:/etc/openhab/configurations/scripts/sonyTVon.sh]" }

It seems to work as well (openhab.log):
2015-10-23 13:23:51.137 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine ‘/etc/openhab/configurations/scripts/sonyTVon.sh’

But when I check the logfile created by the script above (/tmp/sonyTVon.log), there is obviously a problem:

  • failed to open vchiq instance

I guess this is the root cause also for the other problems.
Did not find a proper solution though…

  1. Adding openhab user to the video group did not help

We have eliminated user permissions as a problem (I think).

So there must be something else different between the pi user’s environment and the openhab user’s environment. Are there any differences between pi and openhab’s environment variables, in particular the PATH?

pi’s PATH is:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

openhab’s PATH:
/sbin:/usr/sbin:/bin:/usr/bin

However, I played a little this morning and now it works.

I actually don’t know and just can imagine that adding openhab to the video group required a restart of openhab!?

Anyway, here are the functional rule:
rule “Sony TV State”
when
Time cron “0 0/2 * * * ?” // every 2 minutes -> works as expected !!!
then
var result_TV = executeCommandLine("/etc/openhab/configurations/scripts/readTVstate.sh", 5000)
logInfo(“sony - BLABLA TV Status”, result_TV)
if(result_TV == “on”) {
postUpdate(Sonne_TV, ON) }
else {
postUpdate(Sonne_TV, OFF) }
end

and script:
#!/bin/bash
RESULT_SO=echo pow 0 | cec-client -d 1 -s | grep 'power status:' | awk '{ print $3; }'
echo $RESULT_SO

Problem solved (my second issue switching the TV) !!!
Working version:

Switch Sonne_TV “TV per script” { exec=">[ON:/etc/openhab/configurations/scripts/sonyTVon.sh] >[OFF:/etc/openhab/configurations/scripts/sonyTVoff.sh]" }

I actually don’t know why - it might have been related to the acces rights. That’s why I used a “sudo” in the exec command above.
Additionally I added the user openhab (standard openhab user) to the video group.

The according script I run (see exec above, located in the script folder of openhab) looks like this:
#!/bin/bash
echo ‘on 0’ | cec-client -s