[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Yes, you are correct. My assumption is that for a momentary button activated device, knowing the state in ST is not that important (depending on the use case.). But, being able to say “Alexa, turn on …” and “Alexa, turn off …” is very convenient. That’s all I am suggesting.

No changes on the Arduino code side at all.

The changes are on the ST IDE side.

Ah, I see what you mean. But in this case, would that work? Since the device is already “off” to ST, I don’t think it would trigger any action to take place. You turn the device on, which triggers the esp to turn on the relay, then the esp hits the timer and turns the relay off. This is then reported to ST which turns the device off in ST. When you then tell ST to turn the device off, it is already off to ST so it would no trigger ST to change the status of the device. Correct?

@jpoppinmoneyunit @Ryan780

Ryan,

ST does not typically check the state of a switch before issuing a command. Issuing an off() command runs that code regardless of the state of a switch.

Jake,

Here is a custom DTH you can add to your ST IDE. Make sure to SAVE and PUBLISH it. Then, go into your list of Devices in the ST IDE, and edit the existing ST_Anything Child Device, and then change its “Type” to this newly created version. Afterwards, calling the on() or off() function will do the exact same thing. From the Arduino’s perspective, it will get an ‘on’ command and run through the TimedRelay sequence.

/**
 *  Child Relay Switch Custom
 *
 *  Copyright 2017 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
 *    ----        ---            ----
 *    2017-04-16  Dan Ogorchock  Original Creation
 *    2017-08-23  Allan (vseven) Added a generateEvent routine that gets info from the parent device.  This routine runs each time the value is updated which can lead to other modifications of the device.
 *    2018-03-10  Dan Ogorchock  Modified to have 'off' command to behave the same as the 'on' command.
 *
 * 
 */
metadata {
	definition (name: "Child Relay Switch Custom", namespace: "ogiewon", author: "Dan Ogorchock") {
		capability "Switch"
		capability "Relay Switch"
		capability "Actuator"
		capability "Sensor"

		attribute "lastUpdated", "String"

		command "generateEvent", ["string", "string"]
	}

	simulator {

	}

	tiles(scale: 2) {
		multiAttributeTile(name:"relaySwitch", type: "lighting", width: 3, height: 4, canChangeIcon: true){
			tileAttribute ("device.relaySwitch", key: "PRIMARY_CONTROL") {
				attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"turningOn"
				attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00A0DC", nextState:"turningOff"
				attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#00A0DC", nextState:"turningOff"
				attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
			}
 			tileAttribute("device.lastUpdated", key: "SECONDARY_CONTROL") {
    				attributeState("default", label:'    Last updated ${currentValue}',icon: "st.Health & Wellness.health9")
            }
		}
	}
}

def on() {
	parent.childRelayOn(device.deviceNetworkId)
}

def off() {
	//parent.childRelayOff(device.deviceNetworkId)
	parent.childRelayOn(device.deviceNetworkId)  //issue 'on' command to cause the ST_Anything Timed Relay to fire when the 'off' command is called
}

def generateEvent(String name, String value) {
	//log.debug("Passed values to routine generateEvent in device named $device: Name - $name  -  Value - $value")
	// Update device
	sendEvent(name: name, value: value)
    sendEvent(name: "switch", value: value)
   	// Update lastUpdated date and time
    def nowDay = new Date().format("MMM dd", location.timeZone)
    def nowTime = new Date().format("h:mm a", location.timeZone)
    sendEvent(name: "lastUpdated", value: nowDay + " at " + nowTime, displayed: false)
}

def installed() {
}
1 Like

OH!!! Okay, that makes sense then. Thanks Dan!.

Maybe if we ask @ogiewon really, REALLY nicely. :stuck_out_tongue: Just teasin. :angel:
I am half way to being able to figuring it out…just don’t know enough of the Arduino IDE to get the rest of the way there.

Got it working, incredible! Thank You!

Wish I would have wrote on here weeks ago…

For future projects, is there a way to have ST sense something like maybe the garage door example perhaps? Or is it that there are two child devices, one being a contact sensor and the other the control of the door?

The only way to improve the espresso machine now is to have a voltage reading on the power led to tell if it’s on from afar.

Thanks again

Jake

I took a look at your example servo motor sketch that you posted earlier. It appears to use the standard Arduino servo library. I believe that library may use HW interrupts to take care of executing the motion. If so, that would imply that these are non-blocking calls which would be excellent.

ST_Anything utilizes a C++ Object Oriented Design. Each of the Arduino Sensors and Executors is an independent C++ class. In order for you to add servo motor control, you’ll want to create a new C++ class altogether. I would recommend you base this new class on the EX_Switch_Dim class. This class already knows how to receive an on/off command as well as a dim level. You can use this data from ST to issue corresponding servo motor commands.

Get this working first, with NO changes to the SmartThings Groovy code side. Just be sure to use the name “dimmerSwitch1” in sketch when you declare the object. This will make sure that the “Child Dimmer Switch” DTH is created for this device. This will allow you to control the servo by changing the dimmer level, and turn it “on” and “off”. Later, you can create something more specific to your use-case. Perhaps you’ll want to implement the SmartThings “Window Shade” Capability?

The Garage Door control in ST_Anything is a fairly complex device as it combines a contact sensor and timedRelay device into one device.

What you are suggesting is possible. With a little ingenuity and creativity (and some code) you could combine multiple devices into one virtual device.

Haha ok, thanks. Thought I’d ask.

I’ll stick to the simple stuff for now until I get a handle on things.

I’m less worried about that at the moment than trying to get the code for the servo into the Arduino IDE. I’m sure what you said would make sense to some people but unfortunately I’m completely lost. Think I’m just going to stick with the setup I have working now as I can see myself getting EXTREMELY frustrated when all that takes me 20 hours of work to figure out that I’ve done it completely wrong. Thanks for the info though…at least now I know it’s beyond my capabilities. If I want a sensor on the window with the blinds, I’ll just spend the $20 and buy one.

I plan to use ST_Anything on a D1 Mini Wemos to connect a momentary push button and a electric door strike. I want to assign rules so the momentary push button only powers the relay (connected to the electric door strike) in certain SmartThing’s mode (i.e home mode).

However, if my internet is down or SmartThing’s cloud is down. Can I have the D1 Mini Wemos automatically activate the relay when a push button is pushed?

So somehow program the D1 Mini Wemos to work in a offline state if it is unable to communicate with SmartThings cloud??

I am sure you could, but not without inventing some sort of heartbeat from ST to ST_Anything. If ST_Anything doesn’t get a heartbeat within a certain amount of time, then allow pure local control…

1 Like

How about build something that checks the outage page?

With anything like a door lock you want to make sure your are set even if 100% of functionality is lost. Personally, my requirements are:

  1. Door remain secure, even if 100% power is lost.
  2. Retain access with a backup method, even if 100% of power is lost.

That said, my method would be to use a fail secure door catch, like this one.


Notice how this one says “Fail Secure”

Along with a regular door knob with a keyed lock. Mine is for a garage door, so I don’t have a deadbolt…but electric strike panels don’t work well with deadbolts anyway since they have such a deep throw.

1 Like

You can use a deadbolt with a electric door strike? I thought you couldn’t use any door lock mechanism…and had to be a regular door handle to open/close the door?

But when you use a deadbolt…would it have to remain locked for it to work with the strike?

Do you have any electric door strike recommendations for a deadbolt? I see some on Amazon for $24-$350…have no idea which one to get for my gate:

From what I have read you cannot use an electronic door strike with a deadbolt. The throw is too far (distance bolt travels into the frame). Reread my post.

I’ve actually responded to several of the many posts you’ve created about your gate. I think the connected deadbolt is your best option.

1 Like

I think carrying a key is the best option! :wink:

1 Like

I read the don’t as do…haha

Sorry for some of these repetitive questions…I just have a lot of time to research various products (as I am waiting for the D1 Mini to arrive from China).

So just to confirm…a key locked (like this) can be used with an electric door strike? So when the door lock is locked I can unlock it with the electric deadbolt & with the key? I would assume the electric strike you linked should work with the lockset I linked?

I would love to use a connected Z-Wave/ZigBee lock. But the interior portion of the lock isn’t weatherproof and someone can simply put their hands through the gates to unlock it…I haven’t seen a Z-Wave/ZigBee enabled double-cylinder deadbolt.

Just curious…What is the Gate protecting that the House Door Lock isn’t? Is this an ‘Outside Room’ with furniture, grill, TV, etc…? I really am just curious why the need for double security?

Locks are really only a deterrent for mostly-honest people (e.g teenagers looking to take a dip in your pool, or drink some cool beverages from the outdoor fridge.) A true thief will easily break into your house, bypassing the locks. Unless you have steel bars on every window, a real thief will have no trouble getting in and out of a house before anyone can show up to stop them.

2 Likes