Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_15min does not handle 'consumption' data #136

Open
utdrmac opened this issue Jul 22, 2023 · 3 comments
Open

get_15min does not handle 'consumption' data #136

utdrmac opened this issue Jul 22, 2023 · 3 comments

Comments

@utdrmac
Copy link
Contributor

utdrmac commented Jul 22, 2023

Description

I'm using the example get_meter_reading.py, except I changed line 36 to await meter.get_15min(client) and added print(f"{meter.read_15min}"). This is the output:

$ python3 meter_reading.py
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:smart_meter_texas:Found CA Issuers URI value: http://cacerts.digicert.com/DigiCertTLSRSASHA2562020CA1-1.crt
DEBUG:smart_meter_texas:Loaded certificate file into SSL Context
Authenticating...
DEBUG:smart_meter_texas:Requesting login token
DEBUG:smart_meter_texas:Successfully retrieved login token
Reading meter...
DEBUG:smart_meter_texas:Getting Interval data
ERROR:smart_meter_texas:Error reading data:
DEBUG:smart_meter_texas:Getting Interval data
DEBUG:smart_meter_texas:Getting Interval data
DEBUG:smart_meter_texas:Getting Interval data     <--- line repeats forever, every 2-4 seconds.

After 5 minutes of seeing that same output, I did ctrl-c to stop it.

Is there an update to this aspect? Different API endpoint? Or do you have a working example?

@utdrmac
Copy link
Contributor Author

utdrmac commented Jul 22, 2023

Looks like this func doesn't parse the returned data correctly. The line if entry["RT"] == "G" is the only case it is testing for, yet my data does not contain this value.

[{'DT': '07/20/2023', 'RevTS': '07/20/2023 13:12:00', 'RT': 'C', 'RD': '.17-A,.801-A,.457-A,.186-A,.684-A,.543-A,.171-A,.458-A,,,,,.73-A,.181-A,.295-A,.847-A,.164-A,.152-A,.831-A,.321-A,.185-A,.185-A,.933-A,.184-A,.179-A,.292-A,.731-A,.141-A,.158-A,.432-A,.617-A,.185-A,.185-A,.322-A,.695-A,.148-A,.144-A,.15-A,.836-A,.188-A,.185-A,.184-A,.888-A,.187-A,.186-A,.175-A,.95-A,.164-A,.173-A,.994-A,.178-A,.163-A,1.095-A,.279-A,.265-A,1.218-A,.161-A,.552-A,1.121-A,.182-A,.807-A,.939-A,.182-A,1.078-A,.782-A,.175-A,1.277-A,1.304-A,1.321-A,1.338-A,1.345-A,.99-A,1.558-A,1.451-A,1.307-A,1.296-A,.346-A,1.165-A,1.367-A,.68-A,1.073-A,1.323-A,1.319-A,1.267-A,1.244-A,.545-A,.834-A,1.198-A,.667-A,2.268-A,1.427-A,.537-A,1.225-A,.331-A,.862-A,.73-A,.324-A,1.205-A,.202-A,.515-A'}]

Looking at the SMT.com JS, r = "C" === a.RT ? "Consumption" : "Surplus Generation";

It seems this get_15min func only handles the situation where you generate surplus, and not also handling consumption.

@utdrmac utdrmac changed the title get_15min performs infinite loop get_15min does not handle 'consumption' data Jul 22, 2023
@kschinck
Copy link

kschinck commented Sep 4, 2024

I was able to update the function to support RT="C".
I am debating if "G" or "C" should be positive or negative.

$ git diff ../smart_meter_texas/__init__.py
diff --git a/smart_meter_texas/__init__.py b/smart_meter_texas/__init__.py
index 7ad129e..8e36e56 100644
--- a/smart_meter_texas/__init__.py
+++ b/smart_meter_texas/__init__.py
@@ -105,6 +105,7 @@ class Meter:
         while retry < 3:
             _LOGGER.debug("Getting Interval data")
             surplus = []
