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

Simultaneously support different MQTT payload formats (regular, as well as JSON) #224

Closed
kbahey opened this issue Dec 20, 2024 · 9 comments
Assignees

Comments

@kbahey
Copy link

kbahey commented Dec 20, 2024

I have been using MQTTSubscribe for a few years, so many thanks for a valuable component that enables Weewx to work with any weather sensor.

There is a limitation that the message type must apply to all sensors, like so:

[[message_callback]]
  type = json

That worked well when my outdoor and indoor sensors were both JSON.
My outdoor station is Acurite, and it feeds JSON data Home Assistant.

home/climate/1111-56 
{
"time":"2024-12-20 10:12:00",
"model":"Acurite-5n1",
...
"wind_avg_km_h":5.139,
"temperature_C":-3.77778,
"humidity":96, ...
}

My indoor sensor was a custom one based on a BME280 connected to an ES32.

Then, I replaced the indoor sensor with an AirThings Wave Plus and its MQTT format is like this:

airthings/60:98:66:xx:xx:xx/temperature '21.4'
airthings/60:98:66:xx:xx:xx/humidity '41'

Now it is impossible to feed indoor data to MQTTSubscribe, because the message type is defined globally, and applies to all topics/sensors.

Is it possible to define the message type per topic, or per sensor?

@bellrichm
Copy link
Owner

As of release 2.1, there is a construct.

[[topics]]
    [[[topic-name]]]
        [[[[message]]]]
            type = json | keyword | topic

For more information see, https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Common-Options#the-message-sections

@kbahey
Copy link
Author

kbahey commented Dec 20, 2024

Thanks a lot.
This means that I can finally get back indoor data into Weewx.

A couple of questions:

a) Is "individual" supported as a type, or only "keyword", "topic" and "json"?

b) The examples here imply a different hierarchy than what is in your reply.

With only 3 square brackets for message, then a list of topics for that type.

Like this:

    [[topics]]
        [[[message]]]
            type = individual
        [[[airthings/60:98:66:xx:xx:xx/temperature]]]
            name = InTemp
            conversion_type = float
            units = degree_C

        [[[message]]]
            type = json
        [[[home/climate/1111-56]]]
            [[[[temperature_C]]]]
                name = outTemp
                conversion_type = float
                units = degree_C

Can you please clarify?

@kbahey
Copy link
Author

kbahey commented Dec 20, 2024

I got the json topics working, because it is obvious what their fields are.

Like this:

    [[topics]]
        unit_system = metric

        [[[home/climate/1111-56]]]
            [[[[message]]]]
                type = json

            [[[[temperature_C]]]]
                name = outTemp
                ignore = False
                contains_total = False
                conversion_type = float
                units = degree_C

            [[[[humidity]]]]
                name = outHumidity
                conversion_type = int

            [[[[time]]]]
                ignore = True
            [[[[model]]]]
                ignore = True

        [[[home/climate/1111-49]]]
            [[[[message]]]]
                type = json

            [[[[wind_avg_km_h]]]]
                name = windSpeed
                conversion_type = float
                units = km_per_hour

            [[[[wind_dir_deg]]]]
                name = windDir
                conversion_type = int

            [[[[rain_mm]]]]
                name = rain
                conversion_type = float
                contains_total = True
                units = mm

            [[[[time]]]]
                ignore = True
            [[[[model]]]]
                ignore = True

All the above works as intended, with data flowing through from the weather station through MQTT to Weewx.

But for the other MQTT format (type = individual), I can't figure out what the field name should be?

I have it currently like this, with no field name, because individual does not have a field name like json.

        [[[airthings/60:98:66:xx:xx:xx/temperature]]]
            [[[[message]]]]
                type = individual
                name = inTemp
                conversion_type = float
                units = degree_C

And no data comes through for the inTemp.

How should I proceed with this?

@bellrichm
Copy link
Owner

bellrichm commented Dec 20, 2024

Yeah, topic was a typo.
That looks correct. At this point, set debug = 1 and attach the log. It should show the data coming in and how MQTTSubscribe is processing it.

@bellrichm
Copy link
Owner

Oh I think I see it. Try this. It might work. I might have to do some experimenting.

        [[[airthings/60:98:66:xx:xx:xx/temperature]]]
                name = inTemp
                conversion_type = float
                units = degree_C
            [[[[message]]]]
                type = individual

@kbahey
Copy link
Author

kbahey commented Dec 20, 2024

That worked!

Thank you so much.

It is best if the the above config snippets go into the Wiki.

@bellrichm
Copy link
Owner

Good to hear.
Maybe updating https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/individual-example to move the message section would help. The challenge is there are so many configuration possibilities….
I’m still trying to get v3 out the door, after that I might have time to revisit the wiki/documentation.

@kbahey
Copy link
Author

kbahey commented Dec 21, 2024

Another suggestion:

In the documentation, mention that this global configuration part is no longer recommended (i.e. will still work, but should be replaced by the topic message syntax):

    [[message_callback]]
        type = json

Then in all the examples, add the following syntax for each topic.

    [[[[message]]]]
        type = json

Or

    [[[[message]]]]
        type = individual

That should work for all the new configurations, while those who use the older global type syntax will be unaffected.

@bellrichm
Copy link
Owner

In the reference documentation, https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Common-Options, there is no mention of message_callback. In the log, there is a warning that is deprecated.
In, https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/Common-Options, the [[[topic-name]]] [[[[message]]]] had a todo. I removed that, and added some documenation.
The json example still needs to be updated to remove message_callback.
Next will be to add an example with different ‘topic types’ (message under the the topic-name)
I think that should do it.

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

2 participants