A taste of things to come? - UK smart meter data access

@borpin
That’s why I went for second option (Home Assistant Glow), 2xphotodiode, 2xesp32 and 2xRGB led - for electric and gas. £12,70 delivered. I don’t know how I am getting it installed nor if it is going to work (especially with gas meter), but I am not breaking a bank here. Probably another HA project that will end up unfinished, oh well.

But that is a poor substitute and will not work for a Gas meter - no flashing diode. I’ve got a photo measurement (as well as other OEM kit) but that is irrelevant.

Agreed

I thought the installers were supposed to test for correct operation of both the meter and IHD when they started installing, and in the case of problems to refer it for a more advanced solution?

OEM already offers a sensor to read the diode on meters; no need to use something else. The only problem is what the light means can depend on the configuration of the meter. At least with old-fashioned meters, I’ve no idea if things are any better with smart meters. How do they distinguish between import and export?

@borpin @djh
Did not notice, gas meter doesn’t have flashing led. Make sense, since it would decrease battery life I guess. But I was also hoping leds on HAN device indicate electricity AND gas. I know it is far from average solution (to say at least). Having port would make things so much easier.
And yes, I know, in 99% I spent those 12 quid for nothing.

@DanielKenning

My GlowStick has been running without problems for 12 months.
It’s located in a utility room close to the smart meter on an outside wall.
It’s plugged into a USB port of a Raspberry Pi just for convenience and to power it.
The data comes via wifi & MQTT.
The RPi runs the emon system.

I spent many hours getting things running as I was new to MQTT - you may find my Python script useful …

# PURPOSE: To input Smart Meter data into emoncms (data obtained via a Hildebrand Glow Stick https://www.hildebrand.co.uk/our-products/glow-stick-wifi-cad/ )

# With due acknowledgement to ndfred - a contributor to the Glowmarkt forum
# https://gist.github.com/ndfred/b373eeafc4f5b0870c1b8857041289a9

# Developed and tested on a Raspberry Pi running the Oct 2019 emon image updated to ver 10.2.6

# HOW TO ...

# IMPORTANT - Install mosquitto-clients with: sudo apt-get install mosquitto-clients    XXXXXXXXXXXXX !!!!!!!!!

# The script will create an INPUT node to receive the data

# Copy this script file to  /home/pi  and make it executable with:  chmod +x /home/pi/JB-glowmqtt.py  # using the correct script name

# Run the script with: /usr/bin/python3 /home/pi/JB-glowmqtt.py  # using the correct script name

# All being well, Smart meter data will appear in emoncms webpage Inputs refreshing every 10 secs - Power Now(W) and Daily & CUM Energy(kWh)

# Create FEEDS using Log to Feed and add UNITS (pencil drop-down) to each

# IMPORTANT NOTE ...
# Data from this script is input to emoncms via an http API.  This bypasses emonhub ...
# The EmonHubEmoncmsHTTPinterfacer is not required

# FINALLY ONCE THE SCRIPT RUNS OK: Create the glow.service and enable it so the script runs on boot up as follows:
# Do: CTRL-C to stop the script then - Do: sudo nano /etc/systemd/system/glow.service  and copy & paste in the following BUT adjust the script name ...

"""

[Unit]
Description=Glow Stick service
After=network.target
After=mosquitto.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=pi
ExecStart=/usr/bin/python3 /home/pi/JB-glowmqtt.py

[Install]
WantedBy=multi-user.target

"""
# Then save & exit and to ensure the glow.service runs on boot up - Do:  sudo systemctl enable glow.service

# AS A VERY LAST CHECK - Do: sudo reboot then SSH in again and check the service status with:  systemctl status glow.service

# Finally close the SSH terminal and the script/service will continue to run surviving any future reboots

# ===============================================================================

import datetime
import logging
import json
import paho.mqtt.client as mqtt    # paho-mqtt is already installed in emon
import requests    

# Glow Stick configuration
GLOW_LOGIN = "~~~~~~~~~"
GLOW_PASSWORD = "~~~~~~~~~~~"
GLOW_DEVICE_ID = "~~~~~~~~~~~"   # This is the MAC address of the GlowStick

# Emoncms server configuration
emoncms_apikey = "~~~~~~~~~~~~~~~"   # for Node 15 - change as appropriate
emoncms_server = "http://127.0.0.1"
node = "Glow Stick"  # Name of the node created to receive the INPUT data 

# Name each of the data inputs associated with the newly created node
di1 = "Power Now"      # ref E_NOW below
di2 = "Daily Energy"   # ref E_DAY below
di3 = "CUM Energy"     # ref E_METER below


def on_connect(client, _userdata, _flags, result_code):
    if result_code != mqtt.MQTT_ERR_SUCCESS:
        logging.error("Error connecting: %d", result_code)
        return

    result_code, _message_id = client.subscribe("SMART/HILD/" + GLOW_DEVICE_ID)

    if result_code != mqtt.MQTT_ERR_SUCCESS:
        logging.error("Couldn't subscribe: %d", result_code)
        return

    logging.info("Connected and subscribed")

