Exec, HDMI-CEC and powering on/off the TV

It’s just a String Item, if it changes that gets shown in events.log

…Side-question; If i were to remove the *.log files, they would merely get replaced with a empty log file, right?

I´ll have a reboot to make sure everything gets loaded properly, then try again and check the logs.

the log snippet was bad, i am sorry for that!!
edit: log-snippet after reboot

2020-01-13 00:41:37.545 [ome.event.ItemCommandEvent] - Item 'tvCommand' received command OFF
2020-01-13 00:41:37.566 [vent.ItemStateChangedEvent] - tvCommand changed from NULL to OFF
2020-01-13 00:41:37.931 [ome.event.ItemCommandEvent] - Item 'tvCommand_Args' received command echo standby 0 | cec-client -s -d 1
2020-01-13 00:41:37.935 [ome.event.ItemCommandEvent] - Item 'tvCommand_Run' received command ON
2020-01-13 00:41:37.937 [nt.ItemStatePredictedEvent] - tvCommand_Args predicted to become NULL

Okay, one step forward. What you want arriving in “args”

Next -

This is a problem.
Commanding this ON should trigger your exec Thing.
That in turn should update state to ON.
That is missing; exec is not triggered.

Perhaps exec v2.x binding is not installed.
Perhaps your xxx.things file is not loading correctly - check openhab.log

Hmm, now I notice that you’ve made up syntax for your exec Thing

Nope.
Follow the binding documentation. You must specify the Thing type, the exec binding supports only one Thing type, command.
Then add any name you like for this particulatr Thing.

