Formatting Options for Unit Group group_deltatime

123 views
Skip to first unread message

Karen K

unread,
Nov 5, 2022, 12:00:09 PM11/5/22
to weewx-user
Is there a way to format a value of group_deltatime in decimal hours instead of hours, minutes, and seconds?

Something like
daylight: 9.5 hours
instead of
daylight: 9 hours, 30 minutes, and 0 seconds

Tom Keffer

unread,
Nov 5, 2022, 12:32:47 PM11/5/22
to weewx...@googlegroups.com
I can't think of any way to do that using a simple format string. You'll have to do something like:

#set hours_up = $almanac.sun.visible.raw / 3600.0
<p>Sun up:  $("%.2f" % $hours_up)</p>



--
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/15b424e4-e698-4603-b247-95a0326dc195n%40googlegroups.com.

Karen K

unread,
Nov 5, 2022, 12:47:18 PM11/5/22
to weewx-user
Thank you.



Karen K

unread,
Nov 5, 2022, 1:24:45 PM11/5/22
to weewx-user
I sent a little PR. May you look at it?

Karen K schrieb am Samstag, 5. November 2022 um 17:47:18 UTC+1:
Thank you.



Message has been deleted

cric...@pobox.com

unread,
Jul 21, 2025, 10:08:04 PM7/21/25
to weewx-user
I'm working on adding another observation to my solar monitor and I want the same thing Karen
is asking.  I didn't understand where the example code would go
>> I can't think of any way to do that using a simple format string. You'll have to do something like:
>>  #set hours_up = $almanac.sun.visible.raw / 3600.0
>>  <p>Sun up:  $("%.2f" % $hours_up)</p>"

I tried this is current.inc (SKIN_VERSION = 4.10.2):
    #elif $x == 'last_runtime'
      #set hours_on = $day.last_runtime.raw / 3600.0
      <tr>
        <td class="label">$obs.label[$x]</td>
        <td class="data"><p>$("%.1f" % $hours_on)</p></td>
      </tr>
and it failed miserably.
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: Evaluation of template /home/crichmon/weewx/skins/Seasons/index.html.tmpl failed with exception '<class 'TypeError'>'
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: **** Ignoring template /home/crichmon/weewx/skins/Seasons/index.html.tmpl
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: **** Reason: unsupported operand type(s) for /: 'AggTypeBinder' and 'float'
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****    File "/home/crichmon/weewx/bin/weewx/cheetahgenerator.py", line 348, in generate
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****      unicode_string = compiled_template.respond()
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****    File "_home_crichmon_weewx_skins_Seasons_index_html_tmpl.py", line 226, in respond
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3/dist-packages/Cheetah/Template.py", line 1708, in _handleCheetahInclude
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****      self._CHEETAH__cheetahIncludes[_includeID].respond(trans)
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****    File "cheetah__home_crichmon_weewx_skins_Seasons_current_inc_1753124642_9362485_61563.py", line 251, in respond
Jul 21 13:04:02 router1 weewx[21556] ERROR weewx.cheetahgenerator: ****  TypeError: unsupported operand type(s) for /: 'AggTypeBinder' and 'float'

What am I missing?  The value is in seconds and coming in via mqtt.

Thx, Chris

cric...@pobox.com

unread,
Jul 27, 2025, 6:33:17 PM7/27/25
to weewx-user
So, after a bunch of trial-and-error and remembering various clues from other questions over time, I was able to solve this problem
in weewx/skins/Seasons/current.inc
    #elif $x == 'last_runtime'
      <tr>
        #set hours_on = $rnd(($current.last_runtime.raw / 3600.0), 1)

        <td class="label">$obs.label[$x]</td>
        <td class="data">$hours_on hrs</td>
      </tr>
solves the "I want seconds converted to hours to one decimal."
Reply all
Reply to author
Forward
0 new messages