homieiot / convention

🏡 The Homie Convention: a lightweight MQTT convention for the IoT
https://homieiot.github.io/
Other
715 stars 60 forks source link

Core Design Discussion - Discoverable Type #134

Closed timpur closed 5 years ago

timpur commented 5 years ago

Discussion

Ive been looking into https://iot.mozilla.org/wot/ a lot lately. I i think there are some things we could take from and build on top of.

Id like to have a discussion about some core concepts about the design of homie with you guys.

The main thing id like to discus is our core approach to discoverablity. At the moment we have defined device, nodes and properties levels. Each level has defined attributes.

Im thinking in the mind set of, we define what is needed to "discoverable", and use this to implement everything else. Thus device, nodes and properties are self discoverable since they extends discoverable requirements. The idea it to specify the minimum, and let discovery do the rest.

Things to keep in mind:

Example

Lets say we define a Discoverable type to be:

$name: string, required
$type: string, required
$attributes: [discovery-path], optional
$discoverables: [discovery-path], optional

A Device is an extension of Discoverable, thus:

$name: 'homie-device'
$type: 'device'
$attributes: ["display-name", "version"]
$discoverables: ["temp-node"]

// Attributes
display-name: "Homie Device"
version: "4.0.0"

// Discoverables
temp-node/$name: "temp-node"
temp-node/$type: "temp"
temp-node/$attributes: ["simple-value"]
temp-node/$discoverables: ["complex-value"]
temp-node/simple-value: "25.00"
temp-node/complex-value/$name ... and so on

The idea is that we just use recursion, no level is unique, everything is discoverable with the same process.

Additional Notes

Hope to see your thoughts, remember these are raw ideas, not all of it makes sense :P

timpur commented 5 years ago

In Types (typescript) it would look something like this:

interface Discoverable {
  $name: string;
  $type: string;
  $attributes?: Array<Attribute>;
  $discoverables?: Array<Discoverable>;
}

type Attribute = string;

EG.

interface Device extends Discoverable {
  display-name: string;
  version: string;
  temp-node: Discoverable;
}

const device = {
  $name: "homie-device",
  $type: "device",
  $attributes: ["display-name", "version"],
  $discoverables: ["temp-node"],
  display-name: "Homie Device",
  version: "4.0.0",
  temp-node: {
    $name: "temp-node",
    $type: "temp",
    $attributes: ["simple-value"],
    $discoverables: ["complex-value"],
    simple-value: "25.00",
    complex-value: {
      ...
    }
  }
}
davidgraeff commented 5 years ago

The convention is how it is I'm afraid. Subtle details can be changed but the core topology was set in stone in the beginning already.

The target audience is all the different DIY projects publishing to anywhere on your MQTT broker to be harmonised.

Currently we have Property Attributes im thinking we could define all core ideas in one format.

For $attributes the format could be {discovery-path}[:[{datatype}]:[{unit}]:[{flags}]:[{format}]] Flags: r=retained, s=settable, !=not. eg. value, value:string, value::°C, value:number:°C, value:::!s!r.

$attributes: ["display-name:string", "version:string", "temp:number"]

You successfully reinvented JSon. Some projects like the HomeAssistant MQTT components use this approach of one descriptive topic that uses json to announce all meta data at once. Homie does not though.

davidgraeff commented 5 years ago

Closing for now to keep this tidy. Please reopen if necessary :)