[Solved] Exec a command on command line with Amazon Dash button

Hi,
i try on a raspberry pi 3 with openhab2 to execute a command line with a *.sh file

I have in

items

Number    yeelightwz                 "Yeelight"         <lamp>          {channel="exec:command:yeelightwz:run"}

in

sitemaps

    Frame label="Erdgeschoss" icon="groundfloor" {
        Group item=GF_Terrace
        Switch item=yeelightwz

in

things

Thing exec:command:yeelightwz [ command="sudo -u /home/pi/yeelight.sh", interval=0, autorun=false ]

in

rules

rule "Yeelight_Living"

        when
                Channel "amazondashbutton:dashbutton:xxxxxxxxxxxxxx:press" triggered
        then
                yeelightwz.sendCommand( )
                logInfo("Your command exec", "Result:" + yeelightwz_out.state )
end

but i get a error in log

2018-04-19 17:18:56.225 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Yeelight_Living': An error occurred during the script execution: index=1, size=1

my sh file is:

#!/bin/sh
echo -ne '{"id":1,"method":"toggle","params":[]}\r\n' | nc -w1 192.168.0.76 55443

I did not find the error :frowning:

sendCommand returns instantly and then processes in the background. It is highly unlikely that your script will have even started executing let alone finished executing and put the result in the yeelightwz_out Item (which you didn’t not post the definition for.

So, have you defined yeelightwz_out?

You should create another rule that triggers when yeelightwz_out changes and put the logInfo log statement there.

Can you run the script from the command line as the openHAB user? I ask becasue the command in your Thing looks incorrect. You usually provide a user name when prioviding the -u option.

sudo -u openhab sudo -u /home/pi/yeelight.sh

This will attempt to run the script you have in your Thing as the openhab user, which is the user openHAB runs under.

1 Like

I have solved it with the yeelight binding, i dont know why, but this openhab2 drives me crazy!
first time test the yeelight wasnt working, and after the exec was not working i tried to go back to yeelight binding and it works now. I HATE IT :slight_smile:
I have now installed the yeelight addon manually and here are my items and rules and things:

[ITEMS]

Switch  yeelightwz              "Switch"        <switch>        {channel="yeelight:Wonder:0x0000000004546:Brightness"}
Switch  yeelightoben              "Switch"        <switch>        {channel="yeelight:Wonder:0x000000000253654:Brightness"}

[RULES]

rule "Yeelight_Living"

        when
                Channel "amazondashbutton:dashbutton:xxxxxxxxxxx:press" triggered
        then
                if (yeelightwz.state.toString == "ON") {
                yeelightwz.sendCommand(OFF)
                } else {
                yeelightwz.sendCommand(ON)
                }
end
rule "Yeelight_Oben"

        when
                Channel "amazondashbutton:dashbutton:xxxxxxxxx:press" triggered
        then
                if (yeelightoben.state.toString == "ON") {
                yeelightoben.sendCommand(OFF)
                } else {
                yeelightoben.sendCommand(ON)
                }
end

[Sitemap]

sitemap Hause label="Hause" {
    Frame label="Kalender" {
       Text item=CurrentDate
    }
    Frame label="Erdgeschoss" icon="groundfloor" {
        Group item=GF_Terrace
        Switch item=yeelightwz
        Switch item=yeelightoben
    }


[Things]

ntp:ntp:local [hostname="0.pool.ntp.org", refreshInterval=60, refreshNtp=30, locale="", timeZone="Europe/Vienna" ]
Switch item=yeelightwz_switch
Switch item=yeelightoben_switch