plapointe6 / hamqttdevice Goto Github PK
View Code? Open in Web Editor NEWA library that provides tools to simplify MQTT discovery implementation for Home Assistant to your device.
License: GNU General Public License v3.0
A library that provides tools to simplify MQTT discovery implementation for Home Assistant to your device.
License: GNU General Public License v3.0
I'm getting an error compiling the library for an Arduino Mega 2560.
Arduino\libraries\HAMqttDevice\src/HAMqttDevice.h:24:10: error: 'vector' in namespace 'std' does not name a template type
std::vector _configVars;
^~~~~~
Arduino\libraries\HAMqttDevice\src/HAMqttDevice.h:31:10: error: 'vector' in namespace 'std' does not name a template type
std::vector _attributes;
^~~~~~
As per the Home Assistant MQTT Discovery Documentation, it is possible to define a single sensor that can define multiple values in a single payload (with multiple configs needed) by defineing a value_template
for each that use the same state_topic
.
As far as I can tell, this is not possible with this library. Is that correct? Would it be much work to add support for this?
https://www.home-assistant.io/docs/mqtt/discovery/#sensors-with-multiple-values
When attempting to declare both a SWITCH and BINARY SENSOR in the same arduino sketch I noticed some strange behaviour - for the second device declared, the status topic (stat_t) was omitted from the config payload which appears to be causing homeassistant to fail to import the sensor. i.e. in the example below, garagedoorZSC wouldn't include stat_t even if I manually included garagedoorZSC.enableStateTopic();. If I reversed the following two lines, 'garagedoorZSC' would now include stat_t but 'garagedoor' would not.
HAMqttDevice garagedoor("11HS002 GD DEV", HAMqttDevice::SWITCH, "homeassistant");
HAMqttDevice garagedoorZSC("11ZSC002 DEV", HAMqttDevice::BINARY_SENSOR, "homeassistant");
Arduino code and outputs from serial for the two different cases:
HAMqttDevice garagedoor("11HS002 GD DEV", HAMqttDevice::SWITCH, "homeassistant");
HAMqttDevice garagedoorZSC("11ZSC002 DEV", HAMqttDevice::BINARY_SENSOR, "homeassistant");
<timestamp etc cutoff in serial monitor>Config topic : homeassistant/switch/11hs002_gd_dev/config
22:48:39.071 -> Config payload : {"~":"homeassistant/switch/11hs002_gd_dev","name":"11HS002 GD DEV","cmd_t":"~/cmd","stat_t":"~/state"}
22:48:39.106 -> Config topic : homeassistant/binary_sensor/11zsc002_dev/config
22:48:39.106 -> Config payload : {"~":"homeassistant/binary_sensor/11zsc002_dev","name":"11ZSC002 DEV"}
// Home Assitant device creation for MQTT discovery
HAMqttDevice garagedoorZSC("11ZSC002 DEV", HAMqttDevice::BINARY_SENSOR, "homeassistant");
HAMqttDevice garagedoor("11HS002 GD DEV", HAMqttDevice::SWITCH, "homeassistant");
<timestamp etc cutoff in serial monitor>Config topic : homeassistant/switch/11hs002_gd_dev/config
22:49:29.900 -> Config payload : {"~":"homeassistant/switch/11hs002_gd_dev","name":"11HS002 GD DEV","cmd_t":"~/cmd"}
22:49:29.900 -> Config topic : homeassistant/binary_sensor/11zsc002_dev/config
22:49:29.900 -> Config payload : {"~":"homeassistant/binary_sensor/11zsc002_dev","name":"11ZSC002 DEV","stat_t":"~/state"}
thanks, Dave
I'm using for the first time your library to simplify the management of the MQTT Discovery used by HA.
I have downloaded your "onoff_light" sample and loaded on my NodeMCU (with my settings for the ssid, password & c.)
I'm using Mosquitto broker Add on directly in HA, I have set the discovery_prefix to "/homeassistant" (I think the default of Home Assistant when it's not changed).
HAMqttDevice light("My Nice Lamp", HAMqttDevice::LIGHT, "/homeassistant");
I have also enabled the Serial to show some messages in the serial console:
client.enableDebuggingMessages();
The connection seems working in the correct way:
17:56:32.771 -> MQTT: Connecting to broker "192.168.1.15" with client name "my_sensor" ... (7.259000s) - ok. (7.366000s)
17:56:32.913 -> MQTT: Subscribed to [/homeassistant/light/my_nice_lamp/cmd]
17:56:32.913 -> MQTT: Subscribed to [/homeassistant/status]
17:56:33.056 -> MQTT >> [/homeassistant/status] online
17:56:33.056 -> MQTT << [/homeassistant/light/my_nice_lamp/config] {"~":"/homeassistant/light/my_nice_lamp","name":"My Nice Lamp","cmd_t":"~/cmd","stat_t":"~/state","json_attr_t":"~/attr"}
17:56:38.065 -> MQTT << [/homeassistant/light/my_nice_lamp/state] OFF
17:56:38.065 -> MQTT << [/homeassistant/light/my_nice_lamp/attr] {"IP":"192.168.1.153"}
But I'm not able to see the my Device in the integration page (under MQTT, but I'm not sure if the lib works in this way).
I'm also not able to see my entity under the states page of "Developer tools" (I have searched the name 'my_nice_lamp').
The others devices that are using the MQTT are available under the MQTT integration (I have only Shelly devices actually), I think that the Mosquitto broker are configured correctly.
Have you additional test to suggest?
Thanks
Your library is a good start. But why do you stop at the configuration only?
You could pass an MQTT client to the class and handle the messages and events too! eg. setAttribute(name,value), send(), etc.
Are you planning on this?
-Raomin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.