[weewx-user] Re: How do I convert battery strength back to a string?

2019-05-06 Thread Radar
look at the sensors.inc file

On Monday, May 6, 2019 at 6:16:22 PM UTC-5, Ken Booth wrote:
>
> 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=updateraw=1=24C86E090EC1=tower=4036=34=76.4=30.31=normal=4
> weewx[24667]: interceptor: MainThread: raw packet: 
> {'bridge_id.4036.24C86E090EC1': '24C86E090EC1', 
> 'sensor_type.4036.24C86E090EC1': 'tower', 
> 'battery.4036.24C86E090EC1': 0, 
> ...
> weewx[24667]: interceptor: MainThread: raw data: 
> dateutc=now=updateraw=1=24C86E090A48=tower=5422=34=71.4=29.83=low=3
> weewx[24667]: interceptor: MainThread: raw packet: 
> {'rssi.5422.24C86E090A48': 75.0, 'battery.5422.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
> $current.extraTempBatteryStatus12
> 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
> $current.extraTempBatteryStatus12.raw
> 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 ? 
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/77a148ff-1b38-476e-83cb-dbc21a89942a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[weewx-user] Re: How do I convert battery strength back to a string?

2019-05-06 Thread gjr80
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

On Tuesday, 7 May 2019 09:16:22 UTC+10, Ken Booth wrote:
>
> 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=updateraw=1=24C86E090EC1=tower=4036=34=76.4=30.31=normal=4
> weewx[24667]: interceptor: MainThread: raw packet: 
> {'bridge_id.4036.24C86E090EC1': '24C86E090EC1', 
> 'sensor_type.4036.24C86E090EC1': 'tower', 
> 'battery.4036.24C86E090EC1': 0, 
> ...
> weewx[24667]: interceptor: MainThread: raw data: 
> dateutc=now=updateraw=1=24C86E090A48=tower=5422=34=71.4=29.83=low=3
> weewx[24667]: interceptor: MainThread: raw packet: 
> {'rssi.5422.24C86E090A48': 75.0, 'battery.5422.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
> $current.extraTempBatteryStatus12
> 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
> $current.extraTempBatteryStatus12.raw
> 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 ? 
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/7ffd9919-d550-409b-b47d-6980943f7914%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.