def on_message(_client, _userdata, message):
    payload = json.loads(message.payload)
    current_time = datetime.datetime.now().strftime("%H:%M:%S")
	
    electricity_consumption = int(payload["elecMtr"]["0702"]["04"]["00"], 16)

    if electricity_consumption > 10000000: electricity_consumption = electricity_consumption - 16777216 # Added JB - hex FFFFFF is 16777215 in unsigned 24 bit but -1 in signed 24 bit
    E_NOW = electricity_consumption   # Added JB

    electricity_daily_consumption = int(payload["elecMtr"]["0702"]["04"]["01"], 16)
	
    # electricity_weekly_consumption = int(payload["elecMtr"]["0702"]["04"]["30"], 16)  # Data not provided by GLOW
    # electricity_monthly_consumption = int(payload["elecMtr"]["0702"]["04"]["40"], 16)  # Data not provided by GLOW
    electricity_multiplier = int(payload["elecMtr"]["0702"]["03"]["01"], 16)
    electricity_divisor = int(payload["elecMtr"]["0702"]["03"]["02"], 16)
    electricity_meter = int(payload["elecMtr"]["0702"]["00"]["00"], 16)

    electricity_daily_consumption = electricity_daily_consumption * electricity_multiplier / electricity_divisor
    E_DAY = electricity_daily_consumption     # Added JB
	
    # electricity_weekly_consumption = electricity_weekly_consumption * electricity_multiplier / electricity_divisor
    # electricity_monthly_consumption = electricity_monthly_consumption * electricity_multiplier / electricity_divisor
    electricity_meter = electricity_meter * electricity_multiplier / electricity_divisor
    E_METER = electricity_meter     # Added JB                               
	
    assert(int(payload["elecMtr"]["0702"]["03"]["00"], 16) == 0) # kWh
    
    logging.info("Reading at %s", current_time)
    logging.info("electricity consumption: %dW", electricity_consumption)
    logging.info("daily electricity consumption: %.3fkWh", electricity_daily_consumption)
    # logging.info("* weekly electricity consumption: %.3fkWh", electricity_weekly_consumption)
    # logging.info("* monthly electricity consumption: %.3fkWh", electricity_monthly_consumption)
    logging.info("electricity meter: %.3fkWh", electricity_meter)
    
    # logging.info("Full payload: %s", json.dumps(payload, indent=2))   # Don't need this info printed
	                    	
    data1 = E_NOW
    data2 = E_DAY
    data3 = E_METER

    # Send data to emoncms

    dev_data = {di1: data1, di2: data2, di3: data3}

    data = {
      'node': node,
      'data': json.dumps (dev_data),
      'apikey': emoncms_apikey
    }

    response = requests.post(emoncms_server+"/input/post", data=data)
	
	
	
def loop():
    logging.basicConfig(level=logging.DEBUG, format='%(message)s')
    client = mqtt.Client()
    client.username_pw_set(GLOW_LOGIN, GLOW_PASSWORD)
    client.on_connect = on_connect
    client.on_message = on_message
    client.connect("glowmqtt.energyhive.com")
    client.loop_forever()

if __name__ == "__main__":
    loop()

The Input Processing I use to create Feeds is …

And here’s one view of the Feeds …

(The zero import thru’ the night is because the system hs a large battery installed)

My understanding of how things work is that the GlowStick intercepts the consumption data that is sent by mobile phone signal to the ‘central authority’ that then sends this data to yr supplier who bills you.
Hildebrand is authorised to do this by the ‘central authority’ but only with yr permission - hence the request for yr MPAN.

I recall struggling to get MQTT certification sorted - so this may also help …

I found I needed first to run …

$ curl "https://letsencrypt.org/certs/isrgrootx1.pem.txt" > cert.pem
Then …

$ curl "https://letsencrypt.org/certs/letsencryptauthorityx3.pem.txt" >> cert.pem
The cert.pem file ended up in   /home/pi   and so the connect statement then needed was …

mosquitto_sub --cafile /home/pi/cert.pem -h glowmqtt.energyhive.com -u ~~yr username~~ -P
~~~yr password~~~ -t SMART/HILD/~~~MACaddress~~~ -p 8883

My bottom line/editorial comment is - GlowStick is much easier than tryiing to use uni-directional CT clamps and the data it provides is revenue grade.

Hope this helps

1 Like

Thanks you - I’m sure it will help when I receive the Glowstick. I think this looks like a brilliant challenge for my son who’s into python… a good homework project!
Cheers,
Daniel

My understanding of how things work is that the GlowStick intercepts the consumption data that is sent by mobile phone signal to the ‘central authority’ that then sends this data to yr supplier who bills you.
Hildebrand is authorised to do this by the ‘central authority’ but only with yr permission - hence the request for yr MPAN.

Since I heard of Hildebrand for the first time, I thought their sticks (one for SMETS1 and another for SMETS2) are the only ones authorised to use Zigbee connection directly to smart meters, meaning there is no “middle man”, or as you call it “central authority”?

@Lucas_Ch

Is it a matter of semantics?
The following link is informative …

