diff --git a/wyzesense2mqtt/wyzesense2mqtt.py b/wyzesense2mqtt/wyzesense2mqtt.py index 3c85dce..358e169 100755 --- a/wyzesense2mqtt/wyzesense2mqtt.py +++ b/wyzesense2mqtt/wyzesense2mqtt.py @@ -512,6 +512,11 @@ def on_message_remove(MQTT_CLIENT, userdata, msg): # Process message to reload sensors def on_message_reload(MQTT_CLIENT, userdata, msg): LOGGER.info(f"In on_message_reload: {msg.payload.decode()}") + + # Save off the last known state so we don't overwrite new state by re-reading the previously saved file + LOGGER.info("Writing Sensors State File") + write_yaml_file(os.path.join(CONFIG_PATH, SENSORS_STATE_FILE), SENSORS_STATE) + # We are in a mqtt callback so cannot wait for new messages to publish init_sensors(wait=False)