ESP8266 Temperature Monitoring in Smartthings? (Where to start with a new device)

I’m a bit new to Smartthings and having trouble getting started. I have created a Wifi temperature sensor using a Nodemcu ESP8266 board and DS1820. The ESP8266 posts the temperature to an internal webpage, and also sends the data to Thingspeak.com.

I’m trying to monitor this temperature data in Smartthings, and I’m not sure where to start. Does anyone have some sample code that can get me started? I think I need to create a DeviceHandler and Smartapp to send an HTTP Get request, but I’m not sure how to proceed.

Many thanks for the help!

1 Like

same situation here

I believe you will need to create a service manager, but maybe it’s just a web service . Have you had a chance to look at the developer documentation?

http://docs.smartthings.com/en/latest/

Also, see if the following thread gives you any ideas . A lot of people use MQTT as a bridge.

If your module accessible via http url, it’s easy then, you need a temperature device handler that handle and digest the http response, then create a virtual http device so you can see them in ST app.

Check out my recent release of HTTP switch creator, doing almost the same things but it’s an on/ off switch

1 Like

Thanks for the reply, your HTTP Switch Creator was a helpful start. I’m struggling to make the transition to an HTTP temperature sensor from the HTTP switch. I’m surprised there aren’t more examples like this, can’t believe I’m the first one trying this?

A couple questions:

  1. My device handler code below is a collection of code fragments I’ve found, but I know it still has a number of issues issues. Any ideas on where my issue might be in the device handler to request the data?

  2. For my ESP8266 Temp Sensor, I’m using Arduino IDE. I currently have it posting data to Thingspeak.com and to an internal web page. What code do I need to include for the ESP8266 to respond to the Device Handler request?

Thanks for the help!!!

/*
*  HTTP Temp
*  Category: Device Handler
* 
*/
import groovy.json.JsonSlurper

metadata {
	definition (name: "HTTP Temp", namespace: "mv", author: "MV") {
        capability "Temperature Measurement"
		attribute "temperature", "string"
	}
	preferences {
		input("DeviceIP", "string", title:"Device IP Address", description: "Please enter your device's IP Address", required: true, displayDuringSetup: true)
		input("DevicePort", "string", title:"Device Port", description: "Empty assumes port 80.", required: false, displayDuringSetup: true)
	}
	simulator {
	}
	// UI tile definitions
	tiles(scale: 2) {
		valueTile("Temperature", "device.temperature", width: 2, height: 2) {
			state("default", label: 'Temperature ${currentValue}',
				backgroundColors:[
					[value: 50, color: "#00cc33"],
					[value: 60, color: "#99ff33"],
					[value: 67, color: "#ff6600"],
					[value: 75, color: "#ff0000"]
				]
			)
		}
//		main "Temperature"
//			details (["temperature", "refresh"])
	}
}
def parse(String description) {
    log.debug "Parsing '${description}'"
    def map = [:]
    def retResult = []
    def descMap = parseDescriptionAsMap(description)
    log.debug "parse returns $descMap"
}
//handle commands
def poll() {
    log.debug "Executing 'poll'"
    //getReading()
}

def refresh() {
    log.debug "Executing 'refresh'"
    getReading()
}

// Get the sensor reading
private getReading() {
  setDeviceNetworkId(ip,port)

  log.debug("Executing hubAction on " + getHostAddress())

  def userpassascii = "${username}:${password}"
  def userpass = "Basic " + userpassascii.encodeAsBase64().toString()

  def uri = "/marcos/getCPUTemp"
  def headers = [:]
  headers.put("HOST", getHostAddress())
  headers.put("Authorization", userpass)
  log.debug "Headers are ${headers}"

  def hubAction = new physicalgraph.device.HubAction(
    method: "POST",
    path: path,
    headers: headers
  )
  log.debug hubAction
  hubAction    
}

check the generic http handler from @jzst, he added temperature sensor support:

@Swampmatt

Did you make any headway with this? I’m getting ready to start on a similar project. I’m not a dev, but I’ve been able to do simple contact closures, temp, humidity and moisture sensor in the past. Hopefully I can get this too :slight_smile:

If you have any code that you’d like to share, feel free to post or you can email me at my username @ gmail.

Any update on this?

I recently released a new version of my ST_Anything and SmartThings Arduino libraries which now can run natively on the ESP8266 series of boards, using WiFi to communicate to SmartThings via the ST Hub.

1 Like

This has been my solution to monitor the hot water of my outside boiler. Is a SONOFF TH w/ Eric’s custom firmware and device controller for ST. Works like a charm, have it integrated with my smartiles dashboard.

How do I get the temp and humidity to show? Can these be used to turn on off the th?