Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting MQTT messages #51

Open
jrocketfingers opened this issue Dec 13, 2022 · 9 comments
Open

Documenting MQTT messages #51

jrocketfingers opened this issue Dec 13, 2022 · 9 comments

Comments

@jrocketfingers
Copy link

Hi folks, I'm running a Klimerko-like setup (same sensors, same NodeMCU, but possibly ESP32 instead), with ESPHome firmware. If I understand Klimerko's code correctly, it's just sending MQTT messages to api.allthingstalk.io, and klimerko.org is picking up Klimerko devices from there? If this is the case, I could contribute sensor data as well if I knew the messages being sent.

I should be able to deduce MQTT messages from the codebase, but are there any intentions to document this? If not, I'd be glad to document them if I manage to make it work. In that case, could you direct me on how/where would you want it documented?

@jrocketfingers
Copy link
Author

Just read this off a Klimerko unit UART logs, pasting it here for future reference:

{"air-quality":{"value":"Good"},"pm1":{"value":16},"pm2-5":{"value":22},"pm10":{"value":24},"temperature":{"value":19.59},"humidity":{"value":26.51},"pressure":{"value":1003.7},"firmware":{"value":"2.0.0"},"wifi-signal":{"value":"Good"}}

@epiller
Copy link
Member

epiller commented Dec 20, 2022

Hey @jrocketfingers, Klimerko follows the AllThingsTalk MQTT topic/payload convention documented here.

@jrocketfingers
Copy link
Author

Hey @epiller, thanks! I've seen that doc, but it seems to explain the per-asset messages, not the bulk transfer that Klimerko seems to be making. I assume you've actually used these device states documented on the data formats page?

@epiller
Copy link
Member

epiller commented Dec 28, 2022

@jrocketfingers Yup! That's exactly what's being used.

@dkwireless
Copy link

Can you please share config yaml so we dont have to do it all ove again? :)

@jrocketfingers
Copy link
Author

Sadly I never got it fully operating, hence why I never closed this ticket. I might be misremembering, but the format itself was ok, I think I've failed somewhere else.

I have a mangled mess of a config, but the relevant part should be:

I'll hide it here so people skimming the thread don't copy paste, and then lose hours of their life for no good reason.

mqtt:
  id: att
  broker: "api.allthingstalk.io"
  client_id: "KLIMERKO"
  username: "maker:<maker ID>"
  password: "arbitrary"
  keepalive: 30s
  port: 1883

interval:
  - interval: 1min
    then:
      - logger.log: "Interval triggered"
      - mqtt.publish_json:
          topic: "device/<device ID>/state"
          payload: |-
            root["pm1"]["value"] = id(pm_1_0).state;
            root["pm2-5"]["value"] = id(pm_2_5).state;
            root["pm10"]["value"] = id(pm_10_0).state;
            root["temperature"]["value"] = 0;
            root["humidity"]["value"] = 0;
            root["pressure"]["value"] = 0;
            root["firmware"]["value"] = "2.1.0";

sensor:
  - platform: pmsx003
    type: PMSX003
    id: pmsensor
    pm_1_0:
      name: "Particulate Matter <1.0µm Concentration"
      id: "pm_1_0"
      on_value:
        - mqtt.publish_json:
            topic: "device/<device_id>/asset/pm1/state"
            payload: |-
              root["value"] = id(pm_1_0).state;

You'll have to tweak the sensors to fit your naming as well as add the temperature/humidity/pressure sensor, as I didn't have it at the time. All blocks are top level, indentation should be correct.

⚠️ I'm providing it as-is, it's been quite a while since I've worked on it, and I'm pretty sure this version is just a kitchen sink rather than a solution.

Let me know of any tweaks you make to it :)

@dkwireless
Copy link

No problem. Thanks. I'm still waiting on parts. Just ordered them. But will write here if I manage to build something.

@dkwireless
Copy link

Sucess!
Thanks @jrocketfingers for pointing me in right direction.

You can find code on https://github.com/dkwireless/ESPHOME-Klimerko

@jrocketfingers
Copy link
Author

Happy to have helped, thanks for pushing it across the finish line 🎉 I'll play around with it when I get the chance, in order to make a PR to add MQTT message shape to the docs. That being said I've no idea when it'll happen, so feel free to take it over if you have the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants