Configuration for NodeRed the weather.ini

18 views
Skip to first unread message

Almayate Bajo

unread,
Jan 28, 2024, 1:31:50 PMJan 28
to py...@googlegroups.com
Hello.
Is the weather.ini configured correctly?
--------------------------------------------------------------------
[mqtt]
topic = /arriba/meteo
hostname = localhost
port = 1883
client_id = pywws
retain = False
user =
password =
tls_cert = /home/pi/pywws/ca_cert/mqtt_ca.crt
tls_ver = 2
multi_topic = False

template_txt = ('\n'
        '#idx          \'"idx"         : "%Y-%m-%d %H:%M:%S",\'#\n'
        '#wind_dir     \'"wind_dir_degrees"    : "%.d",\' \'\' \'winddir_degrees(x)\'#\n'
        '#wind_dir     \'"wind_dir_text"       : "%s",\' \'\' \'winddir_text(x)\'#\n'
        '#wind_ave     \'"wind_ave_mps"    : "%.2f",\'#\n'
        '#wind_ave     \'"wind_ave_mph"    : "%.2f",\' \'\' \'wind_mph(x)\'#\n'
        '#wind_gust    \'"wind_gust_mps"   : "%.2f",\'#\n'
        '#wind_gust    \'"wind_gust_mph"   : "%.2f",\' \'\' \'wind_mph(x)\'#\n'
        '#hum_out      \'"hum_out"     : "%.d",\'#\n'
        '#hum_in       \'"hum_in"      : "%.d",\'#\n'
        '#temp_in      \'"temp_in_c"   : "%.1f",\'#\n'
        '#temp_in      \'"temp_in_f"   : "%.1f",\' \'\' \'temp_f(x)\'#\n'
        '#temp_out     \'"temp_out_c"  : "%.1f",\'#\n'
        '#temp_out     \'"temp_out_f"  : "%.1f",\' \'\' \'temp_f(x)\'#\n'
        '#rel_pressure \'"pressure_rel_hpa": "%.1f",\'#\n'
        '#rel_pressure \'"pressure_rel_inhg": "%.4f",\' \'\' \'pressure_inhg(x)\'#\n'
        '#abs_pressure \'"pressure_abs_hpa": "%.1f",\'#\n'
        '#abs_pressure \'"pressure_abs_inhg": "%.4f",\' \'\' \'pressure_inhg(x)\'#\n'
        '#rain         \'"rain_mm"     : "%.1f",\'#\n'
        '#rain         \'"rain_in"     : "%.2f",\' \'\' \'rain_inch(x)\'#\n'
        '#calc \'rain_hour(data)\' \'"rain_last_hour_mm": "%.1f",\'#\n'
        '#calc \'rain_inch(rain_hour(data))\' \'"rain_last_hour_in": "%.2f",\'#\n'
        '#calc \'rain_24hr(data)\' \'"rain_last_24hours_mm": "%.1f",\'#\n'
        '#calc \'rain_inch(rain_24hr(data))\' \'"rain_last_24hours_in": "%.2f",\'#\n'
        '#calc \'rain_day(data)\' \'"rain_day_mm": "%.1f",\'#\n'
        '#calc \'rain_inch(rain_day(data))\' \'"rain_day_in": "%.2f",\'#\n'
        '\n')


----------------------------------------------------------------------------------------
To send data to a NodeRed server?
Greetings

Jim Easterbrook

unread,
Jan 29, 2024, 3:25:33 AMJan 29
to py...@googlegroups.com
On 28/01/2024 18:31, Almayate Bajo wrote:
> Is the weather.ini configured correctly?
> --------------------------------------------------------------------
> [mqtt]

Hopefully one of our mqtt users will be able to help.
--
Jim Easterbrook <http://www.jim-easterbrook.me.uk/>

runge....@googlemail.com

unread,
Jan 29, 2024, 6:17:24 PMJan 29
to pywws
Hi,

i did not know that pywws can also use MQTT.
That's great news and i directly tested it.
Works perfect.

@Almayate Bajo: Your config looks good. But i do not use 
tls_cert = /home/pi/pywws/ca_cert/mqtt_ca.crt
I have this just empty like username.

@Jim:
i have all my values i normally read from the template file, but i have 3 which i do not get working with MQTT.
This are a bit exotic ones ;-) But i use them in my smarthome UI.

In my template file i have them configured as:

Tendency #pressure_trend "%s" "" "pressure_trend_text(x)"#

#hourly#
Forecast #calc "Zambretti(params, data)" "%s"#
Forecastcode #calc "ZambrettiCode(params, data)" "%s"#


I tried it in the template_txt in the weather.ini file with:
'#pressure_trend     \'"pressure_trend_text"       : "%s",\' \'\' \'pressure_trend_text(x)\'#\n'
'#calc \'Zambretti(params, data)\' \'"forecast": "%s",\'#\n'
'#calc \'ZambrettiCode(params, data)\' \'"forecast_code": "%s",\'#\n'

But this gives errors:
2024-01-29 20:50:22:pywws.template:Unknown processing directive: #pressure_trend     '"pressure_trend_text"       : "%s",' '' 'pressure_trend_text(x)'#

And for Zambretti i get even a crash.

Is it even possible to get the hourly values via MQTT?

Thanks and best regards,
Stefan

Jim Easterbrook

unread,
Jan 30, 2024, 3:04:31 AMJan 30
to py...@googlegroups.com
On 29/01/2024 23:17, 'runge....@googlemail.com' via pywws wrote:
>
> @Jim:
> i have all my values i normally read from the template file, but i have
> 3 which i do not get working with MQTT.
> This are a bit exotic ones ;-) But i use them in my smarthome UI.
>
> In my template file i have them configured as:
>
> Tendency #pressure_trend "%s" "" "pressure_trend_text(x)"#
>
> #hourly#
> Forecast #calc "Zambretti(params, data)" "%s"#
> Forecastcode #calc "ZambrettiCode(params, data)" "%s"#
>
> I tried it in the template_txt in the weather.ini file with:
> '#pressure_trend     \'"pressure_trend_text"       : "%s",\' \'\'
> \'pressure_trend_text(x)\'#\n'
> '#calc \'Zambretti(params, data)\' \'"forecast": "%s",\'#\n'
> '#calc \'ZambrettiCode(params, data)\' \'"forecast_code": "%s",\'#\n'
>
> But this gives errors:
> 2024-01-29 20:50:22:pywws.template:Unknown processing directive:
> #pressure_trend     '"pressure_trend_text"       : "%s",' ''
> 'pressure_trend_text(x)'#
>
> And for Zambretti i get even a crash.

I'm not surprised. Try writing a simple text template file first,
testing it with pywws.template as you add features. (You can test it
without stopping pywws, or changing your weather.ini.) Once you get it
working you can then copy it to your MQTT setup.
https://pywws.readthedocs.io/en/latest/api/pywws.template.html

The available functions are listed in the docs for pywws.conversions and
pywws.forecast.

> Is it even possible to get the hourly values via MQTT?

The template processing is quite powerful, but may not do everything you
want.

runge....@googlemail.com

unread,
Jan 30, 2024, 5:15:26 AMJan 30
to pywws
Hi Jim,

sure i have a template file that works.
But i struggle with 3 readings to get them from template file to the MQTT template.

I am talking about this values in the template file:
Tendency #pressure_trend "%s" "" "pressure_trend_text(x)"#
#hourly#
Forecast #calc "Zambretti(params, data)" "%s"#
Forecastcode #calc "ZambrettiCode(params, data)" "%s"#

I added them to the MQTT template as follow:
'#pressure_trend     \'"pressure_trend_text"       : "%s",\' \'\' \'pressure_trend_text(x)\'#\n'
'#calc \'Zambretti(params, data)\' \'"forecast": "%s",\'#\n'
'#calc \'ZambrettiCode(params, data)\' \'"forecast_code": "%s",\'#\n'

But this did not work.
Any ideas?

Thanks and best regards,
Stefan


Jim Easterbrook

unread,
Jan 30, 2024, 6:30:40 AMJan 30
to py...@googlegroups.com
On 30/01/2024 10:15, 'runge....@googlemail.com' via pywws wrote:
>
> I am talking about this values in the template file:
> Tendency #pressure_trend "%s" "" "pressure_trend_text(x)"#
> #hourly#
> Forecast #calc "Zambretti(params, data)" "%s"#
> Forecastcode #calc "ZambrettiCode(params, data)" "%s"#
>
> I added them to the MQTT template as follow:
> '#pressure_trend     \'"pressure_trend_text"       : "%s",\' \'\'
> \'pressure_trend_text(x)\'#\n'
> '#calc \'Zambretti(params, data)\' \'"forecast": "%s",\'#\n'
> '#calc \'ZambrettiCode(params, data)\' \'"forecast_code": "%s",\'#\n'
>
> But this did not work.
> Any ideas?

'pressure_trend' is a member of hourly data, so you need to select
hourly data before using it. Otherwise I don't know. The escaped quotes
are very hard to get right.

runge....@googlemail.com

unread,
Jan 30, 2024, 8:53:24 AMJan 30
to pywws
Ok,

perhaps i am stupid.
In the template txt i have the directive #hourly#
I did not try to add this to the MQTT template.

I will check. 
Thanks,
Stefan

runge....@googlemail.com

unread,
Jan 30, 2024, 3:10:13 PMJan 30
to pywws
Yes i was stupid ;-)
It is working now with all my values.
Very cool that i can use MQTT. 
So i will switch to MQTT instead of file reading for my SmartHome with FHEM.

I have one last question, the reading idx seems to be off by -1 hour in MQTT, 
in my normal file templating this is not the case.

So in MQTT i use:
        '#idx          \'"idx"         : "%Y-%m-%d %H:%M:%S",\'#\n'
