EcoFlow: monitoring with Prometheus and Grafana

By | 07/07/2024
 

In continuation of the topic with Підготовка до зими 2024-2025: ДБЖ, інвертори, та акумулятори (in Ukrainian).

Surprise – there’s even a Prometheus exporter for the EcoFlow – berezhinskiy/ecoflow_exporter!

It looks really cool. I launched it, looked at it, and ran to write this post.

It can be run in a couple of clicks with Docker Compose, the file is included with the exporter.

How does it work?

It turns out that EcoFlow has a mqtt.ecoflow.com service where devices send telemetry. I didn’t find it in my mobile app, but I googled this screenshot in the Home Automation – My Journey thread:

That is, when we register a device in the mobile application, EcoFlow starts sending metrics using the login/password that we use to register in the application itself.

And the export itself works by the same logic, see the code in the ecoflow_exporter.py file: we set our login-password in the parameters (not banking, so we can do it), that it connects to the api.ecoflow.com/auth/login with this login-password, gets a token, and with this token goes to mqtt.ecoflow.com:8883.

And from the mqtt.ecoflow.com, we get a bunch of interesting metrics, which we will look at today.

Running the EcoFlow Prometheus Exporter

Everything is simple here, and is described in the Quick Start documentation.

Clone the repository:

$ git clone https://github.com/berezhinskiy/ecoflow_exporter
$ cd ecoflow_exporter/docker-compose/

In the compose.yaml file, set the logins and passwords: any desired for Grafana, and for the EcoFlow API (these, which you’ve set when installed your EcoFlow application on mobile):

...
  grafana:
    image: grafana/grafana
    container_name: grafana
    ports:
      - 3000:3000
    restart: unless-stopped
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: "admin"
    volumes:
      - ./grafana:/etc/grafana/provisioning/datasources
      - grafana_data:/var/lib/grafana

  ecoflow_exporter:
    image: ghcr.io/berezhinskiy/ecoflow_exporter
    container_name: ecoflow_exporter
    ports:
      - 9091:9091
    restart: unless-stopped
    environment:
      DEVICE_SN: DAEBZ5KF1183072
      ECOFLOW_USERNAME: [email protected]
      ECOFLOW_PASSWORD: "MyPassword"
      EXPORTER_PORT: 9091
...

In DEVICE_SN, specify the serial number of the device – it is displayed in the mobile application:

And launch the containers:

$ docker-compose up

Grafana dashboard

Log in to Grafana, go to http://localhost:3000/dashboards, import the dashboard with the ID 17812:

And we have a lot of interesting graphs:

For example, when I turned off the refrigerator, the battery Discharging Remain Time immediately increased from 8 to 16 hours:

Or the moment when the power came back to the apartment, and the batteries started charging:

As we calculated in the previous post – having a load of 1270 watt/hour and 56 volt batteries – we have 22.6 amps of current – 19 in the metrics of the BMS (Battery Management System) board, and another 3 amps, apparently, for the inverter and other systems of the station.

At the same time, the current from the socket is 5.7 amps (the Current graph):

>>> 1270/220
5.7

Temperature metrics are also interesting:

The inverter heats up to 80 C degrees when running on batteries, even though it’s +25 on the balcony (there’s a separate thermometer near the chargers).

And as soon as the power came on in the apartment, and the station turned off the battery power (and, accordingly, the inverter), the temperature dropped.

Although the inverter might be running all the time if EcoFlow is an Online UPS (see UPS types), but with a lower load. But it seems to me that EcoFlow is still a Line-Interactive system.

A full list of metrics is available in the exporter documentation, though without details. The default metrics are from EcoFlow itself, just with names converted : bms_bmsStatus.maxCellTemp -> bms_bms_status_max_cell_temp.

Alerts in Telegram

With the Prometheus Alertmanager, we can have alerts just everywhere, but for the EcoFlow home stations, I’d better use the Telegram, as I’m always have it running on my laptop/mobile.

Alerts are sent via the Telegram API and a bot whose token can be set in the Alertmanager configuration file alertmanager/alertmanager.yml, and the alerts themselves are described in the file prometheus/alerts/ecoflow.yml – we can tweak them here or write our own.

Create a bot using @BotFather and the /newbot command:

Create a channel:

Add the bot to the channel:

Find the Telegram Group Chat ID.

The easiest way I’ve found is through web.telegram.org – open the channel, and at the top you’ll have the ID:

We can send directly from the bot to our user – then specify our user’s ID in the chat_id field.

If you use a group, then the ID has to be set together with the “-” sign, i.e. in my case it is “-1002162514981“.

Edit the file alertmanager.yml, add parameters for Telegram:

...
receivers:
  - name: telegram
    telegram_configs:
    - bot_token: "745***AJM"
      chat_id: -1002162514981
      api_url: https://api.telegram.org
      message: '{{ template "telegram.template" . }}'
      parse_mode: MarkdownV2

To test alerts, we can change the condition in ecoflow.yml:

groups:
- name: EcoFlow
  rules:
    - alert: EcoFlowOffline
      expr: ecoflow_online == 0
...

To the ecoflow_online != 0.

Restart the containers with docker compose restart or just by exiting and running it again, and check the Alerts page in the Prometheus – http://localhost:9090/alerts:

The alert was triggered.

If you sent a message from the bot to yourself as a user, then find the bot, and click on the Send Message to initiate a chat, because the bot itself will not be able to write to you first – in the Alertmanager logs, you will see the error “bot can’t initiate conversation with a user“:

And immediately we get an alert message from the bot:

If you did it through a Telegram group (I did, so my wife also will be able to get notifications on low battery), the alert will immediately come there:

In general, it makes sense to check the alerts, for example, the EcoFlowHalfBattery alert has the ecoflow_bms_bms_status_f32_show_soc metric used, which is empty for me – check on the page http://localhost:9090/graph:

However, there is the ecoflow_bms_master_soc metric from Grafana:

Therefore, the alert can be rewritten as:

- alert: EcoFlowHalfBattery
  expr: ecoflow_bms_master_soc < 50
  ...

And that’s basically it.

Then you can run it all locally with autostart via systemd, or run it somewhere on a Raspberry Pi.