Is Z-Uno supported by Smart Things? I need a water level sensor

Thanks. I’ll purchase the hardware - maybe the lights will come on for me. Currently I have no idea how this will work.

What exactly are you trying to accomplish? That would help us advise you on your options.

I’m looking for a solution to fill a water tank by turning a water pump on when the water drops below a specified level.
Thanks for you response.

Sounds like @Saif76 does indeed have a solution that you could use without having to reinvent the water wheel! :wink:

I have ordered the sensor and ESP8266. (I have never used a device like this, so I suppose a big learning curve awaits me.
Is my understanding correct that once I have these devices set up with my wifi, I’ll be using your ST_Anything DTH. Am I correct that there is a child-device for the Ultrasonic Distance Measuring Transducer? I suppose once I have all this connect and talking to each other, I will be able to figure out how to calibrate the sensor. I’m concerned that I’ll not be able to read the water level in webCoRE.

Hendre,

I believe you’re going to need some code developed by @Saif76 to get things going. My library does not currently have support for an Ultrasonic Distance Sensor (at least not that I can recall! :slight_smile: )

You are correct that you’ve got a big learning curve ahead of you if you’ve never done any Arduino programming before. There are plenty of “getting started tutorials” that you should familiarize yourself with before even attempting to use ST_Anything. ST_Anything is a hobbyist tool-kit, with some ready-to-run device support. For custom things, like this ultrasonic sensor with tight timing characteristics, some knowledge of C/C++ programming on the Arduino/ESP8266 platform is required. You will also need to learn how to write some Groovy language code on the SmartThings IDE side of things. There is no standard ST Capability for a Level Sensor, so you’re looking at some custom code there as well.

Hopefully @Saif76 can provide some of his work to get you kick-started.

Thanks Dan. I will first do some reading so that I at least have some understanding of what I’m dealing with, before I start bugging @Saif76.

Hi @Saif76.
Would you mind sharing the code you used to get the ultrasonic sensor working with ST_Anything?
There are a few members looking for a solution to check the water level of a reservoir/tank.
Thank you for considering.

Hey,

Yes, Let me post it here and if @ogiewon is interested in including it in his library i’m fine with that.

There is one important change you have to make in the “parent-st-anything-ethernet.groovy”, I had to add a condition to intercept the value of the sensor so i could calculate and show me capacity in percentage and liters. The water tank i am using is cylindrical in shape so my settings accept a height and diameter in cm to calculate volume.

This is the sensor i used - https://www.amazon.com/Waterproof-Ultrasonic-Distance-Measuring-Transducer/dp/B01J5KZU8M/ref=sr_1_sc_1?ie=UTF8&qid=1517795020&sr=8-1-spell&keywords=ultarsonic+water+proof

Here is the code to the Arduino class and the DH - https://github.com/saif76/STWaterLevel

Here is what the it looks like in the app

In the parent device handler i had to change this

childDevice.sendEvent(name: namebase, value: value) 

to

            def functionExist = childDevice.parseValue(namebase,value) // check if the child has a parse function
            if(functionExist)
            {
            	 //log.debug "Function Exists"
            }
            else
            {
            	childDevice.sendEvent(name: namebase, value: value)
                //log.debug "function does not exist"
            }

I know @ogiewon has made a few changes to the library since then, I have not updated my code to accommodate the changes, So please make modifications to fit your needs.

1 Like

Thanks very much - much appreciated. I can’t wait to try this.

Did you install the sensor at the top of the tank, looking down towards the bottom thereof?

Hi again @saif76 and @ogiewon
I’ve now been busy for a few hours and have made some headway. I’ve learned how and managed to program the ESP8266 (ESP-01 Standalone version) and I think I know how to compile the sketch.

I got so far as to get the On/Off LED ST device working. I messed this up however by writing @saif76’s sketch to the ESP8266, which made me realize that one can only write one sketch at a time. I suppose I have to add the libraries together and write them all at the same time as one sketch to the chip?

I noticed the following in the heading of your sketch:

- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte digitalTriggerPin - REQUIRED - the Arduino Pin to be used as a digital output to trigger ultrasonic
//				- byte digitalEchoPin - REQUIRED - the Arduino Pin to be used as a digital input to read the echo
//

Am I correct that I have to add this info here:

PS_Ultrasonic(const __FlashStringHelper *name, unsigned int interval, int offset, byte digitalTriggerPin, byte digitalEchoPin);

If I’m correct, could you help me with the Groovy ST_Anything name? Not sure which DH info I should add there. Should it be Child Ultrasonic Sensor?

Which brings me to another question - once the ESP8266 has been programmed, how did you hook-up the chip to power and the Ultrasonic Sensor? The Sensor came with its own board, but so far I’ve been unable to determine how that should be connected.

Sorry for the newbie questions and thanks again for your assistance.

Edit: I don’t know if I’ve been going at this for too long now, but I don’t think I have any idea of how to combine the sketches and which ones I have to use. My goal is (at this stage) to only use the Ultrasonic Sensor, connected to an ESP-01, to measure the water level in a tank. I managed to do the LED On/Off thing in @ogiewon’s example, but now I stuck. I don’t know which of his sketches I should use and how @Saif76’s sketch for the Ultrasonic sensor, should be added to that.

I made the changes to the parent-st-anything-ethernet DTH.

Hi @Saif76/@ogiewon
I hate to be annoying, but if you perhaps have a few minutes in the next few days, I’ll appreciate your guidance immensely.
Thank you.

Start by following the standard ST_Anything ReadMe linked below. Use the ST_Anything_Multiples_ESP01.ino sketch to get started. Once you have this example working, you can start incorporating @Saif76’s new additions for the ultrasonic level sensor.

Is there a reason you didn’t go with a NodeMCU ESP8266 based board? They are much easier to use as they have onboard USB to ease connection and programming from your computer. The ESP01’s are tiny and inexpensive, but a bit of a pain to hook up and program.

Thank you, Dan, your assistance is much appreciated.

Why the ESP01? Simply because of a lack of experience. As I indicated earlier, I, however, managed to figure the programming out and got so far as to get your LED On/Off example working just fine.
It is the next step where I run into trouble, regardless of how many times I’ve read the README. (I really try to work stuff out, because that is the only way of getting to understand these things.)

My issues which I’ve not been able to figure out:
• Which of your libraries should I use with @Saif76’s sketch? I understand I should use the SmartThingsESP8266WiFi library?
• My understanding is that your library should be combined with @Saif76’s code for the ultrasonic sensor. My issue is that I don’t know how to combine the two. I have tried by loading your SmartThingsESP8266WiFi library and @Saif76’s code in 2 tabs of the Arduino IDE and issued the compile command. That did not work. I tried to “integrate” @Saif76’s code to the bottom of your ESP8266 library within the same tab in the Arduino IDE, but that would also not compile the sketch. My issue is that I know so little, it is almost impossible for me to tell why it fails because I could be making mistakes on numerous levels. I don’t know if I’m adding @Saif76’s code correctly, neither which of your many libraries I should use.

The question therefore here is: If I only want to use the Ultrasonic Sensor, which of your libraries should I use and how do I add @Saif76’s code to your library in the Arduino IDE to create the sketch?

@Saif76’s code contains the following remark at the top: “- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name” What is the object here? Is it your generic ST_Anything Tile in the ST App, or the Tile name of the new DTH being created for the Ultrasonic Sensor.

• Also, not using an Arduino but the standalone ESP8266, how should I change this part of his code, taking into account his remarks at the top of his code: _PS_Ultrasonic(const __FlashStringHelper *name, unsigned int interval, int offset, byte digitalTriggerPin, byte digitalEchoPin). Do you know what the Serial Pin (for the ESP8266) settings should be and how it should be defined here? The examples I could find on the internet contains what seems to be complicated coding and not simply a single digit representing the Pin. Perhaps if I could see what @SAI76’s working sketch looks like, I’ll be able to figure this one out?

• Lastly, as far as the Hardware setup is concerned, once I’ve written the Sketch to the ESP8266, do I connect the Trig and Echo pins of the ultrasonic sensor to the TX/RX pins respectively, or the other way around? Or should the Sensor be connected to the GPO pins of the ESP8266 (I’ve seen other projects on the www connecting sensors to the GPO pins, but I can’t figure out why/when that should rather be used.)

I’m sorry for being such a bother, but I really need to get this working to determine the level of my backup water reservoir. My problem is that I often attempt (electronic/programming) projects far beyond my capabilities.

Hendre,

Before we can learn to fly, we all need to learn to crawl, eh? :slight_smile:

For now, I need you to follow my instructions in the ST_Anything ReadME that I linked above. When you say you got my “On/Off” example working, I need for you to realize that example is not really part of ST_Anything. That is part of the SmartThings… set of communication libraries. Ignore the “SmartThings” examples. I need you to follow the exact step by step instructions in the ST_Anything v2.9 ReadMe file.

In those instructions, it tells you to try compiling and running one of the sample ST_Anything sketches. I specifically told you which sketch you should try to get ST_Anything running on your ESP01 module. Once you get that sketch up and running on the ESP01, and properly showing up in SmartThings on your phone’s ST app, then we can start looking at @Saif76’s additions. Forget about ultrasonic sensors, wiring, combining code, etc… for now. Just focus on following the ReadMe I linked above and getting a solid ST_Anything foundation up and running.

After you get that working, we can start thinking about @Saif76’s code.

1 Like

Hi Dan
I have gone through the Readme again, step by step, but I must be missing something, because I got to the same result:
I compiled the sketch you referred me to, changing the device IP; gateway; subnet; DNS server and ST Hub ID. The sketch compiled without an error and was successfully written to the ESP8266.
I again checked the settings of Parent_ST_Anything_Ethernet in the ST IDE. All seem to be correct:

ST Anything Device ST Anything
Name ST Anything
Label ST Anything
Type Parent_ST_Anything_Ethernet
Version Published
Device Network Id 50B7C3F43143
Status ACTIVE
Hub Home Hub
Group System
Last Activity At 2018-02-10 3:26 PM SAST
Date Created 2018-02-10 3:26 PM SAST
Last Updated 2018-02-14 6:18 PM SAST
Data No data found for device
Current States
numberOfButtons: 5
Preferences (edit)
Name Type Value
ip text 192.168.0.28
mac text 50B7************
numButtons number 5
port text 8090
Execution Location Cloud

I checked the settings of the Device in the ST App on my phone. I did not know what I should set the “buttons” to and entered “5”.
My understanding is that child devices should be created when I save the settings in the ST App. No child devices are however created.

I see no error messages in the ST IDE Log (for ST Anything):

728117ed-a723-41fd-8396-060c0954332e  6:28:06 PM: debug Using ip: 192.168.0.28 and port: 8090 for device: 728117ed-a723-41fd-8396-060c0954332e
728117ed-a723-41fd-8396-060c0954332e  6:28:06 PM: debug Executing 'sendEthernet' refresh
728117ed-a723-41fd-8396-060c0954332e  6:28:06 PM: debug Executing 'refresh()'
728117ed-a723-41fd-8396-060c0954332e  6:27:46 PM: debug Using ip: 192.168.0.28 and port: 8090 for device: 728117ed-a723-41fd-8396-060c0954332e
728117ed-a723-41fd-8396-060c0954332e  6:27:46 PM: debug Executing 'sendEthernet' refresh
728117ed-a723-41fd-8396-060c0954332e  6:27:46 PM: debug Executing 'refresh()'
728117ed-a723-41fd-8396-060c0954332e  6:27:46 PM: debug Executing 'updateDeviceNetworkID'
728117ed-a723-41fd-8396-060c0954332e  6:27:46 PM: debug Executing 'configure()'
728117ed-a723-41fd-8396-060c0954332e  6:27:18 PM: debug Using ip: 192.168.0.28 and port: 8090 for device: 728117ed-a723-41fd-8396-060c0954332e
728117ed-a723-41fd-8396-060c0954332e  6:27:18 PM: debug Executing 'sendEthernet' refresh
728117ed-a723-41fd-8396-060c0954332e  6:27:18 PM: debug Executing 'refresh()'
728117ed-a723-41fd-8396-060c0954332e  6:27:18 PM: debug Executing 'updateDeviceNetworkID'
728117ed-a723-41fd-8396-060c0954332e  6:27:15 PM: debug Hub Port = 39500
728117ed-a723-41fd-8396-060c0954332e  6:27:15 PM: debug Hub IP Address = 192.168.0.21
728117ed-a723-41fd-8396-060c0954332e  6:27:15 PM: debug Executing 'updated()'

This is where I get stuck every time.

What should I see in the ST app?

Not sure which other info will help you to help me:

  • I noticed that the Network ID of the Device changed to the MAC Address of the ESP2866.
  • I can ping the ESP8066’s IP.
  • Github integration is working fine and there are no updates.
  • The Events Log of the ST Anything Device shows nothing unusual:

ST Anything (Device) Events — displayed | all | from device
Date Source Type Name Value User Displayed Text
2018-02-14 6:16:03.700 PM SAST
37 minutes ago DEVICE numberOfButtons 5 ST Anything number of buttons is 5
2018-02-10 3:28:12.044 PM SAST
4 days ago DEVICE numberOfButtons 0 ST Anything number of buttons is 0
2018-02-10 3:26:51.431 PM SAST
4 days ago DEVICE ALERT childDeviceCreation failed ST_Anything Parent Device has not yet been fully configured. Click the ‘Gear’ icon, enter data for all fields, and click 'Done’
2018-02-10 3:26:08.494 PM SAST
4 days ago DEVICE ALERT childDeviceCreation failed ST_Anything Parent Device has not yet been fully configured.

Sure hope you can spot where I’m going wrong and thanks again for your patience. (Hope I won’t have to say that for much longer)

The number of buttons should be set to 0 (zero) since the sketch I told you to use should only have 1 contact sensor and 1 motion sensor defined in the setup() portion of the sketch.

What you should see in SmartThings is a Parent Device with 2 Child Devices (one for Motion and another for Contact).

If you don’t have those created, then you should

  1. check to make sure the MAC address you entered into the Parent’s configuration is correct. This is the number 1 problem people have.
  2. verify the IP address of your ST Hub is correct in the Arduino sketch.
  3. make sure the Parent Device is assigned to your Location and Hub in the ST IDE (Devices tab)
  4. Verify that you _publish_ed each of the Child Device Handlers in the ST IDE (Device Handlers tab)

By pressing “Refresh” in the Parent Device (inside the ST app on your phone), you should see some Live Logging data in the ST IDE. You should also see the corresponding ‘refresh’ command received by the ESP01 in the Arduino IDE Serial Monitor window.

Check all of those things and let us know what you find…

Thank you Dan, you’ve done it! Now I’m even more excited about the possibility of getting the sensor to work.

image

Patiently awaiting the next lesson.

(I suppose I owe you an explanation, even though I’m too embarrassed to tell what I had done wrong. I had the MAC address wrong in the app. When I could not get this to work a few days ago, I tried a different ESP8266 to eliminate the possibility of a hardware issue and in the process, got the MAC addresses of the devices mixed up. :anguished:)

1 Like

Hi @ogiewon
I have been playing with the Arduino IDE to see if I can figure out how to add the Sensor to the ST_A Multiples sketch, but without success. I though I’l first try to compile the sketch without doing the configuration part as explained in @Saif76’s library and if I could get that to work, I’ll bother you guys to find out how to configure the sketch for the sensor, but as I say, I did not have any luck. I found a few videos on Youtube dealing with ST_Anything, but they are more about the result than how to set up the sketch.

So, I’ll appreciate some guidance when you have a few minutes to spare.

  • I don’t know how to include the Ultrasonic sensor to the ST_A Multiples sketch. I have a sub-folder (called ST_WaterLevel) under the Libraries folder containing the .h and .cpp files and I though all I had to do, was to add #include <PS_Ultrasonic.h> under // ST_Anything Library, but it fails to compile.

  • Where do I add this: Create an instance of this class in your sketch’s global variable section
    __ /For Example: st::PS_Ultrasonic sensor1(“ultrasonic”, 120, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_T); and_

  • And what should these be set to:
    st::PS_Ultrasonic() constructor requires the following arguments
    // - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
    // - long interval - REQUIRED - the polling interval in seconds
    // - long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time

I hope this will be the last time I have to ask about this.

I’ll take a quick look ar @Saif76’s code to see what it will take to add it to an ST_Anything sketch…