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

FEMS Requests combined to avoid timeouts #1262

Merged
merged 4 commits into from
Jan 2, 2024

Conversation

sthhs
Copy link
Contributor

@sthhs sthhs commented Nov 18, 2023

My FEMS (Fenecon Home 10, Version 2022 and later) is very sensitive with answering requests at the REST/JSON interface. Too many requests lead to very long answering times (30 s or more) and therefore to timeouts in the OpenWB. In the OpenEMS community you can find that there is indeed a limitation for not overloading the FEMS. The impact on the OpenWB is shown on the attached picture.
Timeouts
With my modifications (combining of the requests in inverter.py, bat.py, counter.py) and increasing the timeout value in counter.py to 6 almost all of the peaks (occurences of timeouts that lead to the wrong calculation of the consumption) disappear. They aren't gone totally, but reduced to a very small quantity.

@sthhs
Copy link
Contributor Author

sthhs commented Nov 19, 2023

Here are more pictures.
Without the modification:
before
Corresponding error message:
error

and with:
after

Comment on lines 40 to 52
# response = session.get(
# "http://" + self.ip_address +
# ":8084/rest/channel/_sum/(GridActivePower|ProductionActivePower|ConsumptionActivePower)",
# timeout=2).json()
# for singleValue in response:
# address = singleValue["address"]
# if (address == "_sum/GridActivePower"):
# grid = scale_metric(singleValue['value'], singleValue.get('unit'), 'W')
# elif address == "_sum/ProductionActivePower":
# pv = scale_metric(singleValue['value'], singleValue.get('unit'), 'W')
# elif address == "_sum/ConsumptionActivePower":
# haus = scale_metric(singleValue['value'], singleValue.get('unit'), 'W')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# response = session.get(
# "http://" + self.ip_address +
# ":8084/rest/channel/_sum/(GridActivePower|ProductionActivePower|ConsumptionActivePower)",
# timeout=2).json()
# for singleValue in response:
# address = singleValue["address"]
# if (address == "_sum/GridActivePower"):
# grid = scale_metric(singleValue['value'], singleValue.get('unit'), 'W')
# elif address == "_sum/ProductionActivePower":
# pv = scale_metric(singleValue['value'], singleValue.get('unit'), 'W')
# elif address == "_sum/ConsumptionActivePower":
# haus = scale_metric(singleValue['value'], singleValue.get('unit'), 'W')

Please remove, GitHub is already tracking changes

Comment on lines 51 to 61
# Grid total energy sums
# response = session.get(
# 'http://'+self.ip_address+':8084/rest/channel/_sum/Grid.+ActiveEnergy',
# timeout=1).json()

# for singleValue in response:
# address = singleValue['address']
# if (address == '_sum/GridBuyActiveEnergy'):
# imported = scale_metric(singleValue['value'], singleValue.get('unit'), 'Wh')
# elif (address == '_sum/GridSellActiveEnergy'):
# exported = scale_metric(singleValue['value'], singleValue.get('unit'), 'Wh')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Grid total energy sums
# response = session.get(
# 'http://'+self.ip_address+':8084/rest/channel/_sum/Grid.+ActiveEnergy',
# timeout=1).json()
# for singleValue in response:
# address = singleValue['address']
# if (address == '_sum/GridBuyActiveEnergy'):
# imported = scale_metric(singleValue['value'], singleValue.get('unit'), 'Wh')
# elif (address == '_sum/GridSellActiveEnergy'):
# exported = scale_metric(singleValue['value'], singleValue.get('unit'), 'Wh')

Comment on lines 28 to 34

# power = scale_metric(response["value"], response.get("unit"), 'W') * -1

# response = session.get(
# 'http://'+self.ip_address+':8084/rest/channel/_sum/ProductionActiveEnergy',
# timeout=2).json()
# exported = scale_metric(response["value"], response.get("unit"), 'Wh')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# power = scale_metric(response["value"], response.get("unit"), 'W') * -1
# response = session.get(
# 'http://'+self.ip_address+':8084/rest/channel/_sum/ProductionActiveEnergy',
# timeout=2).json()
# exported = scale_metric(response["value"], response.get("unit"), 'Wh')

@LKuemmel LKuemmel added this to the 2.1.3 milestone Nov 21, 2023
@sthhs
Copy link
Contributor Author

sthhs commented Nov 21, 2023

Changes completed

@sthhs sthhs requested a review from LKuemmel November 21, 2023 16:51
Copy link
Contributor

@LKuemmel LKuemmel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitte noch die Flake8-Änderungen vornehmen, damit der Test durchläuft.

@sthhs
Copy link
Contributor Author

sthhs commented Dec 1, 2023

Danke für den Hinweis, die Korrekturen sind gemacht.

