[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

@ogiewon, great work and thanks for your efforts here, fantastic.
I’ve been experimenting with the ESP8266 NODEMCU (great little device), I’m now controlling my TV trough ask alexa and the ESP (http://thingsthataresmart.wiki/index.php?title=How_to_Control_your_TV_through_Alexa_and_Smartthings if anyone is interested :slight_smile: ), and have just got your project up and running with a motion and illuminance sensor.
I really like the idea of having just the single parent device, and have updated the code so the child devices are not created as you have shown.
A question, is it possible to move the refresh buttons to the bottom of the list (think it is by adjusting the order in the code) and having one of the sensors (such as light level) as a full tile and the other shown below, much in the same way of a multi sensor, the Aeon Multisensor as an example below

Sure, you can most definitely create your own custom Device Handler and lay out everything exactly the way you want. As long as you have only one of each ST Capabiliy (i.e. one contact sensor, one temperature sensor, one motion sensor, etc…), you do NOT need to even create child devices. You can simply create all of the tiles you need in the Device Handler.

If you look through some of the deprecated device handlers from earlier ST_Anything releases, you will see examples of having all local tiles in one DH. Take a look at the following example… Just make sure the names of each tile matches exactly the names for each device in your sketch (case sensitive!)

Fantastic, thanks. Will have a look and see where I get!

1 Like

Where did you find information on creating the parent without children? My use case has just a single switch (executor) and I would like to have just a single line in my phone app. Right now the parent and child get a slot on the mobile UI.

I posted the information literally a few posts above this one… This was my old way of using a traditional device handler. You just need to remove any of the tiles that you do not want to use, and change the names of the ones you want to use to match the names assigned in your sketch’s setup() routine. Also, remove any of the “capabilities” aside from those you wish to keep.

You can also avoid having two devices show up by simply editing one line of the parent device handler:

On line 379 in the parent-st-anything-ethernet.groovy DH, change the isComponent from false to true. Afterwards, you need to save and publish it. Then remove the existing parent device and manually recreate again. This will result in a single device in the ST App’s “Things View” but there are still technically two devices (the parent and the child).

				addChildDevice(deviceHandlerName, "${device.deviceNetworkId}-${deviceName}${deviceNumber}", null,
		      		[completedSetup: true, label: "${device.displayName} (${deviceName}${deviceNumber})", 
                	isComponent: true, componentName: "${deviceName}${deviceNumber}", componentLabel: "${deviceName} ${deviceNumber}"])

So I tried the changing of line 379. It’s interesting that if I pick a name during device creation that I’d previously used, it gives me options for “replace” or “remove”. This was after I deleted the previous device in ST browser interface. If I hit replace, it spins and spins attempting the check the device’s health. Never came back so I aborted.

I created a new device with a different name and things worked normally. I see the parent in the phone’s UI and I have to select it in order to get to the screen with the child to turn on the switch. Is it possible to have the phone’s UI show only the child so that the switch may be activated from the top level device screen?

Yes, you should be able to do that simply by rearranging the tiles in the DH. I haven’t tried this though, so give it a try and let us know.

	tiles (scale: 2){
   		childDeviceTiles("all")

		standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "default", label:'Refresh', action: "refresh.refresh", icon: "st.secondary.refresh-icon"
		}
        
		standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "configure", label:'Configure', action:"configuration.configure", icon:"st.secondary.tools"
		}

        valueTile("numberOfButtons", "device.numberOfButtons", inactiveLabel: false, width: 2, height: 2) {
			state "numberOfButtons", label:'${currentValue} buttons', unit:""
		}
 

	}

Using the non-parent/child device handler above really is probably what you want to do. It’ll take a little more tweaking on your part, but you’ll get exactly what you want and will learn about customizing a Device Handler in the process. There is decent ST Documentation regarding writing device handlers which will probably help. Just remember to change the tile name from “switch” to “switch1” to match the strings being sent to and from the arduino.

