ecoflow2db

package module
v0.0.0-...-2411c8f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

README

Ecoflow2db application

Introduction

This application named Ecoflow2db is used to query Ecoflow API getting current configuration and Solar data information and generate corresponding database tables in the Postgres database.

Ecoflow2db queries periodically data from all devices quota API calls and store the data. The data is display in Grafana as an example.

Current Ecoflow devices are in use at the moment:

  • Ecoflow Powerstream inverter
  • Ecoflow Delta 2

In advance the application can listen for MQTT events. Unfortunately the MQTT is only active during usage of the Ecoflow App on mobile phone or smartphone device. The corresponding handling is not implemented yet.

Environment variables

Variables Default Description
ECOFLOW_USER Ecoflow API user
ECOFLOW_PASSWORD Ecoflow API password
ECOFLOW_ACCESS_KEY Ecoflow access key created in Ecoflow API
ECOFLOW_SECRET_KEY Ecoflow secret key created in Ecoflow API
ECOFLOW_DB_URL Postgres database URL used to store data
ECOFLOW_DB_USER Postgres user name
ECOFLOW_DB_PASS Postgres user password
LOGPATH Directory for log trace file
ECOFLOW2DB_WAIT_SECONDS 30 Time in seconds waiting between a loop reading statistic data in Ecoflow API

Build

The ecoflow2db application is written in Golang. The tool can be build with

build.sh

Docker environment

The Ecoflow2db application and corresponding Postgres database is running in an Raspberry Pi.

Docker images are on Docker hub at

docker pull thknie/ecoflow2db:tagname

See the example script showing how to start the service with podman. Located is the script in this repostiory at docker/podstart.sh.

Usage in Grafana

In Grafana accessing the data source containing the data received by two input sources

  • First sources comes from mqtt2db. This tool receives Tasmota electric meter data using an Mosquitto MQTT server and store it in database
  • Second sources comes from ecoflow2db using the Ecoflow API receiving Solar panel and inverter statistics and store it in the same database

Both data are containing a wide range of statistic data which can be presented inside an Grafana Dashboard:

Grafana Dashboard example

Grafana Dashboard example


These tools are provided as-is and without warranty or support. Users are free to use, fork and modify them, subject to the license agreement.

Documentation

Index

Constants

View Source
const DefaultIntermediateSize = 15
View Source
const DefaultLoopSeconds = 120
View Source
const DefaultMaxTries = 120
View Source
const DefaultSeconds = 60
View Source
const SELECT_GET_ALL_PARAMETER = `` /* 1708-byte string literal not displayed */

Variables

View Source
var BuildDate string

BuildDate build date

View Source
var BuildVersion = "vDevelopment"

BuildVersion build version

View Source
var CloseIfStuck = false
View Source
var FlowLoopSeconds = DefaultSeconds
View Source
var LoopSeconds = DefaultSeconds
View Source
var MqttDisable = false
View Source
var OutLoopSeconds = DefaultLoopSeconds
View Source
var StatLoopMinutes = time.Duration(5)
View Source
var Version string

Version component version

Functions

func AnalyzeEnergyHistory

func AnalyzeEnergyHistory(lastLimitEntries []*parameter, test bool)

func Callback

func Callback(serialNumber string, data map[string]interface{})

func FormatByteBuffer

func FormatByteBuffer(header string, b []byte) string

FormatByteBuffer formats the byte array to an output with a hexadecimal part, a ASCII part and a EBCDIC converted part of the same data

func FormatBytes

func FormatBytes(header string, b []byte, bufferLength int, modSpace int, max int, showLength bool) string

FormatBytes formats a given byte array and modulo space operator. The modulo space defines the the possition a space is added to the output. The maximum give the maximum characters per line. This function enhance the display with showing the length if showLength is set to true

func InitDatabase

func InitDatabase()

InitDatabase init database connections

func InitEcoflow

func InitEcoflow()

InitEcoflow init ecoflow MQTT

func InitMqtt

func InitMqtt(user, password string)

InitMqtt initialize MQTT listener

func ListDevices

func ListDevices()

func LoadConfig

func LoadConfig(file string)

func ReadCurrentFlow

func ReadCurrentFlow() ([]*parameter, error)

func SetCarACOn

func SetCarACOn(sn string, turnOn bool)

func SetEnvironmentPowerConsumption

func SetEnvironmentPowerConsumption(value float64)

func StartFlow

func StartFlow(test bool)

Types

type MQTTWrapperLogger

type MQTTWrapperLogger struct {
}

func (*MQTTWrapperLogger) Printf

func (l *MQTTWrapperLogger) Printf(format string, v ...interface{})

func (*MQTTWrapperLogger) Println

func (l *MQTTWrapperLogger) Println(v ...interface{})

type Mapping

type Mapping []struct {
	Source      string `yaml:"source"`
	Destination string `yaml:"destination"`
	Type        string `yaml:"type"`
	IfNegative  string `yaml:"ifNegative,omitempty"`
}

type Topic

type Topic struct {
	Name    string  `yaml:"name"`
	Mapping Mapping `yaml:"mapping"`
}

func (*Topic) ParseMessage

func (topic *Topic) ParseMessage(x map[string]interface{}) map[string]interface{}

Directories

Path Synopsis
cmd
ecoflow2db command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL