Coder Social home page Coder Social logo

Comments (3)

plapointe6 avatar plapointe6 commented on June 22, 2024 1

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?

  1. HaMqttConfigBuilder is lighter and more flexible.
  2. 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.

plapointe6 avatar plapointe6 commented on June 22, 2024

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.

lanrat avatar lanrat commented on June 22, 2024

Oh, cool!

What the main difference between HAMqttDevice and the new HaMqttConfigBuilder?

from hamqttdevice.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.