Listening to Domoticz mqtt

Hi!

I have domoticz running with a p1 cable to track power consumption and delivery. The data is pushed to a mosquitto server.

I thought I’d link that information into home assistant, but it’s not as straightforward as I thought.

I’ve set up the Mqtt add-on. And the logging shows it’s receiving data. However, I don’t have any entities popping up.

Seems that needs to be done manually? Per device?
Can’t find any documentation on how to take this further.

The log

2024-12-17 10:05:06.355 DEBUG (MainThread) [homeassistant.components.mqtt.client] Subscribing with mid: 79 to topics with qos: [('domoticz/out/kWh Usage L1 (Calculated)', 0)]
2024-12-17 10:05:06.356 DEBUG (MainThread) [homeassistant.components.mqtt.client] 10.0.0.4: unregister write 35
2024-12-17 10:05:10.664 DEBUG (MainThread) [homeassistant.components.mqtt.client] 10.0.0.4: register write 35
2024-12-17 10:05:10.664 DEBUG (MainThread) [homeassistant.components.mqtt.client] Unsubscribing with mid: 80 to topics: ['domoticz/out/kWh Usage L1 (Calculated)']
2024-12-17 10:05:10.665 DEBUG (MainThread) [homeassistant.components.mqtt.client] 10.0.0.4: unregister write 35
2024-12-17 10:05:14.829 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/stats (qos=0): b'{"uptime":410517095,"voltage":3.41,"free memory":74,"free heap":28456,"wifi":78,"mqtt reconnects":10,"total reads":41443,"good reads":41443,"bad crc reads":0,"bad header reads":0,"too short reads":0,"too long reads":0,"timeout reads":0,"version":"3.8","rules active":0}'
2024-12-17 10:05:14.875 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/LWT (qos=0): b'Online'
2024-12-17 10:05:19.974 INFO (MainThread) [backoff] Backing off fetch_events(...) for 0.3s (aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected)
2024-12-17 10:05:24.830 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/stats (qos=0): b'{"uptime":410527097,"voltage":3.41,"free memory":75,"free heap":28976,"wifi":78,"mqtt reconnects":10,"total reads":41444,"good reads":41444,"bad crc reads":0,"bad header reads":0,"too short reads":0,"too long reads":0,"timeout reads":0,"version":"3.8","rules active":0}'
2024-12-17 10:05:24.876 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/LWT (qos=0): b'Online'
2024-12-17 10:05:30.275 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/s0/Watthour/1 (qos=0): b'0.00'
2024-12-17 10:05:30.320 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/s0/WatthourTotal/1 (qos=0): b'2459515.00'
2024-12-17 10:05:30.321 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on panasonic_heat_pump/s0/Watt/1 (qos=0): b'24'

Hi, nothing here: Integrations - Home Assistant

1 Like

Might be overlooking it but cannot find power consumption/delivery device here? Or should I go more general?

:slight_smile: fter searching a bit further, this seems to be an example of a template:

mqtt:
  sensor:
    unique_id: 'efergy_monitor'
    name: 'Energy Usage'
    state_topic: 'energy/maintariff'
    value_template: "{{ value.split(',')[2] }}"
    device_class: energy
    unit_of_measurement: W

Not the easiest way to set it up :confounded:

Also, didn’t anything show up under Settings → Devices & services → MQTT?

I would have expected that… But no…

What is that 10.0.0.4 device?

That’s the Mqtt broker.

Ah ok, you’re right; the way it is arranged (on mobile apparently) and the foreign language confused me. :wink:

1 Like

Got a bit further… Created all sensors:

