[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

OK, if you want to have the ESP8266 perform the 1 second timing, use my relaySwitch device in the sketch. All you have to do is send it an “on” command and it will turn off automagically after a user defined amount of time. This prevents the risk of the ST cloud failing to turn off the relays after a certain amount of time. ST isn’t 100% reliable regarding timing events like this. Letting the ESP8266 do the work is much safer and more reliable.

Here is an example of 2 of them from my Arduino/W5100 example sketch. Read the comment section of the S_TimedRelay.h or .cpp file for details on all of the arguments.

  //Special sensors/executors (uses portions of both polling and executor classes)
  static st::S_TimedRelay           sensor21(F("relaySwitch1"), PIN_TIMEDRELAY_1, LOW, true, 1000, 0, 1);
  static st::S_TimedRelay           sensor22(F("relaySwitch2"), PIN_TIMEDRELAY_2, LOW, true, 1000, 0, 1);

The relaySwitch device does support both “on” and “off” commands. Say you define the timer to be 10 seconds. Once you send an “on” command, the sketch will turn the output on and start a 10 second countdown. If you send it an “off” during the countdown, it will turn the relay off immediately and cancel the countdown timer.

This device can also be used to cycle a timing sequence a discrete number of times. For example, you could flash an LED 10 times (2 sec ON, 1 sec OFF) with the following configuration:

  static st::S_TimedRelay           sensor21(F("relaySwitch1"), PIN_TIMEDRELAY_1, LOW, true, 2000, 1000, 10);

Will do. Just need a USB extension cable now to reprogram the board so I don’t have to undo all of my work tying in all the sensors to the Arduino board
One more dumb question…
After uploading new ino to arduino…should I delete all the device handlers and devices from SmartThings API first before uploading parent and child groovy’s / integrating with git hub ide…simply to start cleanly?

That’s a good question. Probably not a bad idea to delete the DHs that you manually added before re-adding them via Github integration.

Jeff,

I just completed adding the optional Strobe light capability to my EX_Alarm class in ST_Anything. I have also updated my Parent DH and Child Alarm DH to support this feature. Finally I also modified my ST_Anything_Multiples_EthernetW5100.ino example sketch to demonstrate two EX_Alarm devices, one with strobe and one without. You simply need to supply the extra optional strobe pin to enable the strobe feature.

Hope this helps you with your project!

1 Like

Cool. Thanks Dan. This is my siren (alarm) wires… one pair hooked up to panel (getting power from old alarm panel i’m guessing?) Typically, is this the same setup for alarm wiring on arduino board as reed sensors? i.e. ground one wire and the other plug into mapped pin on board? will arduino board provide low voltage power for the siren? Thanks man.

Usually the sirens are powered by the Alarm Panel, probably at 12Volts. The Arduino cannot supply either the voltage or current required to run a siren. Therefore, what is normally done is to connect a relay to the output of the Arduino. The Arduino can turn a small 5V relay on and off. The contacts of the relay then act as a switch to supply the 12V and high current required for the siren.

OK, I can see how I can make this “work” with several options, but I really like the doorControl device. My only problem is that I don’t have wired garage door contacts to go along with it. I’ll probably just order some and do it right. But that also means that I need to get a new ESP2866 and 4x relay, as the one I have now is only setup for relays, as far as I can tell.

Here is the one I have currently, probably better designed for a sprinkler system or something. http://linksprite.com/wiki/index.php5?title=LinkNode_R8:_Arduino-compatible_WiFi_relay_controller

Unless there was a way for PIN_DOORCONTROL_CONTACT_1 in the doorControl to be a virtual contact sensor that I was able to have mimic the open/close status of the iris sensors I currently have on my garage doors. I certainly don’t know if/how that would be possible. Especially with my limited skill set at all of this.

Dan,

What is the best way to perform the following? I’m using Arduino to ST via Ethernet. I have few RF switches which required the following commands to operate. It doesn’t work with the RCSwitch library. It has it’s own library.

examples:

#include “livolo.h”
//Switch 1
livolo.sendButton(18, 3) // This command will turn on the switch 1
livolo.sendButton(18, 4) // This command will turn off the switch 1

//Switch 2
livolo.sendButton(18, 5) // This command will turn on the switch 2
livolo.sendButton(18, 6) // This command will turn off the switch 2

Thanks,
Jess

Jess,

The easiest way to do that is to simply create a new ST_Anything device class. Use the EX_RCSwitch.h and EX_RCSwitch.cpp as starting point. You could call them EX_LIVOLOSwitch.h and LIVOLOSwitch.cpp.

Remove the RCSwitch include file, and your livolo.h file, rename everything from RCSwitch to LIVOLOSwitch in both files. From there, you simply need to figure out what arguments to pass into the constructor, what private variables you need to store things, and how to call the LIVOLO library from the .cpp file when it receives an “On” or “Off” command.

It may sounds challenging, but if you’ve written any Arduino code before, it really isn’t too difficult.

You could make a custom version of the “Child Door Control” device handler and add to custom commands called “open()” and “close()”. These could then be called from a SmartApp (or maybe even CoRE) to reflect the state of the Iris sensor. Take a look at my old “Virtual Door Control” device handler buried in the ST_Anything github as an example. It should have “open()” and “close()” functions which then update the local tiles.

1 Like

Dan, Thanks for adding the strobe capability to alarm. It works fantastic on the bench. It makes for some interesting logic states on the alarm1 example that does not have a strobe pin defined. Looks like you chose to have a request for strobe1 default to siren1, and stobe1 off then also turns off siren1. Seems like a good way to do it.

1 Like

I tried to do this, I created a Child Virtual Door Control device handler, used the normal one, and changed the open() and close() to that of your virtual example. I then changed the doorcontrol in the IDE to the virtual handler. With CoRE, I can see the doorControl device, but my only options are open and close. So if I setup a piston, if iris is open, then using doorcontrol open, or if iris is closed, using doorcontrol close, it will just keep opening and closing my garage in a loop. I cant figure out how to update just the contact sensor, at least with CoRE. Since in the doorcontrol device, the contact sensor is not exposed as a separate device.

If I don’t have the door hooked up to the relay, the above example absolutely works, and the door icon updates correctly, since there is no door opening/closing when the open/close command is sent.

I’m sure that it is absolutely possible to accomplish, but it is probably beyond my ability/skill level at this point.

I’ll take a look a little later when I have some free time.

Dan, I’ve continuing to test with a sketch that is customized to my application. Everything works great in terms of the Arduino communicating with the device handlers. I am especially impressed with how the parent DH automatically picks up additional channels that are added to the sketch without having to remove and reinstall the parent DH, which would destroy links to smart apps. Even removing channels is seamless with only needing to delete the child DH after editing the sketch. This might be worth including in the documentation to avoid having users remove and reinstall the parent DH as they make changes. This is really awesome!

My current project includes 1 Smoke detector and 1 CO detector. The CO detector does not show up in either my Smart Alarm App or Smart Home Monitor when trying to add it under smoke and CO sensors. The smoke detector does show up. I noticed that the ST capability documentation for smoke detector shows optional CO attributes, so I wonder if the Smart Alarm App and Smart Home Monitor are looking for a combo Smoke and C/O device. I will start looking through the Smart Alarm App to see if I can figure this out.

Jeff,

Thanks for the feedback. Glad to hear it is working well for you. I was really proud of the fact that adding extra devices to the Arduino automagically created the child devices in ST. I am hoping most users will not need to edit the ST Device Handler code at all, which should make it much simpler for people to use the Arduino / ESP8266 boards. Being able to name the child devices and delete them if desired was another accomplishment I am very happy worked out as well as it does.

I have added the “Smoke Detector” capability to the “Child Carbon Monoxide Detector” DH so it will then show up in other apps. Strange that they have a capability for “Carbon Monoxide Detector” but don’t bother to allow you select it in the SHM app. I tested it successfully in SHM. It properly reported “Carbon Monoxide Detected!”

Just update your copy of the “Child Carbon Monoxide Detector” and you should be all set. Remember to Publish->For Self.

1 Like

Ok, so I am making a little progress. I added command “openme” and command “closeme” to the doorControl library, and I am able to control the status of the contact sensor contained within. The problem I am having now, is that since it is not an actual contact sensor, every 5 minutes or so, when the ESP runs its checks, it thinks its open because the actual status within the ESP never did change, so it still reads PIN_DOORCONTROL_CONTACT_1, LOW, true,. And that true resets it to open even if the door is closed.

So I can change that to false, but then the same thing will happen when I leave the door open, it will think it is closed. So I guess now I will need to try to create a Virtual Contact Sensor from your examples, and make that into a Child device to link to my doorControl.

1 Like

@TexAMR,

I have figured out where I lead you astray… Since the Child Door Control DH already has open() and close() functions, which are needed to trigger the garage door relay, you cannot use them from another another SmartApp (like CoRE) to only trigger the update of the doorControl and contact tiles.

So, I added two custom commands, called virtualopen() and virtualclose(), which I then use to update just the values of both tiles in the device handler, without sending any commands to the Arduino/ESP8266 board. I was then able to use CoRE to create two pistons, one for open and another for close. These pistons monitor a another “Contact Sensor” device (like your Iris devices) and then call the custom commands for virtualopen() and virtualclose() respectively.

At this point, I was feeling pretty proud of myself, until I remembered the fact ST_Anything, running on the Arduino / ESP8266 will refresh all of its data by sending an update to SmartThings every 5 minutes. Thus, the doorControl updates from this feature will overwrite the status provide to the Child Door Control DH from your Iris sensor.

So, if you really want to do this, you will need to trap any “doorControl” updates in the Parent DH to NOT call the childSendEvent function of the Child Door Control DH. Hope that makes sense! :wink:

Here is the modified Child Door Control DH if you want to give it a try.

Note to everyone else: Probably best to avoid this custom Child Door Control device handler unless you really know what you’re doing! I am not planning on releasing this version as the use case is pretty unique to @TexAMR.

/**
 *  Child DoorControl
 *
 *  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
 *    ----        ---            ----
 *    2015-04-14  Dan Ogorchock  Original Creation
 *
 *
 */
metadata {
	definition (name: "Child Door Control", namespace: "ogiewon", author: "Daniel Ogorchock") {
		capability "Door Control"
		capability "Garage Door Control"
		capability "Contact Sensor"
		capability "Actuator"
		capability "Sensor"
		capability "Momentary"
        
        command "virtualopen"
        command "virtualclose"
	}

	tiles(scale: 2) {
		multiAttributeTile(name:"doorControl", type: "generic"){
			tileAttribute ("device.doorControl", key: "PRIMARY_CONTROL") {
                attributeState "open", label: 'Open', action: "doorControl.close", icon: "st.doors.garage.garage-open", backgroundColor: "#e86d13", nextState: "open"
                attributeState "closed", label: 'Closed', action: "doorControl.open", icon: "st.doors.garage.garage-closed", backgroundColor: "#00a0dc", nextState: "closed"
                attributeState "opening", label: 'Opening', action: "doorControl.close", icon: "st.doors.garage.garage-opening", backgroundColor: "#e86d13", nextState: "closing"
                attributeState "closing", label: 'Closing', action: "doorControl.open", icon: "st.doors.garage.garage-closing", backgroundColor: "#00a0dc", nextState: "opening"
            }
        }		
		standardTile("contact", "device.contact", width: 2, height: 2) {
			state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#e86d13")
			state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#00a0dc")
		}
 	main (["doorControl", "contact"])
	details (["doorControl", "contact"])
    }
}

// handle commands
def open() {
	parent.childDoorOpen(device.deviceNetworkId)
}

def close() {
	parent.childDoorClose(device.deviceNetworkId)
}

def push() {
	open()
}

// handle commands
def virtualopen() {
    sendEvent(name: "contact", value: "open", isStateChange: true)
	sendEvent(name: "doorControl", value: "open", isStateChange: true)
}

def virtualclose() {
    sendEvent(name: "contact", value: "closed", isStateChange: true)
	sendEvent(name: "doorControl", value: "closed", isStateChange: true)
}
1 Like

@TexAMR

Here is the change I would try to prevent the 5 min periodic updates from changing your Child Door Control values. Note, I have not tested this yet.

In the Parent DH parse() routine, find this section of code and replace it with the version I have shown below:

    if (childDevice != null) {
        //log.debug "parse() found child device ${childDevice.deviceNetworkId}"
        if (namebase != "doorControl") { childDevice.sendEvent(name: namebase, value: value) }
        log.debug "${childDevice.deviceNetworkId} - name: ${namebase}, value: ${value}"
        //If event was dor a "Door Control" device, also update the child door control device's "Contact Sensor" to keep everything in synch
//                if (namebase == "doorControl") {
//               	  childDevice.sendEvent(name: "contact", value: value)
//                    log.debug "${childDevice.deviceNetworkId} - name: contact, value: ${value}"
//                }
        }
1 Like

Now that’s pretty funny! We both basically came up with the same solution, and at the same time.

Yes, I think I am following you on this.

And I see you just replied showing me exactly how to do it, thanks!

1 Like

Thanks for the direction. I’m trying to perform this and I have question on the ST_Anything_Multiples_EthernetW5100.ino file, the latest version. Since there is nothing related to the EX_RCSwitch as sample, I simple change the EX_Switch to EX_LIVOLOSwitch and using the same PIN for the switch, since I use the one PIN for the RF transmitter , like the sample below. Just wonder, if this is the right way. Also, wonder which DH should I use as reference point since you don’t seem to include the EX_RCSwitch in all your latest build anymore.

static st::EX_LIVOLOSwitch executor1(F(“switch1”), PIN_SWITCH, LOW, true);
static st::EX_LIVOLOSwitch executor2(F(“switch2”), PIN_SWITCH, LOW, true);