And i get this value:
pywws_idx    2024-01-30 20:05:28  received at 2024-01-30 21:05:33
All other values are totally up to date.

In my normal file templating i do not have this.

Perhaps you have a idea.
Thanks,
Stefan

Just for everyone interested in MQTT template here my  template_txt definition:
template_txt = ('\n'
        '#idx          \'"idx"         : "%Y-%m-%d %H:%M:%S",\'#\n'
'#wind_dir     \'"wind_dir"    : "%s",\'#\n'
        '#wind_dir     \'"wind_dir_degrees"    : "%.d",\' \'\' \'winddir_degrees(x)\'#\n'
        '#wind_dir     \'"wind_dir_text"       : "%s",\' \'\' \'winddir_text(x)\'#\n'
        '#wind_ave     \'"wind_ave_mps"    : "%.2f",\'#\n'
        '#wind_ave     \'"wind_ave_kmph"    : "%.2f",\' \'\' \'wind_kmph(x)\'#\n'
'#wind_ave     \'"wind_ave_kn"    : "%.2f",\' \'\' \'wind_kn(x)\'#\n'

        '#wind_gust    \'"wind_gust_mps"   : "%.2f",\'#\n'
        '#wind_gust    \'"wind_gust_kmph"   : "%.2f",\' \'\' \'wind_kmph(x)\'#\n'
'#wind_gust    \'"wind_gust_kn"   : "%.2f",\' \'\' \'wind_kn(x)\'#\n'
        '#calc \'wind_chill(data["temp_out"],data["wind_ave"])\' \'"wind_chill_c" : "%.1f",\'#\n'
        '#calc \'dew_point(data["temp_out"],data["hum_out"])\' \'"dew_point_out_c" : "%.1f",\'#\n'
'#calc \'dew_point(data["temp_in"],data["hum_in"])\' \'"dew_point_in_c" : "%.1f",\'#\n'

        '#hum_out      \'"hum_out"     : "%.d",\'#\n'
        '#hum_in       \'"hum_in"      : "%.d",\'#\n'
        '#temp_in      \'"temp_in_c"   : "%.1f",\'#\n'
        '#temp_out     \'"temp_out_c"  : "%.1f",\'#\n'
        '#calc \'apparent_temp(data["temp_out"],data["hum_out"],data["wind_ave"])\' \'"temp_out_realfeel_c" : "%.1f",\'#\n'

        '#rel_pressure \'"pressure_rel_hpa": "%.1f",\'#\n'
        '#abs_pressure \'"pressure_abs_hpa": "%.1f",\'#\n'
        '#illuminance  \'"illuminance_lux" : "%.1f",\'#\n'
        '#illuminance  \'"illuminance_wm2" : "%.2f",\' \'\' \'illuminance_wm2(x)\'#\n'
        '#uv           \'"uv"          : "%.d",\'#\n'
'#raw#\n'

        '#rain         \'"rain_mm"     : "%.1f",\'#\n'
'#calc \'rain_hour(data)\' \'"rain_last_hour_mm": "%.1f",\'#\n'
        '#calc \'rain_24hr(data)\' \'"rain_last_24hours_mm": "%.1f",\'#\n'
        '#calc \'rain_day(data)\' \'"rain_day_mm": "%.1f",\'#\n'
'#hourly#\n'

'#calc \'Zambretti(params, data)\' \'"forecast": "%s",\'#\n'
'#calc \'ZambrettiCode(params, data)\' \'"forecast_code": "%s",\'#\n'
        '#pressure_trend     \'"pressure_tendency"       : "%s",\' \'\' \'pressure_trend_text(x)\'#\n'
        '\n')

Jim Easterbrook

unread,
Jan 30, 2024, 3:26:16 PMJan 30
to py...@googlegroups.com
On 30/01/2024 20:10, 'runge....@googlemail.com' via pywws wrote:
>
> I have one last question, the reading idx seems to be off by -1 hour in
> MQTT,
> in my normal file templating this is not the case.
>
> So in MQTT i use:
>         '#idx          \'"idx"         : "%Y-%m-%d %H:%M:%S",\'#\n'
> And i get this value:
> pywws_idx    2024-01-30 20:05:28  received at 2024-01-30 21:05:33
> All other values are totally up to date.

All pywws timestamps are in UTC. (As stated in the documentation.)
Anything else would lead to insanity. https://xkcd.com/2867/

runge....@googlemail.com

unread,
Jan 30, 2024, 5:04:56 PMJan 30
to pywws
Hmm,

that's really strange.
My templated file has the local time.

Oh ok, now i see:
My template has this directive:
#timezone local#

I will try with this setting in the MQTT template.

Thanks again!

runge....@googlemail.com

unread,
Jan 30, 2024, 5:13:30 PMJan 30
to pywws
Ok it worked! 
Now i have to change all the weather triggers in my SmartHome to the new MQTT Device.
But it is great to have MQTT instead of reading and parsing a file!

Thank you so much,.

Reply all
Reply to author
Forward
0 new messages