MQTT into Home Assistant

For me this is the holy grail, I have my LIVE SMETS-2 meter data (electricity usage and solar export) in Home Assistant. (I'm so excited! Big High Five and THANKYOU to all at Glow / Hildebrand who made this possible)

My Home Assistant knowledge in near minimal so I invite any HA experts to jump in and correct me, but for those at my level or below, this is how I got there:

A Glow IHD running v1.8.12 software (I believe you need V1.8.12 for MQTT support?)

Home Assistant 2022.6 (2022.6 this months release and has new support for MQTT)

The Mosquito MQTT Broker running on my Home Assistant hardware (its a standard add on see: settings/ add-ons)

MQTT is configured on the Glow IHD (very easy)

Optional: I have added the Visual Studio Code Server to HA (settings/ add-ons) or you use the File Editor add-on to edit the configuration.yaml file


You then need to "sense" the MQTT data in Home Assistant

The basic configuration is to edit configuration.yaml and add a section for mqtt (See below) and then you pickup/ use the sensor values as you want in the Home Assistant GUI

[The interface for this forum is basic so the indent spacing in the following may be mangled]

The following demonstrates picking up the Glow data from MQTT

mqtt:

sensor:

  - name: "Metered Current Consumption"

    state_topic: "glow/441793504B6D/SENSOR/electricitymeter" #Need SECRET

    unit_of_measurement: "kW"

    value_template: "{{ value_json.electricitymeter.power.value | round(1) }}"

    device_class: energy

    state_class: total_increasing

  - name: "Metered Export Reading"

    state_topic: "glow/441793504B6D/SENSOR/electricitymeter" #Need SECRET

    unit_of_measurement: "kWh"

    value_template: "{{ value_json.electricitymeter.energy.export.cumulative | round(1) }}"

    device_class: energy

    state_class: total_increasing

  - name: "Metered Import Reading"

    state_topic: "glow/441793504B6D/SENSOR/electricitymeter" #Need SECRET

    unit_of_measurement: "kWh"

    value_template: "{{ value_json.electricitymeter.energy.import.cumulative | round(1) }}"

    device_class: energy

    state_class: total_increasing

  - name: "Metered Unit Price"

    state_topic: "glow/441793504B6D/SENSOR/electricitymeter" #Need SECRET

    unit_of_measurement: "GBP"

    value_template: "{{ value_json.electricitymeter.energy.import.price.unitrate | round(3) }}"

  # Glow Device State Info

  - name: "Glow Han Status"

    state_topic: "glow/441793504B6D/STATE"

    value_template: "{{ value_json.han.status }}"

  - name: "Glow Han RSSI"

    state_topic: "glow/441793504B6D/STATE"

    value_template: "{{ value_json.han.rssi }}"

    unit_of_measurement: "dBm"

  - name: "Glow Software Version"

    state_topic: "glow/441793504B6D/STATE"

    value_template: "{{ value_json.software }}


Tips:

You can check the syntax of your yaml is correct from: developer tools / yaml / configuration validation

You can quickly (re)load the MQTT sensor(s) from developer tools / yaml / YAML config reloading / Manually configured MQTT entities

More/ Advanced:

If you are worried about sharing your config files and the ID of your glow device you can uses secrets.yaml and some thing like:

state_topic: !secret glow_MQTT_topic_electricitymeter

where glow_MQTT_topic_electricitymeter

is

glow_MQTT_topic_electricitymeter: "glow/441793504B6D/SENSOR/electricitymeter"

HA Experts: Anything I can do better, please?

Comments

  • Sorry I forgot to add something about the MQTT topic.

    in the line:

    state_topic: "glow/441793504B6D/SENSOR/electricitymeter"

    I believe 441793504B6D is the id for the Glow device. You will need an MQTT client or similar to get the exact topic name your device is using.

  • @glider51

    [The interface for this forum is basic so the indent spacing in the following may be mangled]

    you can use the 3 backticks to insert code.

    1. value_template: "{{ value_json.electricitymeter.power.value | round(1) }}"

    Why do you round this? It will either round up or down as it stands. If you want just the integer part use int(0) (although a default of zero may cause problems with the accumulator).

    1. ```value_template: "{{ value_json.electricitymeter.power.value | round(1) }}"

    >>Why do you round this?

    Because for my own preference I I don't want the number to 3DP or for the kWh daily/monthly/ all time usage I only want 1DP.

  • So I have been working with HA a lot more recently and I went back to clean up / check my MQTT coding. There were in fact one or two bits missing and I tided it up if anyone want to to reuse it:

    The secret is in the form:

    1. glow_MQTT_topic_electricitymeter: "glow/44xxxxxxxxxx/SENSOR/electricitymeter"

    Replace xxxxxxxxxx with your own device ID (if you are not going to be sharing you code with anyone you can code it directly into state_topic below

    I pickup the mqtt definitions from configuration.yaml as:

    1. mqtt: !include mqttsensors.yaml
    2.  

    [I continue in the next post as this forum would not not let me post the whole thing in one go]

  • So mqttsensors.yaml is:

    1. #mqtt: is the context from the configuration.yaml file
    2. sensor:
    3.   #glow/<UID>/SENSOR/electricitymeter
    4.   #power
    5.   - name: "Metered Current Consumption"
    6.     state_topic: !secret glow_MQTT_topic_electricitymeter
    7.     unit_of_measurement: "W"
    8.     device_class: power
    9.     state_class: measurement
    10.     icon: mdi:meter-electric-outline
    11.     value_template: "{{ value_json.electricitymeter.power.value | float * 1000 |int }}"
    12.  
    13.     #export
    14.   - name: "Metered Export Reading"
    15.     state_topic: !secret glow_MQTT_topic_electricitymeter
    16.     unit_of_measurement: "kWh"
    17.     device_class: energy
    18.     state_class: total_increasing
    19.     icon: mdi:home-export-outline
    20.     value_template: "{{ value_json.electricitymeter.energy.export.cumulative | float |round(1) }}"
    21.  
    22.     #import
    23.   - name: "Metered Import Reading"
    24.     state_topic: !secret glow_MQTT_topic_electricitymeter
    25.     unit_of_measurement: "kWh"
    26.     device_class: energy
    27.     state_class: total_increasing
    28.     icon: mdi:home-import-outline
    29.     value_template: "{{ value_json.electricitymeter.energy.import.cumulative | float | round(1) }}"
    30.  
    31.   - name: "Metered Import Today"
    32.     state_topic: !secret glow_MQTT_topic_electricitymeter
    33.     unit_of_measurement: "kWh"
    34.     device_class: energy
    35.     state_class: measurement
    36.     icon: mdi:home-import-outline
    37.     value_template: "{{ value_json.electricitymeter.energy.import.day | round(1) }}"
    38.  
    39.   - name: "Metered Import This Week"
    40.     state_topic: !secret glow_MQTT_topic_electricitymeter
    41.     unit_of_measurement: "kWh"
    42.     device_class: energy
    43.     state_class: measurement
    44.     icon: mdi:home-import-outline
    45.     value_template: "{{ value_json.electricitymeter.energy.import.week | round(1) }}"
    46.  
    47.   - name: "Metered Import This Month"
    48.     state_topic: !secret glow_MQTT_topic_electricitymeter
    49.     device_class: energy
    50.     state_class: measurement
    51.     unit_of_measurement: "kWh"
    52.     icon: mdi:home-import-outline
    53.     value_template: "{{ value_json.electricitymeter.energy.import.month | round(1) }}"
    54.  
    1.   - name: "Metered Unit Price"
    2.     state_topic: !secret glow_MQTT_topic_electricitymeter
    3.     unit_of_measurement: "pence" #Default is GBP, see below
    4.     device_class: "monetary"
    5.     icon: mdi:home-import-outline
    6.     value_template: "{{ value_json.electricitymeter.energy.import.price.unitrate | float *100 | round(1) }}"
    7.     #unit_of_measurement: "GBP"
    8.     #value_template: "{{ value_json.electricitymeter.energy.import.price.unitrate }}"
    9. 
    10.   - name: "Metered Standing Charge"
    11.     state_topic: !secret glow_MQTT_topic_electricitymeter
    12.     unit_of_measurement: "pence" #Default is GBP, see below
    13.     device_class: "monetary"
    14.     icon: mdi:currency-gbp
    15.     value_template: "{{ value_json.electricitymeter.energy.import.price.standingcharge | float *100 | round(1) }}"
    16.     #unit_of_measurement: "GBP"
    17.     #value_template: "{{ value_json.electricitymeter.energy.import.price.standingcharge }}"
    18.  
    19.     #Timestamp
    20.   - name: "Metered Timestamp"
    21.     state_topic: !secret glow_MQTT_topic_electricitymeter
    22.     device_class: "timestamp"
    23.     icon: mdi:clock-outline
    24.     value_template: "{{ value_json.electricitymeter.timestamp }}"
    25.  
    26.   # Glow Device State Info
    27.   - name: "Glow Han Status"
    28.     state_topic: "glow/441793504B6C/STATE"
    29.     icon: mdi:set-center
    30.     value_template: "{{ value_json.han.status }}"
    31.  
    32.   - name: "Glow Han RSSI"
    33.     state_topic: "glow/441793504B6C/STATE"
    34.     device_class: signal_strength
    35.     unit_of_measurement: "dBm"
    36.     icon: mdi:signal
    37.     value_template: "{{ value_json.han.rssi }}"
    38.  
    39.   - name: "Glow Software Version"
    40.     state_topic: "glow/441793504B6C/STATE"
    41.     icon: mdi:information-variant
    42.     value_template: "{{ value_json.software }}"


Sign In or Register to comment.