Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

micampe/arduino-homebridge-mqtt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino Homebridge MQTT

Build Status

Arduino library for connecting to Homebridge.

Dependancies:

Installation Guide

Usage

// Switch example
#include <Arduino.h>
#include <WiFiManager.h> // You can you anything else to connect to WiFi.
#include <ArduinoHomebridgeMqtt.h>        

const IPAddress MQTT_SERVER = IPAddress(192, 168, 1, 48); // Put your MQTT server IP address here.
const int OUTPUT_PIN = D1;
const char* NAME = "flex_lamp"; // Accessory name must be unique
const char* SERVICE_NAME = "Light"; // Service name. 
const char* SERVICE = "Switch"; // Service as defined in Homebridge

WiFiManager wifiManager;
ArduinoHomebridgeMqtt arduinoHomebridgeMqtt;

// This function gets called when there is a message from homebridge eg. when value(s) is set via Home app.
void callback(const char* name, const char* serviceName, const char* characteristic, int value) {
  if (strcmp(name, NAME) == 0) { // Check to see if the message is for this accessory.
    if (strcmp(serviceName, SERVICE_NAME) == 0) { // Check if the message is to set the value for service "Light".
      digitalWrite(OUTPUT_PIN, value);
    }
  }
}

void setup() {
  Serial.begin(9600);
  pinMode(OUTPUT_PIN, OUTPUT);
  wifiManager.autoConnect();
  arduinoHomebridgeMqtt.onSetValueFromHomebridge(callback);
  arduinoHomebridgeMqtt.connect(MQTT_SERVER);
  arduinoHomebridgeMqtt.addAccessory(NAME, SERVICE_NAME, SERVICE); // If running the first time, you need to add the accessory first.
  arduinoHomebridgeMqtt.getAccessory(NAME); // Get accessory states
}

void loop() {
  arduinoHomebridgeMqtt.loop();
}

About

Arduino library for connecting to Homebridge

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%