How do I convert battery strength back to a string?

49 views
Skip to first unread message

Ken Booth

unread,
May 6, 2019, 7:16:22 PM5/6/19
to weewx-user
When the Acurite SmartHub sends raw data to weewx, the battery status is reported as "normal" or "low" and this is converted to 0 or 1 respectively.

weewx[24667]: interceptor: MainThread: raw data: dateutc=now&action=updateraw&realtime=1&id=24C86E090EC1&mt=tower&sensor=00004036&humidity=34&tempf=76.4&baromin=30.31&battery=normal&rssi=4
weewx[24667]: interceptor: MainThread: raw packet: {'bridge_id.00004036.24C86E090EC1': '24C86E090EC1', 'sensor_type.00004036.24C86E090EC1': 'tower', 'battery.00004036.24C86E090EC1': 0,
...
weewx[24667]: interceptor: MainThread: raw data: dateutc=now&action=updateraw&realtime=1&id=24C86E090A48&mt=tower&sensor=00005422&humidity=34&tempf=71.4&baromin=29.83&battery=low&rssi=3
weewx[24667]: interceptor: MainThread: raw packet: {'rssi.00005422.24C86E090A48': 75.0, 'battery.00005422.24C86E090A48': 1,
...

I've defined the battery status as a count, rather than a percentage in /usr/share/weewx/user/extensions.py
weewx.units.obs_group_dict['extraTempBatteryStatus12'] = 'group_count'

But when I put into the skin in /etc/weewx/skins/Seasons/current.inc
        <td class="data">$current.extraTempBatteryStatus12</td>
the resulting table is displayed as 0% for normal and 1% for low

At the moment I have changed /etc/weewx/skins/Seasons/current.inc to
        <td class="data">$current.extraTempBatteryStatus12.raw</td>
so I get 0.0 for a good battery and 1.0 for a low battery.

What syntax do I use in current.inc to display the string "OK" for 0 or "Low Batt" for 1 ?

gjr80

unread,
May 6, 2019, 8:25:34 PM5/6/19
to weewx-user
Hi,

There are a few ways you could do this but the simplest way for a one-off requirement is a little in-line python code in the template. Put something like the following (untested) in your template:

#set $battery_state = $current.extraTempBatteryStatus12.raw
#set $battery_message = "N/A"
#if $battery_state == 0
#set $battery_message = "OK"
#elif $battery_state == 1
#set $battery_message = "Low Batt"
#end if

Then use $battery_message wherever you want the battery state message to appear.

The code could go in index.html.tmpl or in the .inc, up to you, as long as it is executed before you try to use the $battery_message tag.

Gary

Radar

unread,
May 6, 2019, 8:38:28 PM5/6/19
to weewx-user
look at the sensors.inc file
Reply all
Reply to author
Forward
0 new messages