1. Skip to content

1. Integration into Home Assistant

There are 3 ways to get the data into your Home Assistant:

  1. Using MQTT (Automatically Setup Entities using Home Assistant MQTT Discovery)
  2. Using MQTT (Manually Setup Entities)
  3. Using REST calls

The first one is the easier way if you already have MQTT in use.

1.1 Using MQTT (Automatically Setup Entities using Home Assistant MQTT Discovery)

Starting with Version >12.0.1, AI-on-the-edge-devices support Home Assistant Discovery.

  1. Check here to learn more about it and how to enable it in Homeassistant.
  2. You also have to enable it in the MQTT settings of your device:

    grafik

    Make sure to select the right Meter Type to get the right units!

On the next start of the device, it will send discovery topics and Home Assistant should pick them up and show them under Settings > Integrations > MQTT:

grafik grafik grafik

1.1.1 Using MQTT (Manually Setup Entities)

First make sure with an MQTT client (for example MQTT Explorer) that MQTT works as expected and to get a list of the available topics!

Then add a sensor for each property:

mqtt:
  sensor:
    - state_topic: "wasserzaehler/main/value"
      name: "Watermeter Value"
      unique_id: watermeter_value
      unit_of_measurement: 'm³'
      state_class: total_increasing
      device_class: water # Needs Home Assistant 2022.11!
      icon: 'mdi:water-pump'
      availability_topic: wasserzaehler/connection
      payload_available: connected
      payload_not_available: connection lost

    - state_topic: "wasserzaehler/main/rate"
      name: "Watermeter Rate"
      unique_id: watermeter_rate
      unit_of_measurement: 'm³/min'
      state_class: measurement
      device_class: water # Needs Home Assistant 2022.11!
      icon: 'mdi:water-pump'
      availability_topic: wasserzaehler/connection
      payload_available: connected
      payload_not_available: connection lost

    - state_topic: "wasserzaehler/main/error"
      name: "Watermeter Error"
      unique_id: watermeter_error
      icon: "mdi:water-alert"
      availability_topic: wasserzaehler/connection
      payload_available: connected
      payload_not_available: connection lost    

    - state_topic: "wasserzaehler/uptime"
      name: "Watermeter Uptime"
      unique_id: watermeter_uptime
      unit_of_measurement: 's'
      state_class: measurement
      device_class: duration
      entity_category: diagnostic
      icon: "mdi:timer-outline"
      availability_topic: wasserzaehler/connection
      payload_available: connected
      payload_not_available: connection lost
If you run the discovery once, you can also extract the information from there (MQTT Info, untested):
mqtt: # Extracted form the Discovery but untested!
  sensor:
      - name: Value
        unique_id: wasserzaehler-main_value
        icon: mdi:gauge
        state_topic: wasserzaehler/main/value
        unit_of_measurement: 
        device_class: water
        state_class: total_increasing
        availability_topic: wasserzaehler/connection
        payload_available: connected
        payload_not_available: connection lost

If you want to convert the to l, use a template sensor:

template:
  - sensor:
    - name: "Watermeter in l"
      unique_id: watermeter_in_l
      icon: "mdi:gauge"
      state: "{{ states('sensor.watermeter_value')|float(default=0) * 1000 }}" # Convert 1 m3 => 1000 l
      unit_of_measurement: l
      availability: "{{ states('sensor.watermeter_value') not in ['unknown', 'unavailable', 'none'] }}"

If you you want to have the consumption per day, you can use an Utility Meter. it is a helper and can be used to reset the total increasing values once a day

utility_meter:
  utility_meter_gas_per_day:
    source: sensor.gasmeter_value
    cycle: daily

  utility_meter_water_per_day:
    source: sensor.watermeter_value
    cycle: daily

Note that you also can add it using the UI.

1.1.2 Examples

grafik

grafik

1.1.3 Statistics Graph

Creating Statistics Graphs (e.g. usage per day) is easy using the Energy Dashboard: grafik

Note that there seems to be a bug in the graph, see https://github.com/home-assistant/frontend/issues/13995!

1.1.4 InfluxDb Graphs

See also Influx-DB.

If you have setup InfluxDB already, it is also possible to fetch statistics from there, e.g. daily usage:

from(bucket: "HomeAssistant")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["entity_id"] == "wasserverbrauch_tag")
  |> filter(fn: (r) => r["_field"] == "value")
  |> timeShift(duration: -1d)
  |> aggregateWindow(every: 1d, fn: max, createEmpty: false)
  |> yield(name: "mean")

grafik

1.2 Using REST

When using REST, Home Assistant has to periodically call an URL on the ESP32 which in return provides the requested data.

See REST API for a list of available URLs.

The most practical one is the json entrypoint which provides the most relevant data JSON formatted: http://<IP>/json This would return:

{
"main":
  {
    "value": "512.3020",
    "raw": "0512.3020",
    "error": "no error",
    "rate": 0.000000,
    "timestamp": "2022-10-02T20:32:06"
   [..]
  }
}

To do such a REST call, you need to create a REST sensor:

sensor:

- platform: rest
  name: "Gasmeter JSON" 
  resource: http://<IP>/json
  json_attributes:
    - main
  value_template: '{{ value_json.value }}'
  headers:
    Content-Type: application/json
  scan_interval: 60

template:
  sensor:
  - name: "Gasmeter Value from JSON"
    unique_id: gas_meter_value_from_json
    state: "{{ state_attr('sensor.gasmeter_json','main')['value'] }}"
    unit_of_measurement: 'm³'

  - name: "Watermeter Value from JSON"
    unique_id: water_meter_value_from_json
    state: >-
            {{ state_attr('sensor.watermeter_json','main')['value'] | float }}
    unit_of_measurement: 'm³'
    device_class: water
    state_class: total_increasing
    icon: mdi:gauge

The 2nd way is to use the html api call from value.html :

sensor: - platform: rest resource: http://<IP>/value.html name: cold_water unique_id: cold_water_from_rest unit_of_measurement: "L" device_class: water state_class: total_increasing icon: mdi:gauge scan_interval : 120

See also https://community.home-assistant.io/t/rest-sensor-nested-json/243420/9

1.2.0.1 Photo

REST can also be used to show the photo of the last round:

grafik

To access it, use http://<IP>/img_tmp/alg_roi.jpg resp http://<IP>/img_tmp/raw.jpg.