Hello,
Below I'm posting a script for reading data via the Aquastilla API.
It collects data such as:
- salt level
- water used today
- remaining water until the next regeneration
- expected regeneration date
- flood alarm (I have a dedicated wireless sensor connected)
- vacation mode (status preview and remote on/off capability)
- display of the current operating mode
In the future, I'll probably want to add the ability to remotely turn off the water flow – this option is available in the app.
crontab task:
Code: Select all
*/15 * * * * /usr/bin/python3 /home/pi/domoticz/scripts/python/aquastilla_domoticz.py
The script runs once every 15 minutes. I haven't tried running it at a shorter interval, because, according to the information I have, too frequent calls can temporarily lock the account. Secondly, I don't think it makes sense to update such data too frequently.
you need to create a file and paste the following script into it (You'll need to provide your login details, IP address, and optionally, the names of the displayed information—e.g., modes or error messages)
/home/pi/domoticz/scripts/python/aquastilla_domoticz.py
Code: Select all
import requests
import json
from datetime import datetime, timedelta, timezone
from aquastilla_softener import AquastillaSoftener
# =====================================================
# --- KONFIGURACJA DANYCH LOGOWANIA ---
# =====================================================
EMAIL = "TWÓJ_EMAIL"
PASSWORD = "TWOJE_HASLO"
DOMOTICZ_URL = "http://localhost:8080"
# =====================================================
# --- TWOJE NUMERY IDX Z DOMOTICZA ---
# =====================================================
IDX_SOL = 10
IDX_WODA_DZIS = 11
IDX_WODA_ZAPAS = 12
IDX_ALARM = 13
IDX_DATA_REGEN = 14
IDX_WAKACJE_SW = 15
IDX_TRYB = 16
# =====================================================
def update_domoticz(idx, nvalue, svalue):
url = f"{DOMOTICZ_URL}/json.htm?type=command¶m=udevice&idx={idx}&nvalue={nvalue}&svalue={svalue}"
try:
response = requests.get(url, timeout=5)
return response.status_code == 200
except Exception as e:
print(f"Błąd Domoticz (IDX {idx}): {e}")
return False
# Słownik tłumaczeń trybów (dostosuj, jeśli API zwróci inne nazwy)
TRYBY_PRACY = {
"SERVICE": "Zmiękczanie",
"REGENERATION": "Regeneracja",
"BACKWASH": "Płukanie wsteczne",
"BRINE": "Solankowanie",
"RINSE": "Płukanie końcowe",
"REFILL": "Napełnianie zbiornika",
"STANDBY": "Oczekiwanie"
}
try:
softener = AquastillaSoftener(email=EMAIL, password=PASSWORD)
devices = softener.list_devices()
if not devices:
print("Nie znaleziono urządzeń.")
else:
device = devices[0]
uuid = device['uuid']
headers = softener._get_headers()
base = softener._api_base_url
res_state = requests.get(f"{base}/device/{uuid}/state", headers=headers)
data = res_state.json()
res_settings = requests.get(f"{base}/device/{uuid}/settings", headers=headers)
settings = res_settings.json()
# --- OBRÓBKA DANYCH ---
sol = data.get("saltPercent", 0)
woda_dzis = round(data.get("todayWaterUsage", 0) * 1000, 1)
woda_zapas = round(data.get("waterLeft", 0) * 1000, 1)
# Pobieranie i mapowanie trybu pracy
raw_mode = data.get("operationMode", "UNKNOWN").upper()
tryb_tekst = TRYBY_PRACY.get(raw_mode, f"Inny ({raw_mode})")
raw_date = data.get("expectedRegenerationDate", "Brak")
clean_date = raw_date.split("T")[0] if "T" in raw_date else raw_date
is_vacation = settings.get("vacationMode", False)
vac_n = 1 if is_vacation else 0
vac_s = "On" if is_vacation else "Off"
# Alarm zalania
flood_status = device.get("deviceHistory", {}).get("flood")
n_alert, s_alert = 1, "System bezpieczny"
if flood_status:
flood_time = datetime.fromisoformat(flood_status.replace("Z", "+00:00"))
if datetime.now(timezone.utc) - flood_time < timedelta(minutes=30):
n_alert, s_alert = 4, "ALARM! WYKRYTO ZALANIE!"
# --- WYSYŁKA DO DOMOTICZA ---
update_domoticz(IDX_SOL, 0, sol)
update_domoticz(IDX_WODA_DZIS, 0, woda_dzis)
update_domoticz(IDX_WODA_ZAPAS, 0, woda_zapas)
update_domoticz(IDX_DATA_REGEN, 0, clean_date)
update_domoticz(IDX_ALARM, n_alert, s_alert)
update_domoticz(IDX_WAKACJE_SW, vac_n, vac_s)
update_domoticz(IDX_TRYB, 0, tryb_tekst) # <--- Wysyłka trybu
print(f"[{datetime.now().strftime('%H:%M:%S')}] Aktualizacja OK.")
print(f"Tryb: {tryb_tekst}, Sól: {sol}%, Woda dziś: {woda_dzis}L")
except Exception as e:
print(f"Błąd krytyczny: {e}")
The attached photo shows what types of virtual sensors should be added in domoticz.
This is my first post, so please be understanding when it comes to descriptions and information
Thanks again to waltervl for effectively pointing me in the right direction
