All Projects → microclimates → homie-device

microclimates / homie-device

Licence: MIT license
NodeJS port of Homie for IoT

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to homie-device

SenseoWifi
Wifi'ify the Senseo coffee maker. Circuit and firmware for an internal Senseo hack to monitor and control the daily coffee brew (via MQTT) ☕️📶
Stars: ✭ 73 (+265%)
Mutual labels:  homie, homie-esp8266, homie-convention
mijia-homie
A Homie MQTT bridge for the Xiaomi Mijia 2 hygrometer-thermometer. This repo also serves as the monorepo for a handful of helper crates related to Homie and Bluetooth.
Stars: ✭ 40 (+100%)
Mutual labels:  homie, homie-devices
Mqttclient
A high-performance, high-stability, cross-platform MQTT client, developed based on the socket API, can be used on embedded devices (FreeRTOS / LiteOS / RT-Thread / TencentOS tiny), Linux, Windows, Mac, with a very concise The API interface realizes the quality of service of QOS2 with very few resources, and seamlessly connects the mbedtls encryption library.
Stars: ✭ 234 (+1070%)
Mutual labels:  mqtt-client
Android-MQTT-Demo
An android application to demonstrate the complete MQTT lifecycle.
Stars: ✭ 31 (+55%)
Mutual labels:  mqtt-client
microhomie
MicroPython implementation of the Homie MQTT convention for IoT.
Stars: ✭ 72 (+260%)
Mutual labels:  homie
Android Mqtt Service
A simple MQTT Service that will keep running for the duration of your Android application using the Paho Java MQTT Client.
Stars: ✭ 238 (+1090%)
Mutual labels:  mqtt-client
ComfoAirQ-Homie
Homie4 for Zehnder ComfoAirQ
Stars: ✭ 14 (-30%)
Mutual labels:  homie
Broadlink Mqtt
MQTT client to control BroadLink devices
Stars: ✭ 169 (+745%)
Mutual labels:  mqtt-client
flutter im demo
📞 Flutter 使用 MQTT实现IM功能
Stars: ✭ 81 (+305%)
Mutual labels:  mqtt-client
mqtt-rflink-bridge
Homie based bridge between MQTT and RFlink module
Stars: ✭ 21 (+5%)
Mutual labels:  homie
StriderMqtt
A very thin MQTT client
Stars: ✭ 21 (+5%)
Mutual labels:  mqtt-client
homie-control
A high level application for the Homie-esp8266 IoT framework
Stars: ✭ 40 (+100%)
Mutual labels:  homie
Collectd
The system statistics collection daemon. Please send Pull Requests here!
Stars: ✭ 2,700 (+13400%)
Mutual labels:  mqtt-client
mqtt-433mhz-gateway-homie
433Mhz <-> MQTT gateway for smart home 🏡 automation
Stars: ✭ 37 (+85%)
Mutual labels:  homie
Iot Harbor
reactor3实现的mqtt库
Stars: ✭ 234 (+1070%)
Mutual labels:  mqtt-client
eMQTT5
An embedded MQTTv5 client in C++ with minimal footprint, maximal performance
Stars: ✭ 51 (+155%)
Mutual labels:  mqtt-client
Rumqtt
Pure rust mqtt cilent
Stars: ✭ 198 (+890%)
Mutual labels:  mqtt-client
python-mqtt-client-shell
Python-based MQTT client command shell
Stars: ✭ 45 (+125%)
Mutual labels:  mqtt-client
sonoff-homie
Homie based software for Sonoff module
Stars: ✭ 25 (+25%)
Mutual labels:  homie
SuperLEDstrip
No description or website provided.
Stars: ✭ 13 (-35%)
Mutual labels:  homie

Homie Device

NPM   Build Status   release notes

This is a NodeJS port of the Homie convention for lightweight IoT device interaction on an MQTT message bus.

It is modeled after the great work done for ESP8266 devices, with the goal of not only following the Homie Convention, but at adhering to the implementation interface so both message and API interfaces are familiar.

It's great for mixing ESP8266 devices with Raspberry Pi and other linux or windows based systems on the same MQTT network.

Features

  • Device, Node, and Property with ESP8266-like interface
  • Auto MQTT connect with optional username/password
  • Auto MQTT re-connect
  • Device config matching ESP8266 config JSON
  • Periodic $stats/uptime publishing
  • $online will
  • Device topic events
  • Broadcast message events
  • Periodic stats interval events
  • Device/node/property announcement on connect
  • Property send with retained value
  • Settable properties
  • Property ranges
  • Lightweight
  • Full test coverage

Quick Start

First, get a local MQTT broker running and a window opened subscribing to the 'devices/#' topic.

Next, add these lines to an index.js file and run it:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('bare-minimum');
myDevice.setup();

