This page last changed on Mar 23, 2015 by jesperlykke.

Hello all here.

I have made this RPI-HomeBox, which contains 4 relays for main power, IR-blaster, and IR reciver.

While it all works, i have tried to make a switch for switching some of the relays on|off
I have made a lot of different shell scripts, for testing, but need a switch with on|off state now!

I would really like an example of a shell (.sh) script, which returns a value, which is usefull for a sensor.
Does anybody have the possibility to paste such a script here ?

Rgds; Jesper

Cannot resolve external resource into attachment.

Cannot resolve external resource into attachment.


5.png (image/png)
6.png (image/png)
22stat.PNG (image/png)
22OFF.PNG (image/png)
22ON.PNG (image/png)
22Sensor.PNG (image/png)
22switch.PNG (image/png)
Panel.PNG (image/png)

Soo

No matter what i do, i cannot make it work.

I got the sensor, i got the switch, and i got commands for turn on, and turn off... and ofcause the sensor status command.

I tried every possible exit's from my shell scripts, therefore i got both echo "on", exit 1 etc...

I think i can make it work, if i just know how the exit of my script must look like?
Also i have doubt, if i must use a sensor name.

Anybody got some working scripts (#!/bin/sh) ??

Rgds; Jesper.

----------------------------------------

#!/bin/sh

  1. turn on gpio 20
    /usr/local/bin/gpio write 20 1
    echo "on"
    echo "1"
    exit 1

----------------------------------------

#!/bin/sh

  1. turn off gpio 20
    /usr/local/bin/gpio write 20 0
    echo "off"
    echo "0"
    exit 0

----------------------------------------

#!/bin/sh

  1. sensor
    status=$(/usr/local/bin/gpio read 20)

if [ $status = 1 ]; then
echo "on"
#/usr/local/bin/gpio write 20 1
exit 1

fi
echo "off"
#/usr/local/bin/gpio write 20 0
exit 0

-------------------------------------------

Cannot resolve external resource into attachment.

Cannot resolve external resource into attachment.

Posted by jesperlykke at Mar 24, 2015 19:05

Hi Jesper

I managed to work with the GPIO's through the Webiopi.

Check the link below.

http://www.openremote.org/pages/viewpage.action?pageId=23593362

Hope this helps.

Posted by edgi at Mar 25, 2015 07:06

No matter what i do, i cannot make it work.

You should always reboot the controller (stop/start) after amending and uploading a new design with shell command protocol. There is a bug in the implementation that it work properly only from the cool boot.

echo "on", echo "1" should be OK.

Posted by aktur at Mar 25, 2015 07:31

Hi Thanks.

I will check it out...
I see in link, you made it work with openremote integration ? -Right?

Anyway, thanks for answer!

Rgds; Jesper.

Posted by jesperlykke at Mar 25, 2015 08:11

Hi.

Thanks for confirming that echo "on" and/or echo "1" gives the right return from shell (!#/bin/sh).
So my scripts again :

#!/bin/sh
#turn on gpio 20
/usr/local/bin/gpio write 20 1 # <--- working
echo "on" # <---- NOT neccesary i think?
exit

#!/bin/sh
#turn on gpio 20
/usr/local/bin/gpio write 20 0 # <--- working
echo "off" # <---- NOT neccesary i think?
exit

#!/bin/sh

  1. on-off sensor
    status=$(/usr/local/bin/gpio read 20) # <---- Working
    if [ $status = 1 ]; then # <---- If gpio reads 1 = relay on then echo on
    echo "on"
    exit
    fi # <---- If gpio reads 0 = relay off then echo off
    echo "off"
    exit

Can anybody see, whats wrong, or has anybody ever made a switch/sensor/shellexe combi WORK ???

I allways, reboot my PI with the controller, when i make changes (Read this somewhere else)Thanks.

Rgds; Jesper.

Posted by jesperlykke at Mar 25, 2015 08:24

Yes, you must to install WEBIOPI in the RPI, after checking the installation according to the installation instructions in this LINK you can porceder to perform the configuration on the OpenRemote designer. ( Look at the Troubleshooting in the LINK I send you above )

After the completion of the configuration you must reboot the system (controller / RaspberryPi) as indicated by Michal.

Posted by edgi at Mar 25, 2015 08:32

Cool

So i will try to install it later.

I allready got openremote controller installed on the PI, but does not look to be a problem, having more services running according to CPU-load.

Rgds; Jesper.

Posted by jesperlykke at Mar 25, 2015 08:37

Can anybody see, whats wrong, or has anybody ever made a switch/sensor/shellexe combi WORK ???

I've made lot of them, even implementing whole new protocols through shellexe. Now, look at the output of log file logs/shellexe.log, maybe you will find some clues there. At least you should see your script being executed and returning some value.

Posted by aktur at Mar 25, 2015 08:51

Okay...

Will report back later!

Thanks

Rgds; Jesper.

Posted by jesperlykke at Mar 25, 2015 09:20

Hi again here

So i have been studying my shell log, and pasted some of the outputs here.

But i can't see why, it says "regex evaluation did not find a match" ??

Rgds; Jesper.

#!/bin/sh
/usr/local/bin/gpio write 20 1
exit

#!/bin/sh
/usr/local/bin/gpio write 20 0
exit

#!/bin/sh
status=$(/usr/local/bin/gpio read 20)
if [ $status = 1 ]; then
echo "1"
exit
fi
echo "0"
exit

– SNIP –
DEBUG 2015-03-25 16:03:59,715 (Shell): Will start shell command: /home/pi/scripts/switch/sensor.sh and use params: null
DEBUG 2015-03-25 16:03:59,746 (Shell): Shell command: /home/pi/scripts/switch/sensor.sh returned: 0
INFO 2015-03-25 16:03:59,747 (Shell): regex evaluation did not find a match
DEBUG 2015-03-25 16:04:00,067 (Shell): Building ShellExe command
DEBUG 2015-03-25 16:04:00,068 (Shell): ShellExe Command: commandPath= /home/pi/scripts/power-20-on.sh
DEBUG 2015-03-25 16:04:00,069 (Shell): ShellExe Command created successfully
DEBUG 2015-03-25 16:04:00,105 (Shell): Will start shell command: /home/pi/scripts/power-20-on.sh and use params: null
DEBUG 2015-03-25 16:04:00,131 (Shell): Shell command: /home/pi/scripts/power-20-on.sh returned:
DEBUG 2015-03-25 16:04:01,686 (Shell): Will start shell command: /home/pi/scripts/switch/sensor.sh and use params: null
DEBUG 2015-03-25 16:04:01,712 (Shell): Shell command: /home/pi/scripts/switch/sensor.sh returned: 1
INFO 2015-03-25 16:04:01,713 (Shell): regex evaluation did not find a match
– SNIP –

Cannot resolve external resource into attachment.

Cannot resolve external resource into attachment.

Posted by jesperlykke at Mar 25, 2015 16:47

But i can't see why, it says "regex evaluation did not find a match" ??

If I understand correctly, the values that the scripts return to your status sensor are either "1" or "0". Yet in your sensor you apply RegEx on|off. That does not make sense to me. Have you tried leaving RegEx empty?

Posted by pz1 at Mar 25, 2015 20:16

PZ1, Thanks that did it.

Removing the on|off in regex did the trick.

I am currious now, how this works. - So will test when i am back home from work today

I created both a custom, and a switch sensor. The shell return 1 / 0 OR the on / off, works flawlessly now.

Maybe i have to give echo "Sensorname on" for regex to work ?

Rgds; Jesper

Posted by jesperlykke at Mar 26, 2015 10:38

Hi Jesper,

Thanks for this post and to keep posting until resolution. I very new at this and i have a similar setup that i can get to make it work. Since you already make your works, maybe you or someone else can shed some light on whats wrong.

Currently i only have one simple LED connected to the GPIO22 of my Raspberry Pi that i want to turn on and off. For testing learning purposes i want to start with something really basic and then move on.

Ok, so this are the scripts i have, similiar as yours.

poweron.sh
#!/bin/sh
/usr/local/bin/gpio -g mode 22 out
/usr/local/bin/gpio -g write 22 0
exit

poweroff.sh
#!/bin/sh
/usr/local/bin/gpio -g mode 22 out
/usr/local/bin/gpio -g write 22 1
exit

powerstatus.sh
#!/bin/sh
status=$(/usr/local/bin/gpio -g read 22)
if [ $status = 1 ]; then
echo "1"
exit
fi
echo "0"
exit

This are the screenshots of the configuration of each of the items i have

On the panel view i just have a single switch

When get on my phone to the controller and press the button (which is labeled by "off") the led turns on and thats it. it will stay like that no matter how many times i press the button.

Anyone has any advise?

Posted by jsanjur at Apr 15, 2015 02:34

EDIT: I think the problem was the interval polling time i had on the status command.

Will confirm later

Confirmed. Added the polling interval as 3s on the status and its working now.

Posted by jsanjur at Apr 15, 2015 02:59
Document generated by Confluence on Jun 05, 2016 09:32