+            used = []

             json_response = await client.request(
                 INTERVAL_SYNCH,
@@ -163,6 +164,24 @@ class Meter:
                                 surplus.append([f"{yesterday} {hour}:{minute}", num])
                                 self.interval = surplus
                         return self.interval
+                    elif entry["RT"] == "C":
+                        readdata = entry["RD"].split(",")
+                        for consumed in readdata:
+                            if consumed != "":
+                                if minute_check % 4 == 0:
+                                    hour += 1
+                                    minute = "00"
+                                elif minute_check % 4 == 1:
+                                    minute = "15"
+                                elif minute_check % 4 == 2:
+                                    minute = 30
+                                elif minute_check % 4 == 3:
+                                    minute = 45
+                                minute_check += 1
+                                num = consumed.split("-")[0]
+                                used.append([f"{yesterday} {hour}:{minute}", num])
+                                self.interval = used
+                        return self.interval

     @property
 
```    def reading(self):

@daneski13
Copy link

daneski13 commented Sep 29, 2024

This is something I've been working on as well, I essentially re-wrote the get_15min function to handle the output for the intervalsynch API endpoint to be pretty close to what you get from that "Export My Report" button on SMT's website via a pandas data frame: daneski13/smart-meter-texas@f6dc6c5.

I added a couple of properties that I thought might be useful, an example can be found here.

Would love to see this upstream but I also don't generate surplus so have no idea what it looks like for those that both consume and generate, I assume those with solar panels have that generation ability.

It might be useful to have another property for "net consumption." Handling that in the data frame output would also be nice so there aren't duplicate entries for the same interval e.g. each interval would have a column like "CONSUMPTION_KWH", "SURPLUS_GENERATION_KWH", and "NET_CONSUMPTION_KWH", where NET would be negative if you generated more than used. The issue is I have no idea what the output looks like for those with generation and no way of testing it unless I had a raw JSON output from the intervalsynch endpoint that included both consumption and surplus.

At least with what I've currently implemented, the output from the example looks like this, which is just a slightly nicer version of SMT's "Export My Report":

           USAGE_START_TIME            USAGE_END_TIME  USAGE_KWH ESTIMATED_ACTUAL CONSUMPTION_SURPLUSGENERATION
0 2024-09-01 00:00:00-05:00 2024-09-01 00:15:00-05:00      0.122                A                   Consumption
1 2024-09-01 00:15:00-05:00 2024-09-01 00:30:00-05:00      0.116                A                   Consumption
2 2024-09-01 00:30:00-05:00 2024-09-01 00:45:00-05:00      0.119                A                   Consumption
3 2024-09-01 00:45:00-05:00 2024-09-01 01:00:00-05:00      0.142                A                   Consumption
4 2024-09-01 01:00:00-05:00 2024-09-01 01:15:00-05:00      0.127                A                   Consumption
              USAGE_START_TIME            USAGE_END_TIME  USAGE_KWH ESTIMATED_ACTUAL CONSUMPTION_SURPLUSGENERATION
2587 2024-09-27 22:45:00-05:00 2024-09-27 23:00:00-05:00      0.247                A                   Consumption
2588 2024-09-27 23:00:00-05:00 2024-09-27 23:15:00-05:00      0.260                A                   Consumption
2589 2024-09-27 23:15:00-05:00 2024-09-27 23:30:00-05:00      0.151                A                   Consumption
2590 2024-09-27 23:30:00-05:00 2024-09-27 23:45:00-05:00      0.130                A                   Consumption
2591 2024-09-27 23:45:00-05:00 2024-09-28 00:00:00-05:00      0.220                A                   Consumption
Consumption was 410.639 kWh from 2024-09-01 00:00:00-05:00 to 2024-09-28 00:00:00-05:00
Surplus Generation was 0.0 kWh from 2024-09-01 00:00:00-05:00 to 2024-09-28 00:00:00-05:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants