[NEEDS UPDATING] Raspberry Pi Relay Controller (WebIOPi)

Hi guys
I’ve just give a try all this with my SmartThings and RaspPi
It worked for me at the begining but something is wrong in the updateVirtualRelay method (I’m not an expert with SmartThings platform and I can’t say exactly where the problem is)
After update any WebOIPiManager option and pressing [Done], things started to fail.
I changed update() method to start working again without problems in this way:

def updated() {
    log.debug "Updated with settings: ${settings}"
    unsubscribe()
    def delete = getChildDevices()
    delete.each {
        unsubscribe(it)
        log.trace "about to delete device"
        deleteChildDevice(it.deviceNetworkId)
    }       
    initialize() 
}

Hi again
I also made a modification to allow WebIOPi user//password

Into the preferences declaration

section("Raspberry Pi Setup"){
    input "piIP", "text", "title": "Raspberry Pi IP", multiple: false, required: true
    input "piPort", "text", "title": "Raspberry Pi Port", multiple: false, required: true
    input "theHub", "hub", title: "On which hub?", multiple: false, required: true
    input "piUser","text", "title": "User", multiple: false, required: false
    input "piPsswd","text", "title": "Password", multiple: false, required: false
}

And into de executeRequest method

def executeRequest(Path, method, setGPIODirection, gpioPin) {
       
    log.debug "The " + method + " path is: " + Path;
    
    def headers = [:] 
    headers.put("HOST", "$settings.piIP:$settings.piPort")
    def decoded="$settings.piUser:$settings.piPsswd"
    def encoded = "Basic "+decoded.bytes.encodeBase64()  
    headers.put("Authorization",encoded)

    try {    
    ....

I’ve been able to set this up on the raspberry pi B+. I have the Pi hooked up to a relay. I am able to control the relay via the web gui. When I attempt to control via smartthings, I am able to switch the relay in one direction, but not the other. i.e. I can turn the item on, but not off. How can I begin to troubleshoot this problem?

It works for me switching on and off with both the original version and the one I modified (the original just start to fail after reconfiguring the App)
I have a 2~3 seconds delay with SmartThings when I change the switch state.
Did you take a look into the “Live Logging” tab inside the SmartThings Web IDE?. You could place log.debug calls everywhere to trace what’s happening.

There is a bug in the original code. This has an impact depending on whether you create the GPIOs for the first time or edit them. Take a look at the posts starting a number 48. Tom was going to take a look at this, but it seems had not gotten around to it.

Hello everyone!
Thanks for this iBeech!
I’m very new to the whole smartthings scene, but I’ve had a raspberry pi remotely controlling my garage door for quite a while now. How would I modify the code to make a momentary contact for a relay? I’ve compared the code to the code I use on my webgui, but I just don’t understand what I’m looking at. Any help would be greatly appreciated!

I’m in the same boat. Completely new to Smartthings. I have had my pi connected to a relay to the garage door for years now. I was struggling with getting this working at all until I saw the post about adding a password to the code and had an ah-ha moment. I forgot that I password protected it.

Now I can get it working, but if I use the web interface to the pi, the smartthings device switches to ON, and doesnt switch back off. I was thinking that a momentary button tile would fix this but don’t have a clue where to begin with it.

I also have wired magnetic switch sensors to detect if it the door is open or closed. It would be great if it could read those as well.

Hi there! I want to take this webIOPi project and use it to be able to remotely run a python script on the pi. The python script outputs a signal through an rf shield I have to control some energenie remote control sockets. Is there a template or device type I can use to do this?

Hello guys
Many thanks eBeech. The info shared here is great.

I’ve been looking for alternatives to make something like Scott_Barnard5d1 and rledonne said.
I found BerryIO and gave it a try (no luck for me). Anyway it’s an interesting code and I prefer the way it’s made: https://github.com/nicholaswilde/SmartThingsPublic/blob/master/devicetypes/nicholaswilde/raspberry-pi.src/raspberry-pi.groovy
To use WebIOPi to make a “pulse” to open a garage door, I think the better option is to make the release operation inside a python webiopi macro (inside your Raspberry Pi). This way you will guarantee the relay release operation after push the button (no internet, no SmartTings, no SmartPhone in the middle).
The second problem is to inform SmartThings App that the output is off again. This thread (OpenWRT as a presence control) has a bash script that ilustrate how you could inform SmartThings that something changed Presence Detection using DD-WRT Router Script

As I said before, I’m working on my own solution to all this. I will share my code if I finally get something usefull.

So, to force output OFF after some seconds, save this into a .py file in your RaspberryPi and set into the [SCRIPTS] section in the WebIOPi config file (/etc/webiopi/config)

[SCRIPTS]
dingdong = /yourpathhere/dingdong.py

And the python code for the dingdong.py file:

import webiopi
import datetime

GPIO = webiopi.GPIO

DINGDONG = 18 # GPIO pin using BCM numbering
WAITING_OFF = 3 # Turn output OFF after WAITING_OFF seconds

# setup function is automatically called at WebIOPi startup
def setup():
# set the GPIO used by the DINGDONG to output
GPIO.setFunction(DINGDONG, GPIO.OUT)

# loop function is repeatedly called by WebIOPi
def loop():
    # check if the DINGDONG output is HIGH
    if (GPIO.digitalRead(DINGDONG) == GPIO.HIGH):
        webiopi.sleep(WAITING_OFF)
        # toggle DINGDONG OFF
        GPIO.digitalWrite(DINGDONG, GPIO.LOW)
    # gives CPU some time before looping again
    webiopi.sleep(1)

# destroy function is called at WebIOPi shutdown
def destroy():
    GPIO.digitalWrite(DINGDONG, GPIO.LOW)

For more info abount WebIOPi and python: http://webiopi.trouch.com/Tutorial_Basis.html

1 Like

I’m installing to a RPi3 with 20161125-raspbian-jessie. Install instructions worked until “sudo /etc/init.d/webiopi start” which failed due to a “file not found” error. I rebooted and retried the start, this time with success.

I’m now stuck at the GPIO List step. The WebIOPi menu is there, GPIO List page loads but all items are gray.

Only error I see in the install was this message:

Now launching the Weaved connectd daemon installer…
.
_Sorry, you are running this installer on an unsupported platform. But if you go to _
http://forum.weaved.com we’ll be happy to help you get your platform up and running.

I am able to control the GPIO pin via command line.

Hi

I see you fire two events when the switch is toggled, I’m assuming this is to counter that the switch tile every other time will turn back immediately after you turned it off?

Any solutions to this? :slight_smile:

Regards
Simon

Hey, Tom!
First off thank you very much for this.

I was having an issue with getting relays to turn on with the RPi3. For some reason in lines 331-316 of the WebOIPiManager I’m getting the GPIO two times in the "Parts"array.

Meaning that at line 316 where the code tries to store the “state” from the 7th element of the array it was actually saving the double of the GPIO and storing the state to the 8th element.

Example for GPIO 17:
[piRelay, 192, 168, 0, 102, 17, 17, on]

So changing line 316 to : def state = parts[7] fixed it. Not sure if this is happening to anyone else but I thought I’d post it here just in case.

Thanks, again!

This is the issue I mention earlier in the thread. Changing the element is a sort of fix. However, I noticed that there is a difference between when you freshly create the GPIO and a modified one. It seems to change the makeup of the string.

Got it! Sorry I should have read the whole thread.:disappointed:

Hi!! I’m just getting into home automation and am very new to all of this. It’s been a frustrating past few days but, this is exactly what I’ve been looking for. Opens so many possibilities. I just wanted to say thank you to everyone that posted in this thread.

is it possible to hook up wired sensors to this raspberry PI and have it report to smartthings as individual devices. Example- I have many wired contacts throughout my house and would like it to report open and close for them to smartthings. Is this possible? thanks

there was a write up going around with this same question i have (see below link), but with the discontinuation of Things Shield, I need to look for another way.

http://www.kendrickcoleman.com/index.php/Tech-Blog/total-noob-guide-to-move-your-old-wired-security-system-to-smartthings.html

I’m looking for exactly the same thing, Raymond.

Hi all.
May be the most direct way to send messages back to SmartThings is to use it’s own API. Take a look here https://community.smartthings.com/t/presence-detection-using-dd-wrt-router-script. You will need to deal with the SmartThings API authentication system.
Also, you should take a look to IFTTT. I was checking it some days ago and it’s very easy to undestand how it works. Give it a try with any social network you use and then, you will be able to start using it with SmartThings also (it has a special SmartThings Service to configure).
My own choice was to move the RaspPi software from WebIOPi to NodeRed. It’s really great. It comes pre-installed into Raspbian but I it’s an old version and I installed by myself the curent nodejs and node-red versions . It’s not easy as some nodejs package breaks the standard install system. NodeRed has “nodes” to interact with MQTT (I installed mosquitto), Twitter, Telegram, http (https - to conect IFTT using “Maker”), and many others.
I’m planning to use SmarthThigs to deal with ZWave, Zigbee and also to be my mobile home control device (Android App). I leave for later the NodeRed<=>SmarThings interaction.
If some one is interested on how to install newer NodeRed/Nodejs versions into the RaspPI (and the official install is still not fixed), feel free to ask me again and I will share the procedure here.

Please share. I’m currently using your WebIOPi interface now on my aquarium and it works great.