$unit tag formatting

70 views
Skip to first unread message

František Slimařík

unread,
Nov 29, 2021, 11:46:49 AM11/29/21
to weewx-user
Hello,

I have question regarding tag $unit. When I have for example tag $unit.label.rain it will show me " mm". Is there any way how to show different type of unit in case I want to show snow in my highchart graph and use this tag option? Like $unit.label.rain.cm?

Thanks for answer.

Tom Keffer

unread,
Nov 29, 2021, 7:20:02 PM11/29/21
to weewx-user
Not understanding your question. The $unit tag is designed to retrieve the reporting unit being used by an observation type. Why would you want to retrieve something different?

If you want the value of a type in a different unit, you can do something like:


This will give the rain since midnight in cm. Is this what you are looking for?

-tk


--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/6ef88b26-06fb-464f-bee1-0968a91234a4n%40googlegroups.com.

gjr80

unread,
Nov 29, 2021, 7:57:49 PM11/29/21
to weewx-user
I think, reading between the lines, the issue may be that the OP wants to include something like snow in a WeeWX generated data file to be used by Highcharts, but using cm instead of mm as (seemingly) used for rain. I would expect that instead of passing something like '23 cm' in a single field Highcharts would want the value 23 in one field and 'cm' in another. The former can be obtained (for example) via $day.snow.cm.raw or $day.snow.cm.format(add_label=False) but there is no tag to get the unit label for 'cm' when your default unit for group_rain is mm. The only solution I can think of short of digging into the WeeWX internals is some in-line python code that parses the result of $day.snow.cm. Or hardcoding cm, but that is rather limiting.

Gary

Tom Keffer

unread,
Nov 29, 2021, 8:12:06 PM11/29/21
to weewx-user
That makes sense, but then why not just use $unit.label.snow?

gjr80

unread,
Nov 29, 2021, 8:34:52 PM11/29/21
to weewx-user
Because the unit group being applied to snow, group_rain, is set to ‘mm’ (presumably so that rain appears in the correct/preferred default units) so $unit.label.snow will result in ‘mm’.

Gary

František Slimařík

unread,
Nov 29, 2021, 9:02:37 PM11/29/21
to weewx...@googlegroups.com
Hi Gary,

You got my point and you are also right that “hardcoding” will be probably the best option. Since I am not using default unit I would have to anyway format string and take it out with split() for example but it’s not worth of it. 

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/-cuLPU-mSxM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/94d6c41a-0657-4eca-a5a8-c34d4c9512e7n%40googlegroups.com.

Tom Keffer

unread,
Nov 30, 2021, 7:03:44 AM11/30/21
to weewx-user
Yes, but then snow should be measured in mm.

I can see an issue if you change units. That is, if you're doing something like $day.snow.sum.cm, then you want the appropriate unit label. 


gjr80

unread,
Nov 30, 2021, 2:05:04 PM11/30/21
to weewx-user
That is exactly the issue; the OP wishes to generate a file that includes rain in mm and snow in cm with separate tags for each data value and corresponding unit. Presently I don’t believe that can be done with the existing tag system.

Gary

Reply all
Reply to author
Forward
0 new messages