[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

Jeff,

Thank you for pointing out that minor bug which has been in the code for years! I appreciate the extra set of eyes.

I have fixed it in the ST_Anything class modules’ comments (Illuminance and Voltage). I have also revised the SY_Anything_Multiples_EthernetW5100.ino example sketch.

Again… Thank You!

Dan

I also used 0-1023 as in "float voltage = sensorValue * (5.0 / 1023.0);"
Not sure what your use case is, but to compute actual usage (Irms & Power) I used the EmonLib.h library. It only requires a simple calibration adjustment like “emon1.current(A0, 111.1);”

4/20 Edit: I used these Sparkfun Current Sensor to monitor power. I also have a couple Aeon Power Sensors, but their clamps are enormous and too big as they are made for whole home usage. Another note is that I purchase many of my building components from Sparkfun. They are a little more expensive than getting direct from China, but many (most) times just can’t wait. Sometimes they have custom parts that others don’t even have like these: Mini RGB LED
Hope this helps,
Garnet

Garnet,

At some point I’ll look at the OTA update for the ESP8266 boards. It’s just not high on my priority list as I really need to focus on documentation. Somehow, I managed to put that task off for another night! I am easily distracted when someone like @VooDooFiveTwo asks for new ST Capabilities to be added! :wink:

Dan

Dan, Sorry for the distractions! I am hoping the added capability will be of use to the community. I will stop sending new requests while you finish documentation, which is much more important than my specific projects. Meanwhile, my focus will be bench testing and feedback if I find anything of interest.

1 Like

No worries. I welcome the requests. Documentation is boring! Getting stuff to work is the fun part.

1 Like

Dan, I have your Multiples example up and running on a Mega with Ethernet Shield. I/O function has been bench verified for CO, Voltage, Smoke, Contact and Alarm. Thanks again for the quick capability adds.

1 Like

Hello Eric I’m wondering if you plan to complete the sonoff set and hack the 4 channel device soon as I have six on order so this would finish my home automation project off with style also ordered led rgb controllers to add to my system.ps I flashed the duals with the firmware work great except on the screen where the 2 relays are shown in smarthings,I am unable to change names on these .any clues Thanks

I can’t really do it without a guide if I’m being brutally honest. Though I am learning everyday - understanding that little bit more [learnt what PWM was yesterday]. My noob levels are just too low, I may not be your ideal audience, but with a simple guide and an appetite to learn, I think anyone could get into this stuff.

At the moment i’m trying out Nate’s implementation, but fallen over at the oauth part. So I may over to STA2.2 sooner than I thought, especially as your new sketches just dropped using “Button”.

Anyhow, keep up the good work, it’s appreciated.

1 Like

I’ve finished the 4 Channel. I’ll post it on my thread soon.

As for the naming, @ogiewon, did you ever find a way to change the name of the child device that is seen in the parent handler after the child has been created?

@erocm1231

Nope, I was never able to figure out a solution to that one. May have to ask ST Engineering for an answer. BTW - Thank you very much for your examples of using the Composite Device Handler. I owe you a lot of credit for my recent ST_Anything work.

Again thanks guys for your support much appreciated

Sweet… I’m going to start from scratch… using your latest device handlers code… probably get the ball rolling over the weekend… really appreciate it!

I think i’m off to a good start with your device handler… (see screenshot)… what is next for me? just start plugging in reed sensor pins from the panel into Arduino board?

Thanks!!

What’s this message “null” mean? can’t figure it out…

Dan,
Any chance of a pulse counting flow meter ? I’m wanting to program my ESP-13. I have tried this code and the interrupt routine works.

I can see the messages printed when I blow into the water flow sensor.
The sensor is on pin 2.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

#include “Adafruit_IO_Client.h”

#define AIO_KEY “…your AIO key…”

// Create an ESP8266 WiFiClient class to connect to the AIO server.
WiFiClient client;

// Create an Adafruit IO Client instance. Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Finally create instances of Adafruit_IO_Feed objects, one per feed. Do this
// by calling the getFeed function on the Adafruit_IO_FONA object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed testFeed = aio.getFeed(“esptestfeed”);

int flow;
int flow_pin = 2;
int READ_INTERVAL = 60; // measurement interval seconds

unsigned long flow1count = 0;
long lastReadStart;

int READ_INTERVAL_MILLIS=READ_INTERVAL* 1000;

#define countof(a) (sizeof(a) / sizeof(a[0]))

//char ssid[] = “abz-fi”; // your network SSID (name)
//char password[] = “we do what we must, because we can”; // your network password
const char* ssid = “BRCMGUEST”;
const char* password = “olaitntdf”;

// Update these with values suitable for your network.
//IPAddress server(10, 13, 0, 136);

//PubSubClient client(server);

void setup()
{
Serial.begin(115200);

pinMode(flow_pin, INPUT_PULLUP);
attachInterrupt(flow_pin, flow1, RISING);

// client.set_callback(callback);
// Connect to WiFi network
WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.print(".");
}
Serial.println("");
Serial.println(“Esp General Purpose Server”);
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

// if (client.connect(“arduinoClient”)) {
// client.publish(“outTopic”,“flow boot up”);
// client.subscribe(“inTopic”);
// }

}

void loop()
{
unsigned long currentTime = millis();

if (currentTime - lastReadStart > READ_INTERVAL_MILLIS)
{
flow = flow1count*60/READ_INTERVAL;
lastReadStart= currentTime;

    Serial.print("l/hour:");
    Serial.println(flow);
    flow1count = 0;

if (testFeed.send(flow)) {
Serial.print(F("Wrote value to feed: ")); Serial.println(flow, DEC);
}
else {
Serial.println(F(“Error writing value to feed!”));
}
// Now wait 10 seconds and read the current feed value.
Serial.println(F(“Waiting 10 seconds and then reading the feed value.”));
delay(10000);
// To read the latest feed value call the receive function on the feed.
// The returned object will be a FeedData instance and you can check if it’s
// valid (i.e. was successfully read) by calling isValid(), and then get the
// value either as a text value, or converted to an int, float, etc.
FeedData latest = testFeed.receive();
if (latest.isValid()) {
Serial.print(F("Received value from feed: ")); Serial.println(latest);
// By default the received feed data item has a string value, however you
// can use the following functions to attempt to convert it to a numeric
// value like an int or float. Each function returns a boolean that indicates
// if the conversion succeeded, and takes as a parameter by reference the
// output value.
int i;
if (latest.intValue(&i)) {
Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
}
// Other functions that you can use include:
// latest.uintValue() (unsigned int)
// latest.longValue() (long)
// latest.ulongValue() (unsigned long)
// latest.floatValue() (float)
// latest.doubleValue() (double)
}
else {
Serial.print(F(“Failed to receive the latest feed value!”));
}
}
}

void flow1()
{
flow1count +=1;
}

Interesting. I know where in the Parent DH that error is coming from, just not why. It is trying to create a Child Device using a DH name “null” which obviously doesn’t exist.

Can you please post a copy of your Arduino sketch? Make sure your select/highlight all of it once you paste it into the forum software and then click the “Preformatted Text” menu button that looks like “< / >” to prevent the code from getting messed up.

I made alot of progress last night… using your old code… i was having trouble figuring out the multiples parent/child device handlers (what code should i be using since i am going to take your advice and only use the contact reed sensors… i’ll buy zwave motion and smoke detectors for smart things down the road)

I was missing a large fundamental component (i.e. the other sensor wire for the magnetic reeds needs to be tied together with all other sensor reeds…then connected to the ground pin on arduino board…LIKE YOU SAID!!!)… this was a breakthrough for me last night… i was able to successfully test and label every sensor in my house

here is my current PIN setup on my board…comments are my labels…

So i open the smartthings app, open and close all doors and windows and finally getting correct instantaneous return information (opened or closed)…SUCH A COOL FEELING!!!

My issue is when i try to setup notifications…i do not get a push notification or txt message when sensor is “opened” as i specified

should i be using your new code? i like the way it looks on smart things app (easier labels and easier customization)

#define PIN_CONTACT_KITCHEN_WINDOW1 22 //Master Bedroom Window (brown - green)
#define PIN_CONTACT_KITCHEN_WINDOW2 23 //Master Bedroom Slider (red - red)
#define PIN_CONTACT_KITCHEN_WINDOW3 24 //Kitchen Sliding Door (yellow - red)
#define PIN_CONTACT_MASTER_WINDOW1 25 //Guest Bathroom Window (white - green - black)
#define PIN_CONTACT_MASTER_WINDOW2 26 //Guest Bedroom First Floor Left (gray - red)
#define PIN_CONTACT_OFFICE_WINDOW1 27 //Guest Bedroom First Floor Right (purple - red)
#define PIN_CONTACT_OFFICE_WINDOW2 28 //Living Room Porch Window (blue - red)
#define PIN_CONTACT_GUEST_WINDOW1 29 //Living Room Computer Window (teal - red)
#define PIN_CONTACT_GUEST_WINDOW2 30 //

//House Door Pins
#define PIN_CONTACT_FRONT_DOOR 31 //Front Door (teal - red)
#define PIN_CONTACT_KITCHEN_DOOR 32 //Left Living Room Sliding Window (yellow - yellow)
#define PIN_CONTACT_GARAGE_DOOR 33 //Right Living Room Sliding Window (orange - red)
#define PIN_CONTACT_BEDROOM_DOOR 34 //Downstairs Guest Bedroorm Porch Door (orange - red)

//motion pins
#define PIN_MOTION 35

Have you taken a look at the PS_PulseCounter.h and PS_PulseCounter.cpp files in my ST_Anything Arduino library yet? These were created for a user who wanted to measure water flow through a pipe. It uses HW interrupts to count the number of pulses, as well as a polling method to periodically send updates to ST.

I have not tried compiling a sketch for the ESP8266 using one of these devices yet. If you try it out, please post you findings. Just include PS_PulseCounter.h in your sketch and then create one of these devices within you setup() routine like any other Polling Sensor. Read through the comments section at the top of either the .h or .cpp file for details of the constructor’s arguments.

st::PS_PulseCounter sensor3("power", 60, 5, PIN_PULSE, FALLING, INPUT_PULLUP, 1.0, 0);

I have not created a new 'child device handler" for measuring ‘power’ which is what this is most closely related to in the ST Capabilities list (unless water flow was added recently!) So, you may need to “go old school” for now and create a tile directly in the main DH.