My LaMetric LED Display

I’d just like to show you guys how I have set up my new LaMetric to show various data originating from my [Solar Photovoltaic Power Plant. Even though I know that there is an addon for this device in openHAB, I haven’t used it.

Video link

On the video you will see how my LaMetric is showing

  • Exported (sold) energy today so far…
  • Current PV production power
  • A notification from what’s playing on my sonos (it’s not made from my script)
  • Current power export to the grid
  • Current houshold energy usage
  • Nord Pool current hour energy spot price in SEK
  • Nord pool hourly prices today graph (FWIW)

As I like programming in Python (Jython) I made a simple script running using Helper Libraries for openHAB Scripted Automation.

This is not a tutorial but more an example what can be done.

Below is my jython script in case someone is interested to see how I did it. It won’t of course not work as it is on your system.

from logging import DEBUG, ERROR, INFO, WARNING
import json
import os

from core.rules import rule
from core.triggers import when
from core.utils import getItemValue, send_command_if_different

def formatPower(powerW):
    if powerW < 10000:
        return '{} W'.format(powerW)
    else:
        return '{} kW'.format(round(float(powerW) /1000, 1))

def formatEnergy(energyWh):
    if energyWh < 10:
        return '{} kWh'.format(round(float(energyWh), 1))
    else:
        return '{} kWh'.format(int(round(float(energyWh), 0)))

def formatSpotPrice(sek):
    if sek < 1.0:
        return '{} öre'.format(int(round(float(sek*100), 0)))
    else:
        return '{} kr'.format(round(float(sek), 0))

@rule("push2lametrics", description="Pushing messages to the LaMetrics Solar plant production and energy statistics app. https://developer.lametric.com/applications/app/21164", tags=[])
@when("Item KronorPerHour changed")
@when("System started")
def push2lametrics(event):
    headers = '-H "Accept: application/json" -H "X-Access-Token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ==" -H "Cache-Control: no-cache"'
    url = 'https://192.168.1.44:4343/api/v1/dev/widget/update/com.lametric.XXXXXXXXXXXXXXXXXX82/1'

    push2lametrics.log.setLevel(INFO)
    push2lametrics.log.debug('Pushing messages to the LaMetrics Solar plant production and energy statistics app')

    hourly_energy_revenue_num = round(getItemValue('KronorPerHour', 0.0), 2)
    hourly_energy_revenue_text = '{} KR'.format(hourly_energy_revenue_num)
    pv_num = getItemValue('P_Pv', 0)
    pv_text = formatPower(pv_num)
    grid_num = getItemValue('P_Grid', 0)
    grid_text = formatPower(abs(grid_num))
    load_num = getItemValue('P_Load', 0)
    load_text = formatPower(load_num)
    energy_day_num = getItemValue('E_Day', 0.0)
    energy_day_text = formatEnergy(energy_day_num)
    energy_price_nordpool_num = getItemValue('Energy_Price_Nord_Pool', 0.0)
    energy_price_nordpool_text = formatSpotPrice(energy_price_nordpool_num)

    energy_price_nordpool_hourly = []
    for i in range(0, 24):
        k = int(round(float(getItemValue('Energy_Price_Day1_Hour0{}'.format(i) if i < 10 else 'Energy_Price_Day1_Hour{}'.format(i), 0.0) * 100), 0))
        energy_price_nordpool_hourly.append(k)

    payload = { 'frames': [] }
    index = 0
    if pv_num > 0:
        payload["frames"].append({'text': pv_text, 'icon': 'a27464' if pv_num > 0 else 'i34984', 'index': '{}'.format(index) }) # PV Production
        index = index + 1

    payload["frames"].append({'text': grid_text, 'icon': 'a7463' if grid_num > 0 else 'a7465', 'index': '{}'.format(index) }) # Grid power
    index = index + 1

    payload["frames"].append({'text': load_text, 'icon': 'a21256', 'index': '{}'.format(index) }) # Internal home power Usage
    index = index + 1

    payload["frames"].append({'text': energy_price_nordpool_text, 'icon': 'i35283', 'index': '{}'.format(index) }) # Nord Pool Energy spot price current hour
    index = index + 1

    payload["frames"].append({'chartData': energy_price_nordpool_hourly, 'index': '{}'.format(index) }) # Nord Pool Chart
    index = index + 1

    payload["frames"].append({'text': hourly_energy_revenue_text, 'icon': '30756' if hourly_energy_revenue_num > 0 else '30757', 'index': '{}'.format(index) }) # Hourly energy revenue or cost
    index = index + 1

    if energy_day_num > 0:
        payload["frames"].append({'text': energy_day_text, 'icon': 'a87', 'index': '{}'.format(index) }) # PV Energy generated today
        index = index + 1

    cmd = 'curl -X POST {} -d \'{}\' {} --insecure 1>/dev/null 2>&1 &'.format(headers, json.dumps(payload), url)

    push2lametrics.log.debug("cmd: {}".format(cmd))
    os.system(cmd)

Cheers!

6 Likes