Flume - Water Monitoring

Anyone have any experience with FLUME?

Seems they have an API which could make might make it easy to integrate with OH.

Squid :squid:

I have been using the first gen version of Flume for almost a year. Once calibrated it works great in detecting water usage and leaks using their mobile app. I have not built an openhab binding but have put together a quick python script that uses their api to collect the water usage every few minutes to store them in my own influxdb. Glad to share the script if interested.

Oha, I’ve been looking for something like this for some time. But in the FAQ they quoted that it’s for the US market only currently and sadly it seems that their cloud API don’t offer local access.

If anyone knows a similar product which is available in the EU and comes without a mandatory cloud-connection, please tell me. :slight_smile:

@basriram

Would love to see your python script would you mind sharing?

Squid :squid:

Not the prettiest code with lot of hardcoding but gets the job done, pulls the data every 15 min via a cronjob and inserts them into influxdb 2.0. You need to setup your clientid, clientsecret, username and password for flume api usage and obtain the userid, deviceid using postman or other means.

import time
import json
from datetime import date, timedelta, datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
import math
from pytz import timezone
import requests
database = 'waterdb'
retention_policy = 'autogen'
bucket = f'{database}/{retention_policy}'
token = '<influxdb2.0 token>'
current_milli_time = lambda: int(round(time.time() * 1000))

class FlumeUsageScraper:
    API_url = 'https://api.flumetech.com/oauth/token'
    export_url = 'https://api.flumetech.com/users/<userid>/devices/<deviceid>/query'

    def pretty_print_POST(self, req):
        print('{}\n{}\n{}\n\n{}'.format(
            '-----------START-----------',
            req.method + ' ' + req.url,
            '\n'.join('{}: {}'.format(k, v) for k, v in req.headers.items()),
            req.body,
        ))

    def get_water_usage(self, mytime):
        headers = {
        'Accept' : 'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding' : 'gzip, deflate, br',
        'Accept-Language':'en-US,en;q=0.9',
        'X-Requested-With': 'XMLHttpRequest',
        'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
        }

        data = {
         'grant_type':'password',
         'client_id':'<clientid>',
         'client_secret':'<clientsecret>',
         'username':'<username>',
         'password':'<password>'
         }

        querydata = {'queries':[{'bucket':'MIN','since_datetime':mytime,'request_id':'5705766de1914'}]}
        session = requests.session()
        initreq = requests.Request('POST', self.API_url, data=data, headers=headers)
        initprep = session.prepare_request(initreq)
        self.pretty_print_POST(initprep)
        response = session.send(initprep)
        mydata = response.json()['data']
        access_token = mydata[0]['access_token']
        headers['Authorization'] = 'Bearer ' + access_token
        headers['Content-Type'] = 'application/json'
        jsondata = json.dumps(querydata)
        exportreq = requests.Request('POST', self.export_url, data=jsondata, headers=headers )
        exportprep = session.prepare_request(exportreq)
        self.pretty_print_POST(exportprep)
        response = session.send(exportprep)
        return response.json()

    def run(self):
        lastfifteenmin = datetime.now() - timedelta(minutes = 16)
        print(lastfifteenmin.strftime('%Y-%m-%d %H:%M:%S'))
        data = self.get_water_usage(lastfifteenmin.strftime('%Y-%m-%d %H:%M:%S'))
        jsondata = data['data'][0]['5705766de1914']
        client = InfluxDBClient(url='http://influxdb.iot.lan:8086', token=f'{token}', org='waterdborg')
        write_api = client.write_api()
        for i in range(len(jsondata)):
            if (jsondata[i]['value'] > 0):
                dt = datetime.strptime(jsondata[i]['datetime'], '%Y-%m-%d %H:%M:%S')
                cdt = timezone('US/Central').localize(dt)
                ts = time.mktime(cdt.timetuple())
                print(jsondata[i]['datetime'])
                print(jsondata[i]['value'])
                point = Point("flumedata").field("value", float(jsondata[i]['value'])).time(int(ts),write_precision=WritePrecision.S)
                print(point.to_line_protocol())
                write_api.write(bucket=bucket, record=point)
            else:
                print('not writing 0 value for ts'+jsondata[i]['datetime'])
        write_api.__del__()

if __name__ == '__main__':
  scraper = FlumeUsageScraper()
  scraper.run()

Hey there! Does this code still works for you?

I am getting lost index out of range error wondering if you can help?

Hi all - I have submitted a binding for the Flume water meter into the openhab-addons.

I welcome people to test and provide feedback on the binding. Note, this build only works on Openhab 4.2 and later.

Documentation can be found here:

Regards,
Jeff

3 Likes

Is anybody else getting this error when you first start OH 4.3.0 with the flume binding linked above?

2025-02-16 13:23:08.756 [WARN ] [n.module.provider.AnnotationActionModuleTypeHelper] - Method FlumeDeviceActions::queryWaterUsage has a single output but does not use the default output name in the ActionOutput annotation. This should be fixed in the binding.

Best, Jay

