RuuviBridge icon indicating copy to clipboard operation
RuuviBridge copied to clipboard

Publish each measurement to a different topic

Open hax0rbana-adam opened this issue 3 years ago • 3 comments

As a consumer of temperature data, I would like to be able to obtain values without having to parse JSON strings.

I do not have any opinion about whether this should be published in addition to or in place of the JSON data.

Suggested implementation

Put this behind a config option such as "topic_mode: false" with it disabled by default for backward compatibility.

The topic could be something like:

conf.TopicPrefix+"/"+measurement.Mac+"/"+temperature

With the data being: measurement.temperature

This would then be repeated for each measurement that was obtained (humidity, barometric pressure, etc.)

Code reference

I believe the code that would need to be updated is here: https://github.com/Scrin/RuuviBridge/blob/master/data_sinks/mqtt.go#L78

Comments

I don't really know how to program in GoLang, but maybe I can just pretend it's Python and let the compiler errors light my way.

hax0rbana-adam avatar Aug 06 '23 03:08 hax0rbana-adam

Sorry for the late response. This is something that could be done, however changing the way data is published would break homeassistant compatibility with the current way it works (or add a significant amount of extra complexity to support both methods).

Instead having something like publish_raw: true under mqtt_publisher: in the config that would enable publishing raw values under conf.TopicPrefix+"/"+measurement.Mac+"/"+measurementType for each measurement type (ie. temperature, humidity, etc) in addition to the json format, in order to retain compatibility with homeassistant even when this mode is used. That way you'd have for example:

  • ruuvitag/FE:DC:BA:98:76:54 => {"temperature:"21.45,"humidity":51.23, ... }
  • ruuvitag/FE:DC:BA:98:76:54/temperature => 21.45
  • ruuvitag/FE:DC:BA:98:76:54/humidity => 51.23
  • ...

The downside of this is that you'd have some extra topics being published to even if you don't need them, but it would keep the implementation simple and more reasonable to maintain. Would this work for your use case?

Scrin avatar Sep 06 '23 17:09 Scrin

Yes, that'd work fine for me. I still intend to try implementing it myself and submitting a merge request, but I haven't gotten around to it yet.

hax0rbana-adam avatar Sep 06 '23 18:09 hax0rbana-adam

Done in #13

Scrin avatar Sep 10 '23 19:09 Scrin