Comments (3)
HaMqttConfigBuilder is simple and tiny. It is a tool to generate key/value pairs into a JSON string.
HAMqttDevice does more things on its own under the hood like setting the state topic and generating some key/value entries into the config automatically.
So, why replace HAMqttDevice with HaMqttConfigBuilder if HAMqttDevice does, in fact, more things?
- HaMqttConfigBuilder is lighter and more flexible.
- While HAMqttDevice does things in the background, it was not always clear which thing it does and when. Doing this the new way will put all config key/value pairs for your device into the main sketch at the same place. Noting is done in the background.
I will update my IoT devices soon and I will put more examples into HaMqttConfigBuilder.
from hamqttdevice.
You may be able to do this with plapointe6/HaMqttConfigBuilder
Here how:
// Publish this to: homeassistant/sensor/sensorBedroomT/config
String generateConfigPayload1() {
return HaMqttConfigBuilder()
.add("device_class", "temperature")
.add("name", "Temperature")
.add("state_topic", "homeassistant/sensor/sensorBedroom/state")
.add("unit_of_measurement", "°C")
.add("value_template", "{{ value_json.temperature}}")
.generatePayload();
}
// Publish this to: homeassistant/sensor/sensorBedroomH/config
String generateConfigPayload2() {
return HaMqttConfigBuilder()
.add("device_class", "humidity")
.add("name", "Humidity")
.add("state_topic", "homeassistant/sensor/sensorBedroom/state")
.add("unit_of_measurement", "%")
.add("value_template", "{{ value_json.humidity}}")
.generatePayload();
}
// To generate { "temperature": 23.20, "humidity": 43.70 }
String generateValuesPayload(const double temperature, const double humidity) {
return HaMqttConfigBuilder()
.add("temperature", temperature)
.add("humidity", humidity)
.generatePayload();
}
I will replace HAMqttDevice by the new lib HaMqttConfigBuilder soon in my other projects.
from hamqttdevice.
Oh, cool!
What the main difference between HAMqttDevice and the new HaMqttConfigBuilder?
from hamqttdevice.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hamqttdevice.