Sending SSH Command to Remote Mac (iTunes / play-pause)

Hi Guys,

i want to play/pause my iTunes on my main-mac with OpenHAB.
in the terminal its already working without any password required
( i generated a key on both machines - “tutorial” can be found here )

its already working with this here:

ssh username@192.168.1.x 'osascript -e "tell application \"iTunes\" to playpause"'

now i am able to Play/pause iTunes in Terminal but not in OpenHAB. I already installed the EXEC Binding.

my .item looks like this

Switch iTunes {nh="192.168.1.x" exec="OFF:ssh xxxx@192.168.1.x 'osascript -e "tell application \"iTunes\" to playpause"'}

But its not working… :frowning:
How do i solve this ?

THANKS

is the account that openhab is running under the same as the one you installed the keys for? ie, the user account you are using to interactively run the ssh commands without prompts the same as what openhab is running under?

1 Like

Your binding config was not formatted correctly. You were also missing a double quote at the end, and needed to escape some more of the quotes. When the escapes become a nightmare, you can just put the command into a shell script and call that from exec. Easier to test it too! See if this works:

Switch iTunes {nh="192.168.1.x" exec=">[OFF:ssh xxxx@192.168.1.x 'osascript -e \"tell application \\\"iTunes\\\" to playpause\"']"}
1 Like

THANKS for you Ideas guys

its not working :frowning: after i insert this code in my .items file and press save i get this message in the log:

2017-09-28 12:33:48.043 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.items'
2017-09-28 12:33:48.161 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.items' has errors, therefore ignoring it: [214,33]: missing '}' at 'exec'
[214,37]: mismatched input '=' expecting RULE_ID

dont know how to do that :frowning:

I think so :sweat:

Ah… binding configs need to be separated with a comma:

Switch iTunes {nh="192.168.1.x", exec=">[OFF:ssh xxxx@192.168.1.x 'osascript -e \"tell application \\\"iTunes\\\" to playpause\"']"}
1 Like

Thanks man! now i dont get any “errors” in the log, all is looking good now, but its not working :frowning:

ANY IDEAS ?
THANK you!

Cool!

Try turning up the logging for the exec binding and see what it is reporting for the response by entering this into the Karaf console (when you’re done, put it back by entering the same but replace DEBUG with WARN):

log:set DEBUG org.openhab.binding.exec

Maybe there’s something you can check on the other end?

i see nothing in the log :frowning:

i maybe found a (german) solution here, but cant get it to work

in the end i want to have something like this :smiley:

Are you looking in the openhab.log? If you’re not seeing exec binding logs after toggling the switch, then the logging isn’t setup right. What does log:get show?

Another thing to try is to switch to the same user that is setup to run OH, and run the ssh command in the console. That would show you if the permissions were setup correctly.

43

this is working:

The log:get shows that you don’t have the logging turned on for the exec binding:

log:set DEBUG org.openhab.binding.exec

42

How about log:list?

02

Cool, but weird… log:get worked for me, but I’m on a 2.2.0 snapshot with an updated Karaf.

So… logging is good, but there’s nothing for exec in the openhab.log after toggling the switch? :thinking:

no :frowning: just this:


2017-09-28 14:31:24.254 [ItemCommandEvent          ] - Item 'iTunes2' received command ON
2017-09-28 14:31:24.256 [ItemStateChangedEvent     ] - iTunes2 changed from OFF to ON

That looks like the events.log

ohh sorry i am a newbie, how do i get to the openhab.log ? thx

i am here atm:
http://192.168.1.100:9001/

O, well then you’ve got it. Hmmm.

Do you have the OH2 Exec binding installed and not the OH1?

bundle:list |grep Exec