Thing exec:command:MYTV [ ...

Obviously you will need edit your Item channel links to match new valid Thing name.

the log says:
2020-01-13 00:40:20.988 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘exec.things’
According to paperUI, i have binding-exec - 2.5.1.SNAPSHOT installed.

Im not sure if this is relevant, but on the sitemap in the basicUI, the power symbol next to the “TV_pwr” does go red for off, green for on.

Heh oops… :expressionless:
I did fix exec:command in items and things files, now i get the command reported onto the “result” sitemap item!

…but the TV stays on… :crazy_face:

…fresh event log:


2020-01-13 01:00:49.709 [ome.event.ItemCommandEvent] - Item 'tvCommand' received command ON
2020-01-13 01:00:49.726 [vent.ItemStateChangedEvent] - tvCommand changed from OFF to ON
2020-01-13 01:00:49.735 [ome.event.ItemCommandEvent] - Item 'tvCommand_Args' received command echo on 0 | cec-client -s -d 1
2020-01-13 01:00:49.754 [ome.event.ItemCommandEvent] - Item 'tvCommand_Run' received command ON
2020-01-13 01:00:49.770 [nt.ItemStatePredictedEvent] - tvCommand_Args predicted to become echo on 0 | cec-client -s -d 1
2020-01-13 01:00:49.783 [vent.ItemStateChangedEvent] - tvCommand_Args changed from echo standby 0 | cec-client -s -d 1 to echo on 0 | cec-client -s -d 1
2020-01-13 01:00:49.801 [vent.ItemStateChangedEvent] - tvCommand_Run changed from OFF to ON
2020-01-13 01:00:49.837 [vent.ItemStateChangedEvent] - tvCommand_Run changed from ON to OFF
2020-01-13 01:00:49.857 [vent.ItemStateChangedEvent] - tvCommand_Out changed from standby 0 | cec-client -s -d 1 to on 0 | cec-client -s -d 1
2020-01-13 01:00:49.862 [vent.ItemStateChangedEvent] - theReturn changed from standby 0 | cec-client -s -d 1 to on 0 | cec-client -s -d 1

…and openhab.log:

2020-01-13 01:00:49.841 [INFO ] [e.model.script.HDMI-CEC command exec] - Result:standby 0 | cec-client -s -d 1

exec binding doing what it’s told, then.

I can’t comment on what you’re telling it to do.
I note in post 1 that you had quotes in that echo statement. Are those not needed now?

Mind you, I think it’s still just doing what you asked ? Executing
echo on 0 | cec-client -s -d 1
echoes
on 0 | cec-client -s -d 1
into your results. Is it supposed to go somewhere?
I don’t know linuxy stuff but imagined echo just “types out” what you tell it.

Ive been trying some variations and i did botch the copy/paste before, so it might have happened more than once…

The correct (and working) command is:

echo standby 0 | cec-client -s -d 1

and im able to run it with:

sudo -u openhab echo standby 0 | cec-client -s -d 1

The command is supposed to send “standby” to HDMI-CEC-device 0 (tv) via cec-client, -s = single command, -d 1 = seems to be debug level, controls how much feedback info i get.

cec-client is a part of a “toolbox”, its a progam i downloaded off internet… :slight_smile:

I think pipe | is unworkable in exec; this is not a console environment.
(I’m guessing because exec itself pipes the results)

Why don’t you call this cec-client script thingy directly?

1 Like

due to my incompetence, thats why. :slight_smile:

i dont think its a script tho, it does install and it has a man-page… (witch doesnt help me at all tho)

A little digging seems to show cec-client does not support direct command line parameters. Seems stupid to me, but I am not linuxy.
Here’s a script that seems to tackle that-
https://www.raspberrypi.org/forums/viewtopic.php?t=67899

Here’s an old thread (using a little script to workaround pipe)

1 Like

its working!!! :smiley:

Im now using the script you linked to, seems to work just fine and does cover all my needs!

However, im trying to figure out how to link to that OFF-function in the habpanel, and how to group the off-function with my AllOff group, to turn off all lights and devices with a “goodnight”-button.

So if anything comes to mind, i would greatly appreciate the hint!

Thank you rossko57, for all your help and efforts, i would certainly not have solved this problem without your guidance!

1 Like

To summarize for later readers, the underlying problem here is that pipe | does not work the way you expect in exec binding or action context.

I don’t think that’s a bug, it’s just the way it works.

EDIT - it appears pipe may be made functional soon

1 Like

I can elaborate just a little bit.

When you log into a command line on a Linux/Unix/BSD type machine you are using what is called a “shell”. That is what sh, bash, ksh, zsh, fish (my favorite) etc. are all about. They provide your user interface between the terminal and the operating system. I want to say that again, it is a user interface.

A lot of the stuff that you find when using the command line is implemented by the shell. This includes anything that has to do with text redirection and kicking off programs. So pipes, >, ; to separate commands on one line, && between commands on a line to only run the second command if the first one succeeds, etc. are all features that are provided by the shell. And not all features are provided by all shells and sometimes they are different. For example the following in bash

sudo apt update && sudo apt upgrade

would be the following in fish.

sudo apt update; and sudo apt upgrade

When you are running commands from openHAB using the Exec binding or executeCommandLine, you don’t have a shell. So all of those nice features like pipes and running multiple commands on one line and such are not available to you. So the above two lines can not be run from openHAB directly.

If you need features like pipe or you need to execute more than one command, you need to put it all into a script and call the script. When you have a shell script the first line (for example #!/bin/bash) is a directive that tells it to execute the following code in the given shell. This is what lets you use stuff like pipes in a shell script.

2 Likes

I have a follow-up question:

I would like a “current state”-item on the sitemap that checks wether the TV is ON or OFF every xx seconds.

The shellscript im using is already prepared for the data;


[13:12:55] pi@openHABserver:/opt$ ./hdmi_cec_cmd.sh status
power status: on

I dont have a clue how to do things automatically in the background in openHAB and im not finding much helpful while searching…

Looks like a job for a new exec Thing, using interval= ?

Thanks, that did it! :smiley:

I added the required things/items in the current config files and appearantly that works just fine :slight_smile:

Its a amazing system, this openHAB, a real bitch to work with for a n00b, but its very rewarding!

Learning curve is steep, and with many flexible features it easy to pick the “wrong” (or at least, less efficient) alternative.

In this case for example, you could have used a cron-triggered rule to poll TV, it would work. But the binding auto feature is slicker.

Don’t be afraid to ask, even with the odd grumpy answer :wink:

1 Like