LVAR variable to turn liveweather ON / OFF

Hello, it would be very helpful to have a LVAR variable to be able to turn
live weather on or off. I would love to assign a physical switch (home cockpit
user) to turn live weather on or off (without using the screen

Thanks Okan Sacli

Yeah at the very least I would like to know if its on or off.

Rob Murdoch
PMDG

We’re really not setting the bar very high here… I’d like an API where I can retrieve the current loaded weather data plus a ā€˜live weather’ flag. The parameters for the weather are pretty basic (wind layers, cloud layers, temp/pressure) so reading that in a single query should be relatively simple.

Knowing whether live weather is on or off would be very useful for avionics developers, as then we can know whether to apply cold weather altimetry corrections based on temperature as some real systems do, or not. Applying corrections with offline weather would be counter-productive, as it does not seem to actually alter the lapse rate with temperature.

const wx_listener = RegisterViewListener("JS_LISTENER_WEATHER", () => {});

wx_listener.on('UpdatePreset', (weather) => {
	const is_live = weather.index == 0;
	console.log(weather, is_live);
	// You're welcome!
});

wx_listener.on('SetWeatherList', (weather_presets) => {
	// If you want the list of wx presets.
	console.log(weather_presets);
});
wx_listener.trigger('ASK_WEATHER_LIST');

To note…

  1. You have to unregister (wx_listener.unregister()) and re-register the ViewListener if you want to get fresh data periodically. The sim doesn’t trigger UpdatePreset when the preset changes despite what the event name infers.
  2. The weather data provided in the live ā€œpresetā€ is total BS and cannot be relied on. Getting nearest METAR station data is possible but the code to get it is ridiculously overcomplicated. I can get in the weeds if someone really needs it.
  3. Search for html_ui/js/services/weather.js to get the full list of capabilities. It’s what the weather panel uses to control weather settings. Yes you can also inject custom weather that way :wink:
  4. This works on avionics and in-game panels. If you need this to run in the sim’s toolbar, please refer to this project: GitHub - parallel42/msfs-toolbar-interop

To set weather to live:

wx_listener.trigger('CUSTOM_WEATHER_PRESET_CHANGED', 0); // Use the ID of the desired preset. 0 = Live

Keven Menard
//42

4 Likes

Keven this is awesome - massively appreciated. I looked at weather.js as soon as I discovered it but on my own I totally failed to get it to give me the ā€˜current preset info’. Your code worked straight out of the box.

For multiplayer gliding in MSFS the ability to signature the loaded weather is really quite important, so thanks again.

1 Like

Hi Keven !
I really don’t know anything about code, but, although I have live weather on, the Sun desperately shines everywhere ! (I’m playing on PC) Could your code line help me ? But what should I do with it ?
Thanx for your help !

It looks to me like this might no longer be working.

Previously that UpdatePreset would fire ONCE given this code in the gauge so that would give you the ā€˜weather’ layers data in the callback. As previously reported the callaback otherwise was not called if the preset changed, so it required polling of the RegisterViewListener(ā€œJS_LISTENER_WEATHERā€,…) to keep on top of what weather was currently loaded, but the limited functionality still meant the Wx preset data could be read.

As far as I can tell the callback is now NEVER being called & I can’t see any other way of getting the data from the currently loaded WPR preset file.

Anyone have any clues? It could be just me but certainly my prior ā€˜working’ code is non-functional and I can’t get the clean example from @runshotgun to work in the Coherent Console as before.

In 2020 you only (and automatically) got the data right after registering the listener, in 2024 you have to ask for that data manually.

The cool thing about this change is you can get refreshed data for the current preset whenever you need!

askUpdatePreset()
{
    this.trigger("ASK_UPDATE_PRESET");
}

With the code sample, it would be wx_listener.trigger("ASK_UPDATE_PRESET");

I remain in awe of your investigative skills…

if you can help a man learn to fish, how did you find that ā€œASK_UPDATE_PRESETā€ trigger value? I looked through fs-base-ui .. Weather.js and the sdk docs JS_LISTENER_WEATHER with the idea something like that might be needed (I found ā€œADD_WEATHER_PRESETā€, close but no cigar).

many thanks

edit - before I go off to check it, do you know if the same ā€˜ASK’ method works in 2020 & 2024 ? thanks again.

1 Like

The ASK_UPDATE_PRESET is used in lib.bundle.js in the WeatherListener class.

1 Like

There are multiple ways to go about finding those… some require custom tools; some just require patience. In this case we already have something to work with (the 2020 code) so it was a matter of searching for known code in the default Weather Panel of the new sim and looking around it for new functions.

1 Like

It does not. The only way is to Unregister and Re-register the listener to get it again.

1 Like

thanks very much indeed - these prompt answers really help a lot. (Small addendum in case it helps anyone: maybe 2024 fs-base-ui .. Weather.js is no longer used as that code doesn’t match the same WeatherListener class bundled inside fs-base-ui/html_ui/Global/lib.bundle.js)