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

[BUG] MQTT: Some stat tiles are updated to NaN #166

Closed
nifoc opened this issue May 22, 2023 · 6 comments
Closed

[BUG] MQTT: Some stat tiles are updated to NaN #166

nifoc opened this issue May 22, 2023 · 6 comments
Labels
bug Something isn't working MQTT
Milestone

Comments

@nifoc
Copy link
Contributor

nifoc commented May 22, 2023

Describe the bug

Skin version: 3.2.0
Weewx version: 4.10.2

Some tiles (in my case: rain, ET, lightning_strike_count) are updated to NaN when an "update" to their value arrives via MQTT/Websockets.

To Reproduce

Relevant WS messages:

weather/loop{"dateTime": "1684779296.0", "maxSolarRad_Wpm2": "59.3504593591978", "rainRate_mm_per_hour": "0.0", "hourRain_cm": "0.0", "rain24_cm": "0.0", "dayRain_cm": "0.0", "usUnits": "16.0", "UV": "0.0", "lightning_last_det_time": "1683995566.0", "lightning_strike_count_count": "0.0", "radiation_Wpm2": "16.88", "rain_mm": "0.0", "soilMoist1": "33.0", "soilMoistBatteryVoltage1_volt": "1.7", "soilTemp1_C": "19.499999999999996", "soilTempBatteryVoltage1_volt": "1.74"}

weather/loop{"dateTime": "1684779720.0", "luminosity_lux": "4357.285714285715", "outHumidity": "79.0", "outTemp_C": "20.2", "windDir": "249.35738206967002", "windGust_kph": "7.344018253445514", "windSpeed_kph": "3.770366514045687", "pressure_mbar": "1008.3560000000001", "altimeter_mbar": "1016.85204994225", "appTemp_C": "21.622675005116445", "barometer_mbar": "1016.6121751963587", "cloudbase_meter": "539.2791165127317", "dewpoint_C": "16.436451507787265", "ET_mm": "0.0018763101519641734", "heatindex_C": "20.33833333333333", "humidex_C": "25.099988125380726", "inDewpoint_C": "14.917083616123124", "maxSolarRad_Wpm2": "47.563384063712846", "rainRate_mm_per_hour": "0.0", "windchill_C": "20.2", "windrun_km": "0.1256788838015229", "hourRain_cm": "0.0", "rain24_cm": "0.0", "dayRain_cm": "0.0", "usUnits": "16.0", "UV": "0.0", "lightning_last_det_time": "1683995566.0", "lightning_strike_count_count": "0.0", "radiation_Wpm2": "34.3125", "rain_mm": "0.0", "soilMoist1": "33.0", "soilMoistBatteryVoltage1_volt": "1.7", "soilTemp1_C": "19.61111111111111", "soilTempBatteryVoltage1_volt": "1.74", "inHumidity": "67.0", "inTemp_C": "21.3", "pm10_0_microgram_per_meter_cubed": "48.455", "pm1_0_microgram_per_meter_cubed": "26.427999999999997", "pm2_5_microgram_per_meter_cubed": "38.894", "windGustDir": "251.0", "interval_minute": "2.0"}

Expected behavior

The value should (probably) be changed to 0.0.

Screenshots

Bildschirmfoto 2023-05-22 um 21 40 31

Additional context

My guess is that this is caused by the observations being 0.0 (or being 0.0 after being rounded, in the case of ET) and the stat tiles showing the aggregate (sum?) for the day.

Stat tiles that don't show the sum (radiation, luminosity) and whose value is 0.0 (during the night) are not affected.

@nifoc nifoc added the bug Something isn't working label May 22, 2023
@Daveiano
Copy link
Owner

Daveiano commented May 22, 2023

The skin looks for the value of dayObservation_unit for all sum-enabled obs (like ET, rain, windRun). So for example dayRain_cm.

There is some mismatch between the units. The stat tile shows the value as mm, but your MQTT messages contains the values in cm. Sorry, I will add this to the wiki since it's an important requirement for the live updates to work. You need to set the MQTT message to also use mm (See https://github.com/weewx/weewx/wiki/mqtt#examples for how to configure this for the weewx-mqtt extension).

Something like this should work:

