I have an AmbientWeather WS-2902C which is sending data to weewx running on a RPI 4B 8Gg Ram running on a 1TB SSD. I have Home Assistant Supervised running on the same RPI, and I am also using the AmbientWeather integration in HA. As I wanted to do alot more with the weather station such as sending all the raw data to weather web sites all over the world (AWEKAS example below), I am also running weewx on that same RPI and it is listening to the console data being sent to ambientweather utilizing the “customized” AWNET connection feeding to weewx. To track the continuous success or failure or REST api calls made by weewx to the weather web sites, I have changed the weewx.log file location to:
/usr/share/hassio/share/weewx.log
- which then makes that log file visible within the HA container for tailing with GREP - and I have command line sensors with pretty complex logic to track the weewx transmissions as they take place (to numerous weather web sites as shown below) so that I can track the status of the those transmissions. Here is what the lovelace card for that looks like (“Cnsl” is the AmbientWeather console):
For example, the logic for the AWEKAS (although I am in NJ this web site for my weather station is in Germany LOL) and their website if my favorite, graphically:
anyway, the AWEKAS command-line sensor coniguration.yaml is:
- platform: command_line
name: WEEWX_LAST1_SENT_TO_AWEKAS
command: "grep 'AWEKAS: Published' /share/weewx.log | tail -1 | cut -c-255"
scan_interval: 30
command_timeout: 5
value_template: >
{% set data = value | regex_findall('\(([0-9]+)\)') | first | int | as_datetime | as_local %}
{% set ts = data.year ~ ' ' ~ (value | regex_findall('(.+)kruse-pi weewx') | first).strip() %}
{% set time = strptime(ts, '%Y %b %d %H:%M:%S', data) | as_local %}
{% set str = time.strftime('%a %-m/%-d %-I:%M:%S%p') ~ ' (5 min)' %}
{% set indx = str.find("M (") %}
{% set oldstr = str[indx-1:indx+1] %}
{{ str.replace(oldstr,oldstr.lower()) }}
unique_id: WEEWX_LAST1_SENT_TO_AWEKAS
And the most nightmarish one is “Last Weewx Error:” which has to look at the logic for all of the other sensors to see when they each last had an error, and then report on the most recent one - IF it is still in an error state (and this was a nightmare to figure out):
- platform: command_line
name: WEEWX_LAST1_REST_CALL_FAILURE
command: "grep 'ERROR weewx.restx:' /share/weewx.log | tail -1 | cut -c-255"
scan_interval: 60
command_timeout: 5
value_template: >
{% set data = value | regex_findall('\(([0-9]+)\)') | first | int | as_datetime | as_local %}
{% set errortime = strptime(now().year ~ ' ' ~ ' '.join(value.split(' ')[0:3]),'%Y %b %d %H:%M:%S',data) | as_local %}
{% set errordestination = (((value | regex_findall('(.+): Failed to publish') | first).strip() | regex_findall(': (\w+)') | first).strip()).lower() %}
{% set sensortoretry = 'sensor.weewx_last1_sent_to_' + errordestination %}
{% set thisyear = now().year %}
{% set statessensorretry = states(sensortoretry) %}
{% set joiner1 = ' '.join(states(sensortoretry).split(' ')[0:3]) %}
{% set joiner2 = now().year ~ ' ' ~ joiner1 %}
{% set sensorretriedtime = strptime(joiner2,'%Y %a %m/%d %I:%M:%S%p',data) | as_local %}
{% if (sensorretriedtime > errortime) %}
{{ 'No current errors' }}
{% else %}
{% set ts = data.year ~ ' ' ~ (value | regex_findall('(.+)kruse-pi') | first).strip() %}
{% set time = strptime(ts, '%Y %b %d %H:%M:%S', data) | as_local %}
{{ time.strftime('%a %-m/%-d %-I:%M:%S%p') }}, {{ (value|regex_replace(find='EDT \(([0-9]+)\):', replace='EDT:', ignorecase=False)).split("weewx.restx: ",1)[1] }}
{% endif %}
unique_id: WEEWX_LAST1_REST_CALL_FAILURE
Anyway, here is my question. Although I am using an SSD, I would much rather reduce all the ‘log scraping’ (which is really amatueurish (sp?) in my opinion!) and instead have MQTT messages for each of those transmissions as they take place, sent from weewx to home assistant instead. I will also eventually need to do this instead of the log scraping as I add more functionality (video monitoring etc) to Homa Assistant the RPI at that point won’t be enough hardware (and I would use the RPI only for weewx then) - so such MQTT messages would need to be sent over the network from separate weewx & HA machines. So how do I get the MQTT functionality working from weewx to HA to feed the same data into those what are currently command line sensors - just the information about the restx transmissions - without scraping the log from within weewx to send the message across?