@sthhs sthhs requested a review from LKuemmel December 1, 2023 15:24
Copy link
Contributor

@LKuemmel LKuemmel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Der Test muss noch angepasst werden. Hast Du eine Beispiel-Antwort für die neue Abfrage?

@sthhs
Copy link
Contributor Author

sthhs commented Dec 1, 2023

Die Antworten von meinem FEMS stehen jeweils unter der Abfrage:

inverter.py:
http://'+self.ip_address+':8084/rest/channel/_sum/(ProductionActivePower|ProductionActiveEnergy)

[ { "address": "_sum/ProductionActiveEnergy", "type": "LONG", "accessMode": "RO", "text": "", "unit": "Wh_Σ", "value": 18988374 }, { "address": "_sum/ProductionActivePower", "type": "INTEGER", "accessMode": "RO", "text": "Total production; always positive", "unit": "W", "value": -9 } ]

counter.py:
'http://' + self.ip_address +':8084/rest/channel/(meter0|_sum)/' + '(ActivePower.*|VoltageL.|Frequency|Grid.+ActiveEnergy)'

[ { "address": "meter0/ActivePowerL3", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "W", "value": 6141 }, { "address": "meter0/ActivePower", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "W", "value": 17189 }, { "address": "meter0/ActivePowerL1", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "W", "value": 5575 }, { "address": "meter0/ActivePowerL2", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "W", "value": 5473 }, { "address": "meter0/VoltageL1", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "mV", "value": 229500 }, { "address": "meter0/VoltageL2", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "mV", "value": 229300 }, { "address": "meter0/VoltageL3", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "mV", "value": 229300 }, { "address": "meter0/Frequency", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "mHz", "value": 50000 }, { "address": "_sum/GridSellActiveEnergy", "type": "LONG", "accessMode": "RO", "text": "", "unit": "Wh_Σ", "value": 11752059 }, { "address": "_sum/GridBuyActiveEnergy", "type": "LONG", "accessMode": "RO", "text": "", "unit": "Wh_Σ", "value": 1088853 } ]
bat.py:
"http://" + self.ip_address + ":8084/rest/channel/(ess0|_sum)/" + "(Soc|DcChargeEnergy|DcDischargeEnergy|GridActivePower|ProductionActivePower|ConsumptionActivePower)"

[ { "address": "_sum/ConsumptionActivePower", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "W", "value": 17183 }, { "address": "_sum/ProductionActivePower", "type": "INTEGER", "accessMode": "RO", "text": "Total production; always positive", "unit": "W", "value": -9 }, { "address": "_sum/GridActivePower", "type": "INTEGER", "accessMode": "RO", "text": "Grid exchange power. Negative values for sell-to-grid; positive for buy-from-grid", "unit": "W", "value": 17164 }, { "address": "ess0/Soc", "type": "INTEGER", "accessMode": "RO", "text": "", "unit": "%", "value": 6 }, { "address": "ess0/DcChargeEnergy", "type": "LONG", "accessMode": "RO", "text": "", "unit": "Wh_Σ", "value": 3013394 }, { "address": "ess0/DcDischargeEnergy", "type": "LONG", "accessMode": "RO", "text": "", "unit": "Wh_Σ", "value": 3202108 } ]

@LKuemmel
Copy link
Contributor

LKuemmel commented Jan 2, 2024

Sorry, ich habe mich lange nicht gemeldet. Ich habe die Tests erstellt bzw angepasst und war so frei, sie in Deinen Branch zu pushen. Danke für deine Beispieldaten!

@LKuemmel LKuemmel merged commit 3736fc0 into openWB:master Jan 2, 2024
1 check passed
@@ -20,7 +20,8 @@ def update(self, session: Session) -> None:
else:
data = "ess2"
response = session.get(
"http://" + self.ip_address + ":8084/rest/channel/"+data+"/(Soc|DcChargeEnergy|DcDischargeEnergy)",
"http://" + self.ip_address + ":8084/rest/channel/(" + data + "|_sum)/" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this change breaks queries on older FEMS versions.

At least on my FEMS v 2022.12.5 a query with Regex in any "segment" other than the last one is NOT supported. FEMS just returns:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://<IP>:8084/rest/channel/(meter0%7C_sum)/(ActivePower.*%7CVoltageL.%7CFrequency%7CGrid.+ActiveEnergy)

I also see the optimization done here. But I might not be the only one with older version. Actually I have no control on if and when Fenecon updates my FEMS.

So I have no other idea but reverting this!

dj3mu added a commit to YourCharge/openWBcore that referenced this pull request Jan 11, 2024
At least older FEMS seem not to support Regex in any path fragment other than the very last one.
@dj3mu dj3mu mentioned this pull request Jan 11, 2024
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

Successfully merging this pull request may close these issues.

3 participants