[StdRESTful]
    [[MQTT]]
        ...
        [[[inputs]]]
            [[[[rain]]]]
                units = mm

Can you post the part of your skin.conf where the stat tiles are configured (especially stat_tiles_show_min, stat_tiles_show_max and stat_tiles_show_sum)?

I guess there is some more mismatch since dayET isn`t event included in the MQTT message.

EDIT: is your website anywhere publicly accessible? I need to have a look at how the skin outputs the lightning_strike tile (every tile contains some metadata to map to the correct MQTT property). If not, simply save the index.html file and attach it to the issue.

@nifoc
Copy link
Contributor Author

nifoc commented May 22, 2023

I think I have this configured correctly already.

weewx.conf:

    [[MQTT]]
        server_url = ...
        topic = weather
        unit_system = METRIC
        binding = loop, archive
        log_success = False
        [[[inputs]]]
            [[[[rainRate]]]]
                units = mm_per_hour
            [[[[rain]]]]
                units = mm
            [[[[ET]]]]
                units = mm

skin.conf:

    stat_tiles_show_min = outTemp, outHumidity, barometer, pressure, altimeter, heatindex, dewpoint, windchill, cloudbase, appTemp, rxCheckPercent, consBatteryVoltage
    stat_tiles_show_max = rainRate, UV
    stat_tiles_show_sum = rain, ET, lightning_strike_count

I will look into why dayRain_mm (etc.) are not included in the MQTT message. I guess there are some dayRain (etc.) options that [[MQTT]] expects ... somewhere.

@nifoc
Copy link
Contributor Author

nifoc commented May 22, 2023

        [[[inputs]]]
            [[[[rainRate]]]]
                units = mm_per_hour
            [[[[rain]]]]
                units = mm
            [[[[dayRain]]]]
                units = mm
            [[[[ET]]]]
                units = mm
            [[[[dayET]]]]
                units = mm

For dayRain this just works. dayET is not generated by my station (and apparently not calculated automatically by weewx, even though ET is), but thankfully this can be worked around by installing weewx-GTS.

Only lightning_strike_count remains an issue. Haven't looked for any possible solutions/workaround yet.

But as a general thought: If the stat tile value is NaN, it might be better to not update the tile at all?

@Daveiano
Copy link
Owner

Daveiano commented May 22, 2023

@nifoc Yeah I also digged around a bit.

ET isn't even published by MQTT for my station. But once I added archive as a MQTT binding besides loop (like you have in your MQTT config), it gets sent every 5 minutes. So it's just sent at the end of an archive interval. I guess this is because it's a calculated observation not actually included in the loop data.

Did not notice this yet because I just used loop as MQTT binding till now.

At first I thought the dayObservations need to be handled by weewx-mqtt itself, but I could not find the string day in the whole extension so this seems to be handled by WeeWX itself (or like you said needs to be calculated by another extension, eg weewx-GTS).

I tend to only support the live update via MQTT for "sum observations" if WeeWX provides the dayObservation, because there is too much potential for wrong data if the skin calculates this from the MQTT messages it receives (depends on the generation time of the page and when a user visits the page aka how much data the page receives since the last report run/archive interval).

So yes, the best bet would be to not update the value if the data is missing in the MQTT message.

I attached a updated live-updates.js. Would be great if you could test this out (just replace the file in your skins directory at weewx/skins/weewx-wdc/dist/live-updates.js)

live-updates.zip

@Daveiano Daveiano pinned this issue May 23, 2023
@nifoc
Copy link
Contributor Author

nifoc commented May 23, 2023

I attached a updated live-updates.js. Would be great if you could test this out (just replace the file in your skins directory at weewx/skins/weewx-wdc/dist/live-updates.js)

Sorry, only had time to do a quick test now.

The patched file works like a charm - thank you!

@Daveiano
Copy link
Owner

I committed the change. It will be included in the next release, thank you for spotting this one!

@Daveiano Daveiano added this to the 3.3.0 milestone May 24, 2023
@Daveiano Daveiano added the MQTT label Jun 10, 2023
@Daveiano Daveiano unpinned this issue Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working MQTT
Projects
None yet
Development

No branches or pull requests

2 participants