Arduino + ST to control multiple Relays

Sreekumar,

Just about anything is possible. All of the code you would need to modify is in the Arduino sketch (.ino) file. Read through it carefully and you will see all of the logic regarding the pushbuttons inputs.

Hi All,
New to home automation but I have experience with Arduino. I am trying to use this code to trigger a relay and open the garage door. I have an Arduino Uno and thing shield that I have successfully uploaded the modified code to only using 2 push buttons. When uploading the device handler to the cloud I use the following code.
I can get the switches to turn off but not back on (Arduino is not hooked up to anything yet, just testing code). Please tell me what I am doing wrong. Thanks in advance!

/**

  • ST_Anything_Relays - ST_Anything_Relays.device.groovy
  • Copyright 2015 Daniel Ogorchock
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
  • Change History:
  • Date Who What

  • 2015-03-27 Dan Ogorchock Original Creation

*/

metadata {
definition (name: “ST_Anything_Relays”, namespace: “ogiewon”, author: “Daniel Ogorchock”) {
capability "Actuator"
capability “Switch”

	attribute "switch1", "string"
	attribute "switch2", "string"
    
	command "switch1on"
	command "switch1off"
	command "switch2on"
	command "switch2off"

}

simulator {
}


// tile definitions
tiles {

    standardTile("switch1", "device.switch1", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch1on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch1off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}

    standardTile("switch2", "device.switch2", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch2on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch2off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}

    main (["switch1"])
    details (["switch1","switch2"])
}

}

//Map parse(String description) {
def parse(String description) {
def msg = zigbee.parse(description)?.text
log.debug “Parse got ‘${msg}’”

def parts = msg.split(" ")
def name  = parts.length>0?parts[0].trim():null
def value = parts.length>1?parts[1].trim():null

name = value != "ping" ? name : null

def result = createEvent(name: name, value: value, isStateChange: true)

log.debug result

return result

}

def switch1on() {
log.debug "Executing ‘switch1on’ = ‘switch1 on’"
zigbee.smartShield(text: “switch1 on”).format()
}

def switch1off() {
log.debug "Executing ‘switch1off’ = ‘switch1 off’"
zigbee.smartShield(text: “switch1 off”).format()
}

def switch2on() {
log.debug "Executing ‘switch2on’ = ‘switch2 on’"
zigbee.smartShield(text: “switch2 on”).format()
}

def switch2off() {
log.debug "Executing ‘switch2off’ = ‘switch2 off’"
zigbee.smartShield(text: “switch2 off”).format()
}

If your goal is garage door automation, please just use my ST_Anything_Doors example code from my GitHub repository. It already implements full garage door logic, including automagically firing the relay to either open or close the garage door for 1 second.

Here some more information on it

Very nice! Did not even notice this code. :slight_smile: I tried to use the “configure” tile and nothing happens, am I doing something wrong?
Also, I have a smartthings door sensor that is attached to the garage door, can I use this to give status on the garage door? If so how do I implement this?

Take a look at the Device Handler code to see exactly how the configure tile works. It is used to transfer configuration data from the ST Cloud to the Arduino. The data, in this case, is the polling interval for the temp/humidity sensor, IIRC. It basically allows you to override the hard-coded poling interval in the Arduino temporarily. To set the interval, hit the configure gear icon in the phone app when you have the Arduino Device selected.

As for using the ST Door Sensor, you’re somewhat on your own. My garage door control solution does expect you to use a standard magnetic contact sensor to sense the door position.

You could just use my TimedRelay example code, if all you want is something to simulate a momentary button press.

Dan

Thanks for the reply. I got that to work :slight_smile: I am now working on integrating the smartsense sensor so that it will only trigger if the garage door is down. Thanks again!

1 Like