Alright, I have removed and then added the device, but the hub still does not populate the child devices… I have also double checked the IP settings for conflicts, verified the SmartThings Hub IP and MAC address of ESP-01, and checked the WiFi settings. Also, under the serial monitor when setting up the device, it seems like the chip initializes correctly.

Can you please tell me if I’m doing this correctly :disappointed_relieved:? I have an ESP-01 with the corresponding Multiples sketch, with nothing attached to either GPIO pins.

https://importhack.files.wordpress.com/2014/11/esp8266-reflash-firmware.png

Like this, but without the TX and RX pins attached i.e. only power, ground and pull HIGH on CHPD

I have only changed the lines that you have typed, “You must edit this line!”. I have no other ESP8266 devices registered in the hub, just this one. Also, I am using an Android phone for the setup. Is this setup okay?

The SmartThings IDE displays these log events-

Oh, and the reason why there is a change in numberOfButtons is because the app didn’t allow me to save the device with 0 buttons, which is strange. I had to save saying it had 2 then re-save with 0. Excuse me for bothering you so much :sweat_smile:.

Thank you Dan,

My first couple of attempts have not been pretty but I’m going to keep working at it while reading the documentation. It seems to me that I still need the ST_Anything parent (networking, etc.) and substitute my switch device handler for the child switch handler in your code. I’m probably headed in the wrong direction because taking this approach still puts the parent at the top level of the UI.

@digadv

Here is a modified Device Handler that you should be able to use for a single “switch” device.

Please MODIFY YOUR SKETCH’s setup() routine to rename the EX_Switch device from “switch1” to “switch” so that it matches the tile name below in the Device Handler. These strings much match exactly, including case. Recompile and reload the Arduino/ESP8266.

Then, delete your current Parent device. You’ll need to copy and paste the following text into a new Device Handler (from code). Save it and publish it. Then manually create a new device using this device handler. Go into your phone’s ST App to configure this new device’s settings (Arduino IP Address, MAC Address, and Port) just like you’ve done previously.

This device handler does NOT use parent/child DH’s. It is a single device handler that knows already what Tiles are necessary to match your Arduino sketch’s configuration. This is much less plug and play and requires users to edit groovy code if they modify their sketch. Also, you can only have one “switch”, one “temperature”, one “contact”, etc… But it does remove the parent/child relationship and the extra baggage associated with it.

Hope this helps!

/**
 *  ST_Anything_Ethernet_Switch.device.groovy
 *
 *  Copyright 2017 Dan G 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-02-08  Dan Ogorchock  Original Creation
 *    2017-02-12  Dan Ogorchock  Modified to work with Ethernet based devices instead of ThingShield
 *    2017-07-18  Dan Ogorchock  Modified for a user who simply wants one switch device.
 *
 */
 
metadata {
	definition (name: "ST_Anything_Ethernet_Switch", namespace: "ogiewon", author: "Dan Ogorchock") {
		capability "Switch"
		capability "Sensor"
        capability "Actuator"
	}

    simulator {
 
    }

    // Preferences
	preferences {
		input "ip", "text", title: "Arduino IP Address", description: "ip", required: true, displayDuringSetup: true
		input "port", "text", title: "Arduino Port", description: "port", required: true, displayDuringSetup: true
		input "mac", "text", title: "Arduino MAC Addr", description: "mac", required: true, displayDuringSetup: true
}

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

        main(["switch"])
        details(["switch"])
	}
}

// parse events into attributes
def parse(String description) {
	//log.debug "Parsing '${description}'"
	def msg = parseLanMessage(description)
	def headerString = msg.header

	if (!headerString) {
		//log.debug "headerstring was null for some reason :("
    }

	def bodyString = msg.body

	if (bodyString) {
        log.debug "BodyString: $bodyString"
    	def parts = bodyString.split(" ")
    	def name  = parts.length>0?parts[0].trim():null
    	def value = parts.length>1?parts[1].trim():null
		def results = []
    	results = createEvent(name: name, value: value)

		log.debug results
        return results

	}
}