Congratulations, you've got a running Homie device!

Take a look at the messages on your MQTT bus under devices/bare-minimum. Then ctrl-c the program and watch the broker administer the will.

Setting Firmware

To publish the firmware name & version, call myDevice.setFirmware():

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('bare-minimum');
myDevice.setFirmware('nodejs-test', '0.0.1');
myDevice.setup();

Adding a Node

Devices aren't much use until they have some nodes and properties. Place the following into the index.js file and run it again:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');
var myNode = myDevice.node('my-node', 'test node friendly name', 'test-node');
myNode.advertise('my-property-1').setName('Friendly Prop Name').setUnit('W').setDatatype('integer');
myDevice.setup();

Publishing a Property

Publishing properties has the same interface as the Homie ESP8266 implementation:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');
var myNode = myDevice.node('my-node', 'test node friendly name', 'test-node');
myNode.advertise('my-property-1').setName('Friendly Prop Name').setUnit('W').setDatatype('integer');
myDevice.setup();

myNode.setProperty('my-property-1').send('property-value');

Settable Properties

To set properties from MQTT messages, add a setter function when advertising the property:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');
var myNode = myDevice.node('my-node', 'test node friendly name', 'test-node');
myNode.advertise('my-property-1').setName('Friendly Prop Name').setUnit('W').setDatatype('string').settable(function(range, value) {
  myNode.setProperty('my-property-1').setRetained().send(value);
});
myDevice.setup();

Once running, publish a message to the devices/my-device/my-node/my-property-1/set topic.

Array Nodes

Array nodes are also supported by passing lower and upper bounds on the range when creating the node.

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');

var lowerBound = 0;
var upperBound = 10;
var myNode = myDevice.node('my-node', 'test node friendly name', 'test-node', lowerBound, upperBound);

Publishing a property to a specific node index can be done like this:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');
var myNode = myDevice.node('my-node', 'test node friendly name', 'test-node', 0, 10);
myNode.advertise('my-property-1');
myDevice.setup();

// Publishes 'property-value' to the 'devices/my-device/my-node_2/my-property-1' topic.
myNode.setProperty('my-property-1').setRange(2).send('property-value');

Setting a property on a specific node index can be done like this:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');
var myNode = myDevice.node('my-node', 'test node friendly name', 'test-node', 0, 10);
myNode.advertise('my-property-2').settable(function(range, value) {
  var index = range.index;
  myNode.setProperty('my-property-2').setRange(index).send(value);
});
myDevice.setup();

Now publish a message to the devices/my-device/my-node_8/my-property-2/set topic.

Device Messages

Incoming messages to the device emit message events. You can listen for all messages to the devices/my-device/# topic like this:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');

myDevice.on('message', function(topic, value) {
  console.log('A message arrived on topic: ' + topic + ' with value: ' + value);
});

myDevice.setup();

Now publish a message to the devices/my-device/my-node/my-property-2_8/set topic.

Topic Messages

You can listen for specific incoming topics by adding a listener to the message:{topic} event for the device:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');

myDevice.on('message:my/topic', function(value) {
  console.log('A message arrived on the my/topic topic with value: ' + value);
});

myDevice.setup();

Now publish a message to the devices/my-device/my/topic topic.

Broadcast Messages

You can listen to all devices/$broadcast/# messages by adding a listener to the broadcast event:

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('my-device');

myDevice.on('broadcast', function(topic, value) {
  console.log('A broadcast message arrived on topic: ' + topic + ' with value: ' + value);
});

myDevice.setup();

Now publish a broadcast message to the devices/$broadcast/some-topic topic. All homie devices are exposed to broadcast messages.

Device Settings

To configure your device with external settings, pass a full or partial config object to the HomieDevice constructor. If you've worked with the Homie ESP8266 implementation, this will be familiar:

var HomieDevice = require('homie-device');
var config = {
  "name": "Bare Minimum",
  "device_id": "bare-minimum",
  "mqtt": {
    "host": "localhost",
    "port": 1883,
    "base_topic": "devices/",
    "auth": false,
    "username": "user",
    "password": "pass"
  },
  "settings": {
    "percentage": 55
  }
}
var myDevice = new HomieDevice(config);
myDevice.setup();

Connection

The Homie device maintains an isConnected (true/false) state, and emits a connect and disconnect event as the device becomes connected with MQTT.

Quiet Setup

If you don't want the startup message, pass the quiet flag of true to setup myDevice.setup(true).

var HomieDevice = require('homie-device');
var myDevice = new HomieDevice('bare-minimum');
myDevice.setup(true);

Contributors


lorenwest

marcus-garvey

rozpuszczalny

carterzenk

License

May be freely distributed under the MIT license.

Copyright (c) 2017-2018 Loren West and other contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].