Pool Stats with Flipr

Hello Openhab users,

I’m lucky enough to have a pool in my garden and I’m using OH2.5 since one year to automate the pump (using solar panel optimization). However I recently have some issue with my pool system (Zodiac Tri Pro) that was showing crazy numbers for PH & Chlorine and the pool was back to damn green color (should be blue…)

I decided to go for Flipr Start that is capable of collecting data such as PH, Redox, Chlorine thanks to a floating thing directly in the pool. The cost is important (200 Euros) and you should add 60 Euros yearly subscription if you want to use API (needed for OH) and use their Sigfox network sync with their cloud.
This is all expensive (+maintenance) but if it works I’m happy to continue - let me know if you have a better setup anyway.

The setup is pretty basic as I’m not a developper and I’ve used the following.

Python Script to get data from FliprAPI: flipr.py

#!/usr/bin/python
# -*- coding: latin-1 -*-

import requests

url = "https://apis.goflipr.com/OAuth2/token"

payload='grant_type=password&username=yourusername&password=yourpassword'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Cookie': 'ARRAffinity=e7eb41d88dc1d0d267ff2d136e49ca19a13d2c61504aad914f4e92e340e46d11; ARRAffinitySameSite=e7eb41d88dc1d0d267ff2d136e49ca19a13d2c61504aad914f4e92e340e46d11'
}

response = requests.request("POST", url, headers=headers, data=payload)
data = response.text
data2 = "Bearer " + data.split('"')[3]



url = "https://apis.goflipr.com/modules/yourserial/survey/last"

payload={}
headers = {
  'Authorization': data2,
  'Cookie': 'ARRAffinity=e7eb41d88dc1d0d267ff2d136e49ca19a13d2c61504aad914f4e92e340e46d11; ARRAffinitySameSite=e7eb41d88dc1d0d267ff2d136e49ca19a13d2c61504aad914f4e92e340e46d11'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text.encode('unicode-escape').decode('utf-8'))

The script will return a JSON such as :

{"MeasureId":337,"Source":"Bluetooth","DateTime":"2021-05-22T16:12:33.978143Z","Temperature":20.44,"PH":{"Label":"PH","Message":"Trop faible","Deviation":-1.52,"Value":6.61,"DeviationSector":"TooLow"},"OxydoReductionPotentiel":{"Label":"Potentiel Redox.","Value":401.0},"Conductivity":{"Label":"Conductivité","Level":"--"},"UvIndex":0.0,"Battery":{"Label":"Batterie","Deviation":1.0},"Desinfectant":{"Label":"Chlore","Message":"Trop faible","Deviation":-0.80764455381986666,"Value":0.09041378838716238,"DeviationSector":"TooLow"}}

Don’t forget to add your script in the exec.whitelist file.

/etc/openhab2/scripts/flipr.py

Then I’m using Exec Binding to automate the python script every 1000 seconds: flipr.things

Thing exec:command:flipr "flipr" @ "flip" [command="/etc/openhab2/scripts/flipr.py", interval=1000,timeout=5, autorun=true]

I’ve created the items to execute and collect the data: flipr.items

Switch FliprRun {channel="exec:command:flipr:run"}
String Flipr "Flip Text" {channel="exec:command:flipr:output"}
String Flipr_Source "Source"
String Flipr_DateTime "DateTime"
Number Flipr_Temperature "Temperature"
String Flipr_PH "PH"
String Flipr_Redox "Redox"
String Flipr_Conductivity "Conductivity"
String Flipr_Desinfectant "Desinfectant"

Note : Yet the DateTime does not work properly

And created a rule to convert JSON to items every 10 minutes: flipr.rules:

rule "Flipr"

when 
Time cron "* */10 * * * ?" //Run this rule every hour
then
    val String json = (Flipr.state as StringType).toString

		val String Source  = transform("JSONPATH", "$.Source", json)
		//DTime  = transform("JSONPATH", "$.DateTime", json)
		val String Temperature  = transform("JSONPATH", "$.Temperature", json)
		val String PH  = transform("JSONPATH", "$.PH.Value", json)
		val String Redox  = transform("JSONPATH", "$.OxydoReductionPotentiel.Value", json)
		val String Conductivity  = transform("JSONPATH", "$.Conductivity.Level", json)
		val String Desinfectant  = transform("JSONPATH", "$.Desinfectant.Value", json)
	
		
		Flipr_Source.postUpdate(Source)
		//Flipr_DateTime.postUpdate(DTime)
		Flipr_Temperature.postUpdate(Temperature)
		Flipr_PH.postUpdate(PH)
		Flipr_Redox.postUpdate(Redox)
		Flipr_Conductivity.postUpdate(Conductivity)
		Flipr_Desinfectant.postUpdate(Desinfectant)
		
	logInfo("notifications", "Flipr : " + Flipr.state)

end

For the display I’m using a basic sitemap config:

  Text item=Flipr_Source label="Source [%s]"
               			  	Text item=Flipr_Temperature label="Temperature [%s]"
					{Chart item=Flipr_Temperature period=D label="Flipr Temperature" legend=true}							
					Text item=Flipr_PH label="PH [%s]"
					{Chart item=Flipr_PH period=D label="Flipr PH" legend=true}
					Text item=Flipr_Redox label="Redox [%s]"
					{Chart item=Flipr_Redox period=D label="Flipr Redox" legend=true}														
               			    Text item=Flipr_Conductivity label="Conductivity [%s]"
   					{Chart item=Flipr_Conductivity period=D label="Flipr Conductivity" legend=true}														
					Text item=Flipr_Desinfectant label="Desinfectant [%s]"
   				{Chart item=Flipr_Desinfectant period=D label="Flipr Desinfectant" legend=true}														

Thanks to the integration, I can now check my pool stats very easily in OH Sitemap and use the data to execute the pomp at the right moment (in order to use solar panel electricity of course).

Happy to get your feedback on this one.
Ben / OH2.5 with Flipr