The ‘central authority’ I referred to is the Data and Communications Company (DCC)

And if Hildebrand is the only company authorised to intercept smart meter data then their GlowStick is a uniquely valuable product.

Which does beg the question - how do the many different types of In Home Displays work?

@johnbanks
But the difference is huge.
They way I understand it, GlowStick from Hildebrand connects directly to smart meter HAN zigbee network, same way as IHD does. Meaning, that when you put kettle on, IHD display goes to “red” within 2 seconds (so basically shows real time electricity consumption). And if GlowStick is connected the same way, it will also send consumption data in real time (to their Bright app, not DCC).
But when you work through “central authority”, the minimum time you can get up-to-date data is 30 minutes.
And don’t get me wrong, I think device is great.

@DanielKenning

And whilst you’re waiting for yr son to succeed with the Python project, you’ll be able to use Hildebrand’s Bright App on yr mobile phone which is very informative.

@Lucas_Ch

You are correct - the GlowStick immediately responds when you put the kettle on (using yr example).

Apologies if my earlier post could be interpreted as suggesting GlowStick got it’s data from DCC.
I was just trying to emphasise that the GlowStick minute by minute data is revenue grade - the same data that when accumulated into 30 min chunks eventually results in yr monthly bill from yr suppllier.

@johnbanks
Yes, at first that was my interpretation. Sorry if I read it wrong.

Question for you though… GlowStick allows you (well, Hildebrand allows you) to set MQTT. But where? Can you set MQTT server locally, i.e. Raspberry Pi? My guess is no, they set it up on their end?

And if Hildebrand is the only company authorised to intercept smart meter data then their GlowStick is a uniquely valuable product.

Well, n3rgy does the same (intercepts data), just without the stick. :wink: And yes again, definitely a valuable product.

@Lucas_Ch

Yr question - "Can you set MQTT server locally, i.e. Raspberry Pi? "
.
My answer - Pls see my earlier very long post. I’m getting the data into my Raspberry Pi. The data does come from Hildebrand as I understand it. So, I guess, if Hildebrand no longer existed then there would be no data - very much a guess on my part. It does not keep me awake at night tho’.

I have no knowledge of n3rgy.
Is their data capable of being captured by a Raspberry Pi?
Is it electricity supplier agnostic?
Does it rely long term on n3rgy continuing to exist?
I would like to know more about n3rgy.

@johnbanks
I am no programmer, but from the code in your post, it looks like communication seems to be over the internet (between GlowStick → Hildebrand servers → emon software installed on Raspberry Pi, hence certificate requirements), so technically, if Hildebrand gone bust, you would no longer be able to monitor you data.

I have no knowledge of n3rgy.
Is their data capable of being captured by a Raspberry Pi?

Any device really, where you can run software to capture data

Does it rely long term on n3rgy continuing to exist?

Yes, same as Hildebrand in my opinion.

But the minimum data rate here is 30mins.

Where did you get emon software from? Or more precisely… who gave you instructions how to install it/set it up?

Has anyone tried signing up to the free Hildebrand smart meter data service (data coming over metering system rather than via CAD):

https://glowmarkt.com/

I tried to get it working yesterday but it errored out for me.

@beaylott
Their Bright App works well but I THINK it relies on having a GlowStick installed.
You could always pose the question to their Support team.

@Lucas_Ch
Re:

Where did you get emon software from? Or more precisely… who gave you instructions how to install it/set it up?

As my script states, it is built around code from ndfred, a contributor to the Glowmarkt forum:

# With due acknowledgement to ndfred - a contributor to the Glowmarkt forum
# https://gist.github.com/ndfred/b373eeafc4f5b0870c1b8857041289a9

In crude terms that copy & paste got the data published to MQTT. I then added my code around that to get the data into emon. I’m no programmer - it took many hours of learning in lockdown time.

The problem of Certification was solved via an email exchange with Hildebrand support.

@beaylott

Has anyone tried signing up to the free Hildebrand smart meter data service (data coming over metering system rather than via CAD):

https://glowmarkt.com/

I tried to get it working yesterday but it errored out for me.

I didn’t sign up. But I am very cautious when something says “FREE Try now” with a star, with no reference to it. :smiley: Probably I am too cautious.
What error did you get? I only tried putting my MPAN to check if I am eligible and I am. I have SMETS1 meter.
@johnbanks

Their Bright App works well but I THINK it relies on having a GlowStick installed.

It seems like you need GlowStick to use an app, but you can still get data without stick and app, but at slower rate (30mins). That’s my understanding.

In crude terms that copy & paste got the data published to MQTT.

The reason I asked, I found this info, where (somehow) Hildebrand can create MQTT access. If that was local (i.e Raspberry Pi) it would be 100% perfect solution (for me, anyway).

I am waiting for a Glowstick from Hildebrand, and the helpdesk there said I can install Bright anyway, and get the data on my phone. I installed Bright a couple of days ago, it says it’s “getting your app up and running” and promises I will be able to see my SMETS2 data in a day or two… all with no need to get permission form the electricity supplier (Good Energy).