rsnodgrass / pyflowater

Python interface for the Flo by Moen API
Other
17 stars 7 forks source link

Anyone figured out the push notifications? #12

Open michaelmaston opened 3 years ago

michaelmaston commented 3 years ago

First off, thanks so much for all involved that have contributed to this info. Super useful!!!

Anyone figure out how to use the following URL for Flo? I captured some calls to it with Charles on my iPhone.

https://api-gw.meetflo.com/api/v1/pushnotificationtokens/ios

It looks to me like a way to get change notifications pushed to you vs. polling for changes. I assume it's using some separate channel, perhaps a TCP connection so I don't see anything in my captures after this gets called pretty early in the app's startup. The outbound JSON looks like this:

{ "aws_endpoint_id": "id string for AWS I assume", "mobile_device_id": "id string for the device", "token":"token string different than auth token" }

and what comes back in the response is this:

{ "mobile_device_id": "same device id string as above", "aws_endpoint_id": "same AWS id string as above", "client_id": "client id of some sort", "user_id": "my user id", "token": "same token as above", "client_type": 1, "mobile_device_id_client_id": "mobile_device_id in this message" + ":" + "client_id in this message", "created_at": "2021-08-02T20:36:14.120Z", "updated_at": "2021-08-02T20:36:14.120Z" }

I took out the actual data where it was helpful to point out where the same values show up. I haven't tried repeating this capture yet to see if anything changes from run to run. Without knowing where to go next it doesn't help but hoping someone out there has dug deeper into this.

I'm assuming you need to use the response info, particularly the mobile and client ids to log in somewhere else to get the push notifications.

Separate question: Is there a recommendation on how often to poll the server for updates, both from the perspective of what is reasonable given how slow/fast things change and keeping Moen from getting irritated by me using there server? Having the push notifications would eliminate that issue but until it is actually working, I have to poll.

michaelmaston commented 3 years ago

Quick update. I tried capturing the data again and it appears the values don't seem to change those posted to the server or those returned (other than the timestamps). I might be able to find some of these id's in the data returned by the server for the account, ... but how to use them to get push notifications?

dulitz commented 3 years ago

I don't think APNs will be useful for you. Read this AWS Pinpoint page and the iOS SDK page linked from it. APNs delivers notifications to iOS apps, and it won't in general work to use Flo's APNs setup to push notifications to someone else's app.

michaelmaston commented 3 years ago

Thanks, I'm sure you're right. I'm also wondering if this is more about the notifications mentioned here (https://solutions.moen.com/FAQ's/FAQ's-Flo/Using_Flo/How_does_the_device_notify_me_if_there_is_a_leak_in_my_water_system%3F) rather than ones from the service to the app about device changes (I could be wrong).

Thoughts on the polling rate? I haven't my Flo installed yet so I'm trying to make sense of things without everything going yet.

dulitz commented 3 years ago

Sorry, I forgot to answer that part of your question. :) I poll every 2 minutes to create pressure/flow rate graphs (for any sustained flows), and to update the hourly consumption graphs.

Since I can't get it to return minutely consumption data at all, polling more frequently than every 2 minutes seems to not be very useful.

I'm curious how the app receives the real-time flow rate data when you have the app open. I would like to have that but instrumenting my phone is not high on my priority list. If you can get info on that I'd be much obliged! I'm thinking there may be MQTT under the hood somewhere...

michaelmaston commented 3 years ago

Definitely makes sense at that poll rate. Once I get the shutoff installed so I am actually gathering interesting data, I will definitely take a look at that and post back up here. Right now everything I get is 0 (as I'd expect) when it comes to measurements. I've got a lot working already based on the code here and digging thru network traces from the app.

Hopefully get it installed in the next week or so.

dulitz commented 3 years ago

Cool. BTW if you are planning on graphing interesting data from your house, I'd recommend putting the data into Prometheus and using Grafana to generate dashboards. A la:

image

Take a look at my porter repo if that's something you want to try.

dulitz commented 3 years ago

I just noticed in const.py:

# FIXME: for real time access to flow rates and
#https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel?database=projects%2Fflotechnologies-1b111%2Fdatabases%2F(default)&gsessionid={GSESSION_ID}&VER=8&RID=rpc&SID={SESSION_ID}&CI=0&AID=113&TYPE=xmlhttp&zx=lsvpgbg6aoar&t=2

That looks like what we would need to dig into to get real time access.

michaelmaston commented 3 years ago

Cool stuff. I'll definitely be checking out that stuff once the valve is in and collecting data. I've been using Google Charts for other charting I do in automation (mostly around HVAC systems) but I'll check those out and see how they compare. I get pretty good results with Google Charts but their docs seem like they are a mix of their old and new charts so getting things the way you want them can be a bit of a treasure hunt. Lol

One other thing I've noticed about the Moen service is that it seems to start off with a placeholder location in New York and adds the location you define after that. So when I loop thru the locations the service gives me, I get two, one real, one this one in New York. Fortunately the placeholder has no devices under it so it is easy to ignore. I can't see it in the app so no way to delete it. I even tried unpairing my Flo, creating a completely separate new account under a different email and added it back in. I still ended up getting the New York placeholder location along with the one I defined. It's not a problem to handle but just seems odd and I haven't seen any reference to it. Do you see this too if you enumerate the locations returned by the service?

dulitz commented 3 years ago

Yes, I have a placeholder location in New York also.

dulitz commented 3 years ago

Now that the real-time listener code is merged in 0.5.0, is this issue closed @michaelmaston ?