private getHostAddress() {
    def ip = settings.ip
    def port = settings.port

	log.debug "Using ip: ${ip} and port: ${port} for device: ${device.id}"
    return ip + ":" + port
}


def sendEthernet(message) {
	log.debug "Executing 'sendEthernet' ${message}"
	new physicalgraph.device.HubAction(
    	method: "POST",
    	path: "/${message}?",
    	headers: [ HOST: "${getHostAddress()}" ]
	)
}

// handle commands

def on() {
	log.debug "Executing 'switch on'"
	sendEthernet("switch on")
}

def off() {
	log.debug "Executing 'switch off'"
	sendEthernet("switch off")
}

def updateDeviceNetworkID() {
	log.debug "Executing 'updateDeviceNetworkID'"
    if(device.deviceNetworkId!=mac) {
    	log.debug "setting deviceNetworkID = ${mac}"
        device.setDeviceNetworkId("${mac}")
	}
}

def updated() {
	if (!state.updatedLastRanAt || now() >= state.updatedLastRanAt + 5000) {
		state.updatedLastRanAt = now()
		log.debug "Executing 'updated'"
    	runIn(3, updateDeviceNetworkID)
	}
	else {
		log.trace "updated(): Ran within last 5 seconds so aborting."
	}
}

Been having a play with the single device handler, and this is where i have got to.

Its not as straight forward as the parent child method, but this does give me what i’m looking for, so thanks Dan, fantastic effort here.
Its a shame its not possible (as far as I can determine) to have tiles defined in the parameters/settings so we could just specify the name of the tiles we want to show.

I also added in the ESP8266 sending the time to smartthings so that you can see when it was last updated.

1 Like

Looking good! Glad to see you’ve gotten the hang of it and now understand some of the pros and cons of using the Parent/Child (i.e. Composite) Device Handlers.

For most people, they use ST_Anything to add a bunch of sensors to SmartThings all from one board. A classic example of this is replacing an old alarm panel with an Arduino/ESP8266 board. In this case, they will have a bunch of contact sensors and thus the Parent/Child design is MUCH more user friendly than what we used to have to do!

Since you are seeing the events trying to create the child devices, I am wondering whether or not you actually added and published the child devices in your SmartThings IDE? The error message appears to be cut off.

Can you please provide a screen capture of your ST IDE Live Logging window just after you power on the ESP01 and it sends up its initial set up status updates? That will help determine what the real issue is.

Thanks for the quick reply Dan. I think I have published all of your child devices correctly-

The message that was cut off reads in full, “Child device creation failed. Please make sure that the ‘null’ is installed and published.” Again, I haven’t changed any of the names of the devices in the Multiples sketch…

The Live Logging page stays empty when I turn on the ESP-01, all it says is " Waiting on events…". Toggling a z-wave switch also doesn’t produce any logs.

Thanks in advance.

If live logging is completely empty for your account, something is wrong. Are you sure you are logged into the correct Shard for ST IDE?

So it turns out my browser was doing something funky, but I fixed it and I see the logs now. After I turn on the ESP-01, I see these logs-

After this, it sends no other logs at least for the next fifteen minutes and when rebooted does not produce any more logs.

Hi Dan,

Thanks very much for the code … you saved me a lot of time and it works great. I’m going to use these examples to learn groovy. You should be a teacher if not already. Thanks again.

So, those log entries are all from ST sending data to the ESP01.

The earlier events you showed were from the ESP01.

So, something strange is happening.

Can you copy and paste the detailed parent device info page from the IDE?

Can you ping the hub from a PC? Can you ping the ESP01 from a PC?

When you are looking at the Live Logging, are you looking at ALL devices? Do not just select the parent device. We need to see everything.

Also, when you press the REFRESH button on the parent device on your phone, what do you see in the Arduino IDE’s Serial Monitor window for the ESP01?

Hey Dan,

Any idea why routines don’t work with esp8266 configured only with 2 IS_DoorControl sensor/executors? I have a routine configured to close the door at night, but no joy so far. Everything else works properly.

Jeff