[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

What happens if you change that line to

if ((name != null) && (value != null)) {

I haven’t tested this at all yet, so I’d appreciate it if you could let me know if it works, please.

This appears to be working. Getting “0” values now on the phone app. I also added a 2 lines to cut off the decimal since I don’t need it when reporting millivolts.

def parse(String description) {
    log.debug "parse(${description}) called"
	def parts = description.split(" ")
    def name  = parts.length>0?parts[0].trim():null
    def value = parts.length>1?parts[1].trim():null
    
    // get rid of the decimals since its millivolts
    value = Float.parseFloat(value)
    value = value as int 
    
    if ((name != null) && (value != null)) {
        // Update device
        sendEvent(name: name, 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)
    }
    else {
    	log.debug "Missing either name or value.  Cannot parse!"
    }
}
1 Like

So I have a small issue, its not related to the work here, I just think its where I have my ESP32 and DS18B20 located. I’m using this to control my pool so there may also be AC interference on data wire.

I keep getting a random “Temperature for the device # 1 is: -196.60”, maybe like 1 out of 20 readings get sent back to smarthings as “-196.60”

Is there a way not to send: “Everything: Sending: temperature1 -196.60”, like ignore all bad readings and not send them to ST?

Thanks for any help!
Nathan

BTW:
I know its not the sensor, board or wiring, as I have tried two different setups (see below)

Connection Setup
I have the DS18B20 connected to my ESP-WROOM-32 via a 6’ shielded cat5 cable (shield connected to ground, and using 2 pairs: +5 & ground twitted pair , data & ground twitted pair. I have tried both a 4.7k and a 3k pullup resistor connected at board side(not at sensor). I have also tried 2 different sensors and have also had this same issue on a ESP8266(that im now upgrading to a ESP32) so 2 different board and also two different complete wire setups.

I think I understand the issue you’re seeing… You could modify PS_DS18B20_Temperature.cpp source code to not send the invalid data. The -196.60 value you’re seeing is the same value you’d get if no sensor was connected at all, IIRC. I personally prefer to allow ST_Anything to send the data, invalid or otherwise, in order to know that there is some sort of a problem.

However, a simple fix in your case would be to simply modify the “Child Temperature Sensor” DTH groovy code to catch these large negative values and exclude them from being used. This would give you the opportunity to at least add a log.debug statement to know whether or not data has been excluded. I would also NOT update the Last Updated time stamp.

Maybe something like this (untested code below!!!)

def parse(String description) {
    log.debug "parse(${description}) called"
	def parts = description.split(" ")
    def name  = parts.length>0?parts[0].trim():null
    def value = parts.length>1?parts[1].trim():null
    if (name && value) {
    	// Offset the temperature based on preference
        def offsetValue = Math.round((Float.parseFloat(value))*100.0)/100.0d

        if (offsetValue < -190) {
          log.debug "Invalid sensor data = ${offsetValue} received and excluded"
          return
        }

        if (tempOffset) {
            offsetValue = offsetValue + tempOffset
        }

        if (tempUnitConversion == "2") {
            //log.debug "tempUnitConversion = ${tempUnitConversion}"
            double tempC = fahrenheitToCelsius(offsetValue.toFloat())  //convert from Fahrenheit to Celsius
            offsetValue = tempC.round(2)
        }

        if (tempUnitConversion == "3") {
            //log.debug "tempUnitConversion = ${tempUnitConversion}"
            double tempC = celsiusToFahrenheit(offsetValue.toFloat())  //convert from Celsius to Fahrenheit
            offsetValue = tempC.round(2)
        }

        // Update device
        sendEvent(name: name, value: offsetValue)
        // 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)
    }
    else {
    	log.debug "Missing either name or value.  Cannot parse!"
    }
}

I have a lot of these DS18B20 sensors and they do throw out an invalid number occasionally. I think Dan’s solution is the easiest way. I have been filtering them in the Arduino code but that requires you to not use the ST_Anything polling sensor and use the native Dallas one wire library and code, then push to ST separately.

You maybe sampling it to often.
Check out page 9.
I have using one with no problems, but I only poll it every five minutes.

I a arduino soil moisture sensor YL-69.

How get work with smartthings?

It depends on how you want to use that sensor. What is your goal? The sensor has both a digital and analog output, so the answer to the question will help determine the best method for integration.

I was thinking I could use it to detect a water leak and to see when I need to water my plants using the digital pen.

Which micro controller are you planning on using?

ST_Anything already has support for basic analog water sensor which can easily report the standard SmartThings states of “wet” or “dry”. So, you could use the PS_Water device to achieve your goal if your micro controller has an analog input.

If you really need to use a digital input, I’ll have to add a new device to ST_Anything to support using a digital input for detecting “wet” and “dry”.

Is there a DH for a plant moisture sensor in ST_Anything? If so what model?

Thanks

Not specifically for plant moisture…but there is one for a generic analog water sensor. This implement the ST Capability for water leak detection, reporting either wet or dry, based on an analog threshold you define when declaring the PS_Water Device in your sketch.

This could be easily used with any soil sensor that outputs an analog signal.

Here is the water sensor I used when developing the PS_Water Device for ST_Anything

Esp8266 no more need to write WiFi credentials in the code. Watch the video in let me know if you think you can implement this into St anyting.

I am well aware of this ESP8266 capability, but I am not currently considering adding this to ST_Anything. Others have successfully done this within their sketch. Search this thread to see how they’ve done it.

Personally, since you have to edit the sketch anyway to define your devices, I believe it is simpler to hard code these values.

I did add Arduino IDE OTA (over the air) update capability to the ESP8266 already. This makes making changes pretty easy, without having to connect anUSB cable after the initial sketch upload to the ESP8266.

1 Like

So I think that will work. I only care when it needs water. Here’s what I am considering.

Thanks

As long as those are used in ‘Analog Mode’, you should be able to use the existing PS_Water device. The only ‘gotcha’ that we might run into is if the logic is reversed from the behavior of the ‘red’ sensor I linked above. In that case, it is a simple code edit to change a ‘>’ symbol to a ‘<’ symbol in PS_Water.cpp.

If you really just want a notification on your phone, you could also simply wire the Digital output on this sensor to a digital pin. Then, use the IS_Contact device to monitor the pin and send ‘open’ and ‘closed’ events. You can then use these events to send you a notification. If you decide to try this route, we may need to disable the internal pullup resistor feature of the IS_Contact device (no code change necessary for this, though…)

Yeah analog mode was what I was thinking. Ultimately I want the Arduino to activate a relay that opens a valve to water some plants based on what that sensor tells me. Dry=operate relay,

Understood. I’d say buy one and start playing with it. I am happy to assist your ST_Anything to get it working the way you’d like it to. Another user was asking the exact same question just a few posts above yours.

They are on my list. I hope to get my Arduino installed with other sensors and relays soon. Thanks for all your support

1 Like

Here’s my experience with soil moisture and water leak detection. I have one of those soil moisture resistive probes with DO and AO board using the analog out and publishing to ST using the Humidity device handler. The ST part works great, the probe not so well. The probe starts to corrode and drift down over time. Would try a capacitive probe next time around.

For floor water leak detection Im using the PS_water handler and this sensor, works great.