Weather Software > WeeWX Software

Reading rain rate more frequently than the archive period


Hi, I've been using WeeWx for many years now but first time posting here.

I'm writing a program in Python that queries my Acurite 5 in 1 probe through WeeWX for the rain rate and if it's above 0mm, then close the car windows if they are opened. It works well but relies on daily.json to fetch the rain rate and that value I believe updates at the archive frequency (ie, 5 minutes) but the stations sends that data every 36 seconds. Is there a way to fetch this value? The only other option that I can think of is to set the "archive_interval" to 60 instead of 300 in [StdArchive]. If I do that, will that mess up all the historical data already in the database? Any other side effects?

Thanks for your help at keeping the inside of my car dry  :oops:

I switched from reading the JSON data to subscribing to my HomeAssistant MQTT where WeeWX also publishes its loop data (raw data ever 18 seconds). It's working perfectly.

This is the code if anyone is interested.

--- Code: ---#!/usr/bin/env python3

import teslapy
import paho.mqtt.client as mqtt
import json
import time
from datetime import datetime

raining = False

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.

# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
#    print(msg.topic+" "+str(msg.payload.decode('utf-8')))
    jsondata = json.loads(str(msg.payload.decode('utf-8')))
    rain_cm = jsondata.get('rain_cm')

    if rain_cm is not None:
        now =
        current_time = now.strftime("%H:%M:%S")
        print(current_time + ": " + rain_cm)

        rain = float(rain_cm)
        if rain > 0.0:
            if raining == False:
                raining = True
                print("Reading car")
                tesla = teslapy.Tesla('')
                if not tesla.authorized:
                    tesla.refresh_token(refresh_token=input('Enter SSO refresh token: '))
                vehicles = tesla.vehicle_list()
                vehicles[0].sync_wake_up()  # We need to get up to date data so no choice but to wake it
                vehicleData = vehicles[0].get_vehicle_data()

                fd_window = int(vehicleData['vehicle_state']['fd_window'])
                fp_window = int(vehicleData['vehicle_state']['fp_window'])
                rd_window = int(vehicleData['vehicle_state']['rd_window'])
                rp_window = int(vehicleData['vehicle_state']['rp_window'])
                windows = fd_window + fp_window + rd_window + rp_window
                print('Number of windows open: ' + str(windows))

                moving = vehicleData['drive_state']['shift_state']
                print('Driving: ' + str(moving))

                if moving is None and windows > 0:
                    print("Closing windows!")


                    vehicles[0].command('WINDOW_CONTROL', command='close', lat=latitude, lon=longitude)
                    print("It's raining but our windows are closed")

                print("Already checked for this rain period, skipping")
            raining = False
            print("All is fine")

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.username_pw_set(username="username", password="password")

client.connect("hostname", 1883, 60)

# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.

--- End code ---


[0] Message Index

Go to full version