Skip to content

Instantly share code, notes, and snippets.

@ndfred
Last active August 17, 2023 11:31
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ndfred/5bb51b567f8cfaf2bb06da6393169321 to your computer and use it in GitHub Desktop.
Save ndfred/5bb51b567f8cfaf2bb06da6393169321 to your computer and use it in GitHub Desktop.

⚠️ There is now an official way to connect Glow to Home Assistant via MQTT, I would suggest using that instead of the method described below. Here are the sensor templates for that (replace GLOW_DEVICE_ID with the relevant information for your device):

mqtt:
  sensor:
    - name: "Home Power"
      state_topic: "glow/GLOW_DEVICE_ID/SENSOR/electricitymeter"
      unit_of_measurement: 'W'
      value_template: "{{ (value_json['electricitymeter']['power']['value'] * 1000) | int }}"
      icon: 'mdi:flash'

    - name: "Home Energy"
      state_topic: "glow/GLOW_DEVICE_ID/SENSOR/electricitymeter"
      unit_of_measurement: 'kWh'
      state_class: 'total_increasing'
      device_class: 'energy'
      unique_id: 'home_energy'
      value_template: "{{ value_json['electricitymeter']['energy']['import']['cumulative'] }}"

    - name: "Home Daily Energy"
      state_topic: "glow/GLOW_DEVICE_ID/SENSOR/electricitymeter"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['electricitymeter']['energy']['import']['day'] }}"
      icon: 'mdi:flash'

    - name: "Home Gas"
      state_topic: "glow/GLOW_DEVICE_ID/SENSOR/gasmeter"
      unit_of_measurement: 'm³'
      state_class: 'total_increasing'
      device_class: 'gas'
      unique_id: 'home_gas'
      value_template: "{{ value_json['gasmeter']['energy']['import']['cumulativevol'] }}"

    - name: "Home Daily Gas"
      state_topic: "glow/GLOW_DEVICE_ID/SENSOR/gasmeter"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['gasmeter']['energy']['import']['day'] }}"
      icon: 'mdi:flash'

Here is a way to expose most of the Glow Display MQTT information to home assistant through templates. Please make sure you ask Hildebrand support to enable your account for MQTT access before setting everything up.

The first step is to connect Home Assistant to MQTT. If you don't have your own broker hooked up yet, go ahead and set it up (I would suggest using the Integrations UI) and specify your Glow username and password as well as glowmqtt.energyhive.com as the server and 8883 as the port to make sure we're establishing a secure SSL connection.

If you already have your own MQTT server hooked up to Home Assistant, like I do, you will have to set up a bridge between your MQTT server and the Glow one, after that your server will mirror the MQTT messages from the Glow server. You have to do this because Home Assistant does not support connecting to more than one MQTT server.

I will assume you are using Mosquitto as an MQTT server. Start by creating a file named /etc/mosquitto/conf.d/glow.conf with the following content (replace GLOW_USERNAME, GLOW_PASSWORD and GLOW_DEVICE_ID with your relevant information):

connection glowmqtt
address glowmqtt.energyhive.com:8883
remote_username GLOW_USERNAME
remote_password GLOW_PASSWORD
bridge_capath /etc/ssl/certs/
topic SMART/HILD/GLOW_DEVICE_ID in 0

Once that is done, just restart Mosquitto to reload its configuration:

sudo systemctl restart mosquitto

Now you should be able to see your Glow messages over MQTT by using your client of choice.

If that works all right, you can open the Home Assistant configuration.yaml file (for me it is located at /home/homeassistant/.homeassistant/configuration.yaml) and add these new sensors under the sensor section (replace GLOW_DEVICE_ID with the relevant information for your device):

mqtt:
  sensor:
    - name: "Home Power"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'W'
      value_template: "{{ value_json['elecMtr']['0702']['04']['00']|int(base=16) }}"
      icon: 'mdi:flash'

    - name: "Home Energy"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      state_class: 'total_increasing'
      device_class: 'energy'
      unique_id: 'home_energy'
      value_template: "{{ value_json['elecMtr']['0702']['00']['00']|int(base=16) * value_json['elecMtr']['0702']['03']['01']|int(base=16) / value_json['elecMtr']['0702']['03']['02']|int(base=16) }}"

    - name: "Home Daily Energy"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['elecMtr']['0702']['04']['01']|int(base=16) * value_json['elecMtr']['0702']['03']['01']|int(base=16) / value_json['elecMtr']['0702']['03']['02']|int(base=16) }}"
      icon: 'mdi:flash'

    - name: "Home Weekly Energy"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['elecMtr']['0702']['04']['30']|int(base=16) * value_json['elecMtr']['0702']['03']['01']|int(base=16) / value_json['elecMtr']['0702']['03']['02']|int(base=16) }}"
      icon: 'mdi:flash'

    - name: "Home Monthly Energy"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['elecMtr']['0702']['04']['40']|int(base=16) * value_json['elecMtr']['0702']['03']['01']|int(base=16) / value_json['elecMtr']['0702']['03']['02']|int(base=16) }}"
      icon: 'mdi:flash'

    - name: "Home Gas"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'm³'
      state_class: 'total_increasing'
      device_class: 'gas'
      unique_id: 'home_gas'
      value_template: "{{ value_json['gasMtr']['0702']['00']['00']|int(base=16) * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"

    - name: "Home Daily Gas"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['gasMtr']['0702']['0C']['01']|int(base=16)  * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
      icon: 'mdi:flash'

    - name: "Home Weekly Gas"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['gasMtr']['0702']['0C']['30']|int(base=16)  * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
      icon: 'mdi:flash'

    - name: "Home Monthly Gas"
      state_topic: "SMART/HILD/GLOW_DEVICE_ID"
      unit_of_measurement: 'kWh'
      value_template: "{{ value_json['gasMtr']['0702']['0C']['40']|int(base=16)  * value_json['gasMtr']['0702']['03']['01']|int(base=16) / value_json['gasMtr']['0702']['03']['02']|int(base=16) }}"
      icon: 'mdi:flash'

If you would like to set up the energy dashboard, pick Home Energy for electricity and Home Gas for gas.

Now restart your Home Assistant instance, and you should be good to go! All the sensors should appear in the developer tools menu, for instance sensor.home_instant_energy, and update in real time.

If you'd like to play with the MQTT API, you can also check out my python code to connect and fetch data directly from the MQTT server.

@ndfred
Copy link
Author

ndfred commented Aug 15, 2022

It’s been a while since I have checked in here, nice to see people are still fixing issues!

I’ll refresh my config soon and expect to make the following changes, let me know if there is anything else you’d like to see or stuff I should know about:

  • share my energy dashboard configuration which took WAY too long to set up properly
  • leverage the new local MQTT connection to hopefully improve privacy / latency / resilience
  • filter out spikes and invalid values in the gas measurements in particular

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment