Separate things on a single device regarding the UI

Hi again
Is it possible to add multiple separated things on a single device (ex:esp8266) instead of grouping them all?
The following images describe exactly what I want:
Active case:


Admirable one:

I’m pretty sure that this can be done by giving things different URLs like this: Ip/things/LED Ip/things/DISTANCE etc, but I don’t know how to do it.
I’ve checked out one of the suggested posts during the creation of this post titled “Multiple things on Arduino”, and edited it to fit my needs. The sketch is as follows:



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

const char *ssid = "*=* dP *=*";
const char *password = "djfa1953";

#if defined(LED_BUILTIN)
  const int ledPin = LED_BUILTIN;
#else
  const int ledPin = 13; // manually configure LED pin
#endif

WebThingAdapter *adapter;

const char *ledTypes[] = {"Light", nullptr};
ThingDevice led1("led1", "Built-in LED 1", ledTypes);
ThingDevice led2("led2", "Built-in LED 2", ledTypes);
ThingProperty ledOn1("on", "", BOOLEAN, "OnOffProperty");
ThingProperty ledOn2("on", "", BOOLEAN, "OnOffProperty");

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFB, 0x80 };
IPAddress ip(192, 168, 0, 100);

bool lastOn = false;

void setup(void) {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);

  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  adapter = new WebThingAdapter("w25", WiFi.localIP());

  led1.addProperty(&ledOn1);
  led2.addProperty(&ledOn2);
  adapter->addDevice(&led1);
  adapter->addDevice(&led2);
  adapter->begin();

  Serial.println("HTTP server started");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.print("/things/");
  Serial.println(led1.id);
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.print("/things/");
  Serial.println(led2.id);
}

void loop(void) {
  adapter->update();
  bool on = ledOn1.getValue().boolean;
  digitalWrite(ledPin, on ? LOW : HIGH); // active low led
  if (on != lastOn) {
    Serial.print(led1.id);
    Serial.print(": ");
    Serial.println(on);
  }
  lastOn = on;
}

Am I on the right way?
I hope my question is clear enough.
Thanks in advance.

Nas

This is up to the adapter developer as to how the device is presented.

In fact, for one addon, I wanted to ask the developer to merge the properties into one device rather than many.

It’s not nice for me to see the light and the distance measurement are grouped together without the need of grouping them.

@N4SIR0DDIN3 Yes, that thread you posted will show you exactly what you need to do.

Awesome!!!
I’ve uploaded the sketch, and the result was satisfying.

Have a look at the new Highlights addon. It allows you to turn any existing property into a new separate thing.

1 Like

Sounds really interesting.
I’ll give it a try.

I am using a zooz 4-in-1 motion/temperature/humidity/light sensor, and ran into the same issue of being able to add it as only one type of device. The Highlights workaround did the trick for me. I originally added it as a motion sensor only, and then added 3 more devices through highlights. Make sure to define one ‘highlight’ at a time, then add it in the Things section, rename it, and repeat for each sensor. Otherwise, they all show up under the original name in Things and you won’t be able to tell which one is which.