Skip to main content
Version: Latest

Flows CLI Tools

The Flows platform provides powerful command-line tools through the simt-emlite package for interacting with meters and managing the communication infrastructure.

Installation

Install the Flows CLI tools via pip:

pip install simt-emlite

Requirements:

  • Python 3.13 or higher (< 4.0)
  • Network access to Flows infrastructure
  • Configuration files in ~/.simt/

Latest Version: 0.23.7 (PyPI)

CLI Tools Overview

The package provides two main CLI tools:

1. emop - Meter Operations

Direct interaction with Emlite meters via EMOP (Emlite Meter Operating Protocol)

2. mediators - Communication Management

Management of mediator servers that handle meter communications

Quick Start

Initial Setup

  1. Install the package:
pip install simt-emlite
  1. Create configuration directory:
mkdir -p ~/.simt
  1. Configure environment:
# Set your environment (prod, staging, or local)
emop env_set prod

# Verify configuration
emop env_show
  1. Test connection:
# List available meters and mediators
mediators list

# Check meter signal quality
emop csq EML2137580826

Common Operations

Check Meter Status

# Get prepayment balance
emop prepay_balance EML2137580826

# Check signal quality
emop csq EML2137580826

# Alternative using -s flag
emop -s EML2137580826 csq

# Read current tariff
emop tariffs_active_read EML2137580826

Update Tariffs

emop tariffs_future_write \
--from-ts "2025-01-01T00:00:00" \
--unit-rate "0.2798" \
--standing-charge "0.6556" \
--emergency-credit "15.00" \
EML2137580826

Send Prepayment Token

emop prepay_send_token EML2137580826 "12345678901234567890"

Manage Mediators

# List all mediators
mediators list

# Create mediator for meter
mediators create EML2137580826

# Start mediator
mediators start EML2137580826

# Check mediator status
mediators list --meter EML2137580826

Configuration

Environment File

Create ~/.simt/emlite.env:

# Database connection
DATABASE_URL=postgresql://user:pass@flows.simtricity.com:5432/flows

# API configuration
FLOWS_API_URL=https://api.flows.simtricity.com
JWT_SECRET=your-jwt-secret
API_TOKEN=your-api-token

# Environment selection
ENVIRONMENT=production # or development, staging

# Mediator settings
MEDIATOR_GRPC_PORT=50051
MEDIATOR_TIMEOUT=30

# Optional: Logging
LOG_LEVEL=INFO

DNS Configuration

For production access, configure DNS for wireguard if required:

# Add to /etc/hosts or configure DNS
<internal-ip-1> flows.simtricity.com
<internal-ip-2> mediators.simtricity.com

Environment Management

The CLI supports multiple environments:

# List available environments
emop env_list

# Switch environment
emop env_set staging

# Show current environment
emop env_show

Advanced Usage

Batch Operations

Process multiple meters efficiently:

#!/usr/bin/env python3
import subprocess
import json

meters = ["EML2137580826", "EML2137580827", "EML2137580828"]

for meter in meters:
# Get balance
result = subprocess.run(
["emop", "prepay_balance", meter],
capture_output=True,
text=True
)
balance = json.loads(result.stdout)
print(f"{meter}: £{balance['balance']:.2f}")

Profile Data Retrieval

Get historical consumption data:

# Get profile data for specific timestamp
emop profile_log_1 --timestamp 2024-07-19T00:00 EML2137580826

# Get latest profile
emop profile_log_latest EML2137580826

Error Handling

The CLI provides detailed error messages:

# Example with error handling
if ! emop prepay_balance EML2137580826; then
echo "Failed to read balance"
# Check mediator status
mediators list --meter EML2137580826
fi

Troubleshooting

Connection Issues

  1. Check environment configuration:
emop env_show
  1. Verify mediator is running:
mediators list --meter EML2137580826
  1. Test network connectivity:
nc -zv flows.simtricity.com 5432

Permission Errors

Ensure your API token has appropriate permissions:

# Test with explicit token
export API_TOKEN=your-token
emop list

Timeout Issues

Adjust timeout in configuration:

export MEDIATOR_TIMEOUT=60  # Increase to 60 seconds
emop prepay_balance EML2137580826

Command Reference

emop Commands

Commands can be used with serial as positional argument (emop COMMAND SERIAL) or with -s flag (emop -s SERIAL COMMAND).

CommandDescriptionExample
csqSignal qualityemop csq EML2137580826
serial_readRead meter serialemop serial_read EML2137580826
clock_time_readCurrent meter clockemop clock_time_read EML2137580826
instantaneous_voltageCurrent voltageemop instantaneous_voltage EML2137580826
readCurrent meter readingemop read EML2137580826
read_element_aElement A readingemop read_element_a EML2137580826
read_element_bElement B readingemop read_element_b EML2137580826
prepay_balanceGet current balanceemop prepay_balance EML2137580826
prepay_send_tokenApply tokenemop prepay_send_token EML2137580826 12345678901234567890
tariffs_active_readCurrent tariffemop tariffs_active_read EML2137580826
tariffs_future_readFuture tariffemop tariffs_future_read EML2137580826
tariffs_future_writeUpdate tariffemop tariffs_future_write --unit-rate 0.28 EML2137580826
profile_log_1 to profile_log_8Get profile dataemop profile_log_1 --timestamp 2024-07-19 EML2137580826
backlightRead backlight settingemop backlight EML2137580826
load_switchRead load switch settingemop load_switch EML2137580826
prepay_enabledCheck prepay modeemop prepay_enabled EML2137580826
env_setSet environmentemop env_set prod
env_showShow environmentemop env_show

mediators Commands

CommandDescriptionExample
listList mediatorsmediators list
list --escoFilter by ESCOmediators list --esco wlce
list --existsFilter by existencemediators list --exists False
createCreate mediatormediators create EML2137580826
destroyRemove mediatormediators destroy EML2137580826
startStart mediatormediators start EML2137580826
stopStop mediatormediators stop EML2137580826
restartRestart mediatormediators restart EML2137580826
logsView logsmediators logs EML2137580826
env_setSet environmentmediators env_set prod

Integration Examples

Python Script Integration

from simt_emlite import MeterClient

# Initialize client
client = MeterClient(environment="production")

# Get meter
meter = client.get_meter("EML2137580826")

# Read balance
balance = meter.prepay_balance()
print(f"Current balance: £{balance:.2f}")

# Update tariff
meter.tariffs_future_write(
activation_datetime="2025-01-01T00:00:00",
unit_rate_a=0.2798,
standing_charge=0.6556
)

Shell Script Automation

#!/bin/bash

# Check all meter balances
for meter in $(emop list | jq -r '.[].serial'); do
balance=$(emop prepay_balance $meter | jq '.balance')
if (( $(echo "$balance < 5" | bc -l) )); then
echo "Low balance alert: $meter has £$balance"
fi
done

Best Practices

  1. Always check meter status before operations:
emop csq METER_SERIAL
  1. Use appropriate timeouts for slow networks:
export MEDIATOR_TIMEOUT=45
  1. Log important operations:
emop tariffs_future_write ... 2>&1 | tee -a /var/log/tariff-updates.log
  1. Handle errors gracefully in scripts:
if ! output=$(emop prepay_balance $meter 2>&1); then
echo "Error reading meter $meter: $output" >&2
exit 1
fi

Additional Resources