mqtt:
  sensor:
    - name: "kWh Delivery L1"
      state_topic: "domoticz/out/kWh_Delivery_L1_Calculated"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_delivery_L1"

    - name: "kWh Delivery L2"
      state_topic: "domoticz/out/kWh_Delivery_L2_Calculated"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_delivery_L2"

    - name: "kWh Delivery L3"
      state_topic: "domoticz/out/kWh_Delivery_L3_Calculated"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_delivery_L3"

    - name: "kWh Usage L1"
      state_topic: "domoticz/out/kWh_Usage_L1_Calculated"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_usage_L1"

    - name: "kWh Usage L2"
      state_topic: "domoticz/out/kWh_Usage_L2_Calculated"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_usage_L2"

    - name: "kWh Usage L3"
      state_topic: "domoticz/out/kWh_Usage_L3_Calculated"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_usage_L3"

    - name: "Voltage L1"
      state_topic: "domoticz/out/Voltage_L1"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "V"
      device_class: voltage
      state_class: measurement
      unique_id: "Voltage_L1"

    - name: "Voltage L2"
      state_topic: "domoticz/out/Voltage_L2"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "V"
      device_class: voltage
      state_class: measurement
      unique_id: "Voltage_L2"

    - name: "Voltage L3"
      state_topic: "domoticz/out/Voltage_L3"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "V"
      device_class: voltage
      state_class: measurement
      unique_id: "Voltage_L3"

    - name: "Usage L1"
      state_topic: "domoticz/out/Usage_L1"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Usage_L1"

    - name: "Usage L2"
      state_topic: "domoticz/out/Usage_L2"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Usage_L2"

    - name: "Usage L3"
      state_topic: "domoticz/out/Usage_L3"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Usage_L3"

    - name: "Delivery L1"
      state_topic: "domoticz/out/Delivery_L1"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Delivery_L1"

    - name: "Delivery L2"
      state_topic: "domoticz/out/Delivery_L2"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Delivery_L2"

    - name: "Delivery L3"
      state_topic: "domoticz/out/Delivery_L3"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Delivery_L3"

    - name: "Current L1"
      state_topic: "domoticz/out/Current_L1_L2_L3"
      value_template: "{{ value_json.svalue1.split(',')[0] }}"
      unit_of_measurement: "A"
      device_class: current
      state_class: measurement
      unique_id: "Current_L1"

    - name: "Current L2"
      state_topic: "domoticz/out/Current_L1_L2_L3"
      value_template: "{{ value_json.svalue1.split(',')[1] }}"
      unit_of_measurement: "A"
      device_class: current
      state_class: measurement
      unique_id: "Current_L2"

    - name: "Current L3"
      state_topic: "domoticz/out/Current_L1_L2_L3"
      value_template: "{{ value_json.svalue1.split(',')[2] }}"
      unit_of_measurement: "A"
      device_class: current
      state_class: measurement
      unique_id: "Current_L3"

    - name: "Actual Usage L1_L2_L3"
      state_topic: "domoticz/out/Actual_Usage_L1_L2_L3"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Actual_Usage_L1_L2_L3"

    - name: "Actual Delivery L1_L2_L3"
      state_topic: "domoticz/out/Actual_Delivery_L1_L2_L3"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "Actual_Delivery_L1_L2_L3"

    - state_topic: "domoticz/out/Stroom"
      name: "Low Tariff Usage"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "low_tariff_usage"

    - state_topic: "domoticz/out/Stroom"
      name: "High Tariff Usage"
      value_template: "{{ value_json.svalue2 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "high_tariff_usage"

    - state_topic: "domoticz/out/Stroom"
      name: "Low Tariff Return"
      value_template: "{{ value_json.svalue3 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "low_tariff_return"

    - state_topic: "domoticz/out/Stroom"
      name: "High Tariff Return"
      value_template: "{{ value_json.svalue4 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "high_tariff_return"

    - state_topic: "domoticz/out/Stroom"
      name: "Actual Consumption"
      value_template: "{{ value_json.svalue5 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "actual_consumption"

    - state_topic: "domoticz/out/Stroom"
      name: "Actual Return"
      value_template: "{{ value_json.svalue6 }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      unique_id: "actual_return"

    - state_topic: "domoticz/out/Stroom"
      name: "Consumed Energy"
      value_template: "{{ (value_json.svalue1 | float) + (value_json.svalue2 | float) }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "consumed_energy"

    - state_topic: "domoticz/out/Stroom"
      name: "Delivered Energy"
      value_template: "{{ (value_json.svalue3 | float) + (value_json.svalue4 | float) }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "delivered_energy"

    - state_topic: "domoticz/out/Totaal - kWh opbrengst"
      name: "Solar Panel Delivery"
      value_template: "{{ value_json.svalue1 }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "solar_panel_delivery"