Hi jay. You can install the binding directly from openHAB now vs using the link above. There were changes checked in from others which look like it is related to the issue you are seeing - not sure if those fix the issue or not. If you can confirm you see the issue with the binding from openHAB install, I can look at it this week.

Regards.

Thanks, I got the latest 4.x version here now.

https://openhab.jfrog.io/ui/native/libs-snapshot-local/org/openhab/addons/bundles/org.openhab.binding.flume/4.4.0-SNAPSHOT/org.openhab.binding.flume-4.4.0-20241215.134717-1.jar

Best, Jay

Hey Jeff,

Started this morning below:

Flume Meter Device
CONFIGURATION_ERROR
Invalid user credentials, please check configuration

I disable the Meter Device THING and re-ENABLE it and it goes back ONLINE then after a bit goes OFFLINE again.

Deleted Meter Device and re-SCANed and it comes back. I enable it and it goes back OFFLINE again.

I’m thinking something changed on Flume’s side?

The cloud connector THING is ONLINE still.

I even reinstalled the binding from OH natively, same thing.

Best, Jay

I noticed this in my setup as well but have not had time to debug. I’ll take a look at it.

1 Like

Hi Jay -

The fix was a little more involved as Flume restricted the API further on the duration that can be queried so I had to rewrite how the binding established a historical baseline for the cumulative usage. Anyway, if you can give it a try and make sure it works for you. This was compiled for OH 4.3.3.

https://drive.google.com/file/d/1ueP9wbYwkMYpEKCX25MoDvDeiVmJpERI/view?usp=sharing

BR, Jeff

Thank you! I have dropped it in OH 4.3.5 and will let you know if it goes offline or not. I do monitor both THINGS statuses for it, so I’ll know if it goes OFFLINE again.

Best, Jay

8 Hours went by w/o either THING going OFFLINE and it’s collecting data also.

Thank you again! Any additional test you want me to do, I’d be glad to help.

Best, Jay

1 Like

Has anybody gotten this channel to work on a rule? The app sends me the alert but the rule never fires.

Channel “flume:meter-device:e14420bb44:7105470611102401252:usageAlert” triggered

Best, Jay

Hi Jay - This is working in my setup. I presume you are getting the usage alerts through the flume app? If you can put the binding in debug mode, you should see something like the following in your log when you get a usage alert.

2025-06-09 19:02:03.674 [DEBUG] [.internal.handler.FlumeDeviceHandler] - Alert query: FlumeApiQueryWaterUsage[requestId=SYSTEM_TRIGGERED_USAGE_ALERT, sinceDateTime=2025-06-08T01:39, untilDateTime=2025-06-08T01:5
4, bucket=MIN, groupMultiplier=null, operation=AVG, units=GALLONS, sortDirection=null]
2025-06-09 19:02:03.675 [DEBUG] [.binding.flume.internal.api.FlumeApi] - METADATA: {"queries":[{"request_id":"SYSTEM_TRIGGERED_USAGE_ALERT","since_datetime":"2025-06-08 01:39:00","until_datetime":"2025-06-08 01:
54:00","bucket":"MIN","operation":"AVG","units":"GALLONS"}]}
2025-06-09 19:02:03.675 [DEBUG] [.binding.flume.internal.api.FlumeApi] - REQUEST: HttpRequest[POST /users/XXX/devices/YYY/query HTTP/1.1]@39697ba2
2025-06-09 19:02:03.784 [DEBUG] [.internal.handler.FlumeDeviceHandler] - High Flow Alert triggered at 2025-06-08T01:54.  Water has been running for 15 minutes averaging 6.8 gallons every minute.
2025-06-09 19:02:03.784 [DEBUG] [.binding.flume.internal.api.FlumeApi] - METADATA: {"queries":[{"request_id":"USAGE_FROM_BASELINE","since_datetime":"2025-06-01 00:00:00","until_datetime":"2025-06-09 19:02:03","b
ucket":"MON","group_multiplier":1,"operation":"SUM","units":"GALLONS","sort_direction":"ASC"}]}
2025-06-09 19:02:03.784 [DEBUG] [.binding.flume.internal.api.FlumeApi] - REQUEST: HttpRequest[POST /users/XXX/devices/YYYY/query HTTP/1.1]@570b3df3

Are you creating an item against this trigger channel (usage-alert)?

I’m not, just the channel is the item on the rule.

I just looked through my events and this channel isn’t triggered at all even though the app sent me the notice. This has been the case since I set this up months ago.

I will put in debug mode once I understand how you’re referencing this channel in OH (channel vs. item).

Best, Jay

I don’t attach an item since it is a trigger channel. I am using python scripting, but here is my rule:

@rule("Rule Usage Alert", description="This rule will run on a usage alert",
    tags=["Flume"])
@when("Channel flume:meter-device:XXX:YYYY:usage-alert triggered")
def Rule_Usage_Alert(module, input):
    event = input['event']
    logger.info("Usage Alert: ", event)
    NotificationAction.sendNotification("jeff@james-online.com", "Flume usage event")

I will put in debug mode and let you know next time my sprinkler system runs and see what happens.

I’m running this version → org.openhab.binding.flume-4.3.3-SNAPSHOT.jar

Thanks!