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