I’m trying to integrate huskylens with home assistant but it’s showing the following error
This is my code running in wemos
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include "HUSKYLENS.h"
// WiFi settings
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// MQTT settings
const char* mqtt_server = "your_MQTT_SERVER";
const char* mqtt_topic = "your_MQTT_TOPIC";
const int mqtt_port = 1883;
WiFiClient espClient;
PubSubClient client(espClient);
HUSKYLENS huskylens;
void setup() {
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Connect to MQTT server
client.setServer(mqtt_server, mqtt_port);
while (!client.connected()) {
if (client.connect("ESP8266Client")) {
// Subscribe to MQTT topic
client.subscribe(mqtt_topic);
} else {
delay(5000);
}
}
// Initialize HuskyLens
Wire.begin(D2, D1);
huskylens.begin(Wire);
}
void loop() {
// Check if HuskyLens is ready
if (huskylens.isLearned()) {
// Get data from HuskyLens
HUSKYLENSResult result = huskylens.request();
if (result.command == COMMAND_RETURN_BLOCK) {
// Send data to MQTT server
String payload = String(result.xCenter) + "," + String(result.yCenter);
client.publish(mqtt_topic, payload.c_str());
}
}
}
This is the yaml code in configuration.yaml
sensor:
- platform: mqtt
state_topic: "homeassistant/sensor/huskylens"
name: "HuskyLens"
value_template: "{{ value_json.x }},{{ value_json.y }}"
unit_of_measurement: "px"
Any idea how to make it work?