jim-easterbrook / pywws

Python software for USB Wireless WeatherStations
https://pywws.readthedocs.io/
GNU General Public License v2.0
204 stars 62 forks source link

Unable to get Wind Chill in MQTT #84

Closed GeekyTim closed 5 years ago

GeekyTim commented 5 years ago

I've tried formatting the wind_chill in the MQTT template, but for the life of me I cannot get it to work. I get:

File "", line 12 Jun 01 19:44:34 PiWeather pywws-livelog[1570]: '#calc \'wind_chill(data('temp_out'], data['wind_ave'])\' \'"chill": "%.0f",\' \'\' \'scale(x, 10.0)\'#\n'

Do you have any idea what is happening here?

jim-easterbrook commented 5 years ago

The template parser can't parse that expression, probably because you're using single quotes ' for both the element names (e.g. 'temp_out') and the "words" that make up the #calc# expression, (e.g. 'wind_chill(data('temp_out'], data['wind_ave'])').

GeekyTim commented 5 years ago

I have it outputting some data now. Not sure how accurate it is at the moment, but I think I have got it now.

vlczak commented 5 years ago

@GeekyTim I noticed you had data('temp_out'] instead of data['temp_out'] Could you post here your final working template for others?

Thanks

jim-easterbrook commented 5 years ago

That's a mistake I hadn't spotted. Should definitely be square brackets.

GeekyTim commented 5 years ago

Here is the line:

'#calc \'wind_chill(data["temp_out"], data["wind_ave"])\' \'"chill": "%.1f", \' #\n'

And it works!

jim-easterbrook commented 5 years ago

I prefer to use double quotes for the #calc delimiters and single quotes for the dict keys, which is the style I've been consistent in using in pywws.

#calc "wind_chill(data['temp_out'],data['wind_ave'])" "'chill':'%.1f',"#