Now energy dash is still empty… Seems domoticz and home assistant work very differnently.

1 Like

The energy dash is not updated instantly.
Did you configure it?

Otherwise it would not be 2 different platforms…

Looks like the topics above are malformed, the topic should not contain the name used in domoticz, that name should be checked in the value_json.name field. I had more success using sensors as follows, and get graphs under http://homeassistant:8123/config/entities, see my config below:

mqtt:
  sensor:
    - name: "Gas"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Gas' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.gas_usage') }}
        {% endif %}
      unit_of_measurement: "m3"
      device_class: energy
      state_class: total_increasing
      unique_id: "gas_usage"

    - name: "Electricity Usage High Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.electricity_usage_high_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_usage_high_tariff"

    - name: "Electricity Usage Low Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue2 }}
        {% else %}
          {{ states('sensor.electricity_usage_low_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_usage_low_tariff"

    - name: "Electricity Production High Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue3 }}
        {% else %}
          {{ states('sensor.electricity_production_high_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_production_high_tariff"

    - name: "Electricity Production Low Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue4 }}
        {% else %}
          {{ states('sensor.electricity_production_low_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_production_low_tariff"

    - name: "kWh Delivery L1 (Calculated)"
      state_topic: "domoticz/out"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_delivery_L1"
      json_attributes_topic: "domoticz/out"
      json_attributes_template: "{{ value_json | tojson }}"
      value_template: >
        {% if value_json.name == 'kWh Delivery L1 (Calculated)' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.kWh_delivery_L1') }}
        {% endif %}

    - name: "kWh Delivery L2 (Calculated)"
      state_topic: "domoticz/out"
      value_template: "{{ value_json['svalue1'] }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_delivery_L2"
      json_attributes_topic: "domoticz/out"
      json_attributes_template: "{{ value_json | tojson }}"
      value_template: >
        {% if value_json.name == 'kWh Delivery L2 (Calculated)' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.kWh_delivery_L2') }}
        {% endif %}

    - name: "kWh Delivery L3 (Calculated)"
      state_topic: "domoticz/out"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_delivery_L3"
      json_attributes_topic: "domoticz/out"
      json_attributes_template: "{{ value_json | tojson }}"
      value_template: >
        {% if value_json.name == 'kWh Delivery L3 (Calculated)' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.kWh_delivery_L2') }}
        {% endif %}

    - name: "kWh Usage L1 (Calculated)"
      state_topic: "domoticz/out"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_usage_L1"
      json_attributes_topic: "domoticz/out"
      json_attributes_template: "{{ value_json | tojson }}"
      value_template: >
        {% if value_json.name == 'kWh Usage L1 (Calculated)' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.kWh_usage_L1') }}
        {% endif %}

    - name: "kWh Usage L2 (Calculated)"
      state_topic: "domoticz/out"
      value_template: "{{ value_json['svalue1'] }}"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_usage_L2"
      json_attributes_topic: "domoticz/out"
      json_attributes_template: "{{ value_json | tojson }}"
      value_template: >
        {% if value_json.name == 'kWh Usage L2 (Calculated)' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.kWh_usage_L2') }}
        {% endif %}

    - name: "kWh Usage L3 (Calculated)"
      state_topic: "domoticz/out"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: measurement
      unique_id: "kWh_usage_L3"
      json_attributes_topic: "domoticz/out"
      json_attributes_template: "{{ value_json | tojson }}"
      value_template: >
        {% if value_json.name == 'kWh Usage L3 (Calculated)' %}
          {{ value_json.svalue1 }}
        {% else %}
          {{ states('sensor.kWh_usage_L2') }}
        {% endif %}

# Define utility meters
utility_meter:
  daily_electricity_usage_high_tariff:
    source: sensor.electricity_usage_high_tariff
    cycle: daily
  daily_electricity_usage_low_tariff:
    source: sensor.electricity_usage_low_tariff
    cycle: daily
  daily_electricity_production_high_tariff:
    source: sensor.electricity_production_high_tariff
    cycle: daily
  daily_electricity_production_low_tariff:
    source: sensor.electricity_production_low_tariff
    cycle: daily

  monthly_electricity_usage_high_tariff:
    source: sensor.electricity_usage_high_tariff
    cycle: monthly
  monthly_electricity_usage_low_tariff:
    source: sensor.electricity_usage_low_tariff
    cycle: monthly
  monthly_electricity_production_high_tariff:
    source: sensor.electricity_production_high_tariff
    cycle: monthly
  monthly_electricity_production_low_tariff:
    source: sensor.electricity_production_low_tariff
    cycle: monthly

Kind regards,
Dennis

Looks like it it working now:

Home assistant energy dashboard through MQTT:

Configuration:


mqtt:
  sensor:
    - name: "Gas"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Gas' %}
          {{ value_json.svalue1 | float * 0.001 }}
        {% else %}
          {{ states('sensor.gas_usage') }}
        {% endif %}
      unit_of_measurement: "m3"
      device_class: gas
      state_class: total_increasing
      unique_id: "gas_usage"

    - name: "Solar Panel Delivery"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Solar uitbouw' %}
          {{ value_json.svalue2 | float * 0.001 }}
        {% else %}
          {{ states('sensor.solar_panel_delivery') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "solar_panel_delivery"

    - name: "Electricity Usage High Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue1 | float * 0.001 }}
        {% else %}
          {{ states('sensor.electricity_usage_high_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_usage_high_tariff"

    - name: "Electricity Usage Low Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue2 | float * 0.001 }}
        {% else %}
          {{ states('sensor.electricity_usage_low_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_usage_low_tariff"

    - name: "Electricity Production High Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue3 | float * 0.001 }}
        {% else %}
          {{ states('sensor.electricity_production_high_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_production_high_tariff"
    - name: "Electricity Production Low Tariff"
      state_topic: "domoticz/out"
      value_template: >
        {% if value_json.name == 'Power' %}
          {{ value_json.svalue4 | float * 0.001 }}
        {% else %}
          {{ states('sensor.electricity_production_low_tariff') }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      unique_id: "electricity_production_low_tariff"

# Define utility meters
utility_meter:
  daily_electricity_usage_high_tariff:
    source: sensor.electricity_usage_high_tariff
    cycle: daily
  daily_electricity_usage_low_tariff:
    source: sensor.electricity_usage_low_tariff
    cycle: daily
  daily_electricity_production_high_tariff:
    source: sensor.electricity_production_high_tariff
    cycle: daily
  daily_electricity_production_low_tariff:
    source: sensor.electricity_production_low_tariff
    cycle: daily

  monthly_electricity_usage_high_tariff:
    source: sensor.electricity_usage_high_tariff
    cycle: monthly
  monthly_electricity_usage_low_tariff:
    source: sensor.electricity_usage_low_tariff
    cycle: monthly
  monthly_electricity_production_high_tariff:
    source: sensor.electricity_production_high_tariff
    cycle: monthly
  monthly_electricity_production_low_tariff:
    source: sensor.electricity_production_low_tariff
    cycle: monthly

Here is the domoticz energy dashboard at roughly the same time:

One of the challenges was converting the so-called kWh measurements into real kWh measurements, i.e. dividing the Wh by 1000. It took a while before homeassistant showed proper values, could not easily get the old big values out of the history.

Kind regards,
Dennis