Komunikácia / Home Assistant

Integrácia MiniHPC s Home Assistant cez MQTT

MiniHPC je možné integrovať do systému Home Assistant pomocou protokolu MQTT. Vďaka tomu je možné sledovať dáta (napr. teplotu, výkon, príkon, stavy relé výstupov,...) ale aj nastavovať rôzne parametre (napr. mód kúrenia/chladenia, nastavovanie teplôt a ďalších parametrov MiniHPC).

Predpoklady a požiadavky

1. Funkčný MQTT broker

  • Napríklad Mosquitto MQTT broker.
  • Ak je použitý Home Assistant OS alebo Home Assistant Supervised, je možné využiť oficiálny Mosquitto Add-On.

2. Pripojenie MiniHPC k MQTT brokeru

  • Vo web rozhraní MiniHPC je potrebné nastaviť IP adresu, port a prihlasovacie údaje (používateľ, heslo) k brokeru.

3. Znalosť tém (topics) používaných MiniHPC

  • V rámci MQTT zariadenie (MiniHPC) publikuje dáta do konkrétnych tém (napr. miniHPC/data/...) a prijíma príkazy cez iné témy (napr. minihpc/set/...).

4. Home Assistant s aktívnou MQTT integráciou

  • V Home Assistante je potrebné pridať integráciu MQTT cez Settings → Devices & Services → Add Integration.

Nasledujúci príklad zobrazuje kompletný configuration.yaml s ukážkovými senzormi. Pri reálnom nasadení treba upraviť koreňový topic (ak je použitý iný ako defaultný miniHPC).

mqtt:
# =======================
# 1) Senzory (čítanie dát z MiniHPC)
# =======================
  - sensor:
    - name: "Teplota T1"
      unique_id: "teplota_t1"
      state_topic: "miniHPC/data/t1"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: &minihpc_device_info
        identifiers: "MiniHPC"
        name: "MiniHPC"
        model: "MiniHPC"
        manufacturer: "MiniHPC"
        configuration_url: http://192.168.1.199 # update this with your MiniHPC config URL

    - name: "Teplota T2"
      unique_id: "teplota_t2"
      state_topic: "miniHPC/data/t2"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota T3"
      unique_id: "teplota_t3"
      state_topic: "miniHPC/data/t3"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota T4"
      unique_id: "teplota_t4"
      state_topic: "miniHPC/data/t4"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota T5"
      unique_id: "teplota_t5"
      state_topic: "miniHPC/data/t5"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota T6"
      unique_id: "teplota_t6"
      state_topic: "miniHPC/data/t6"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota Vonkajšia"
      unique_id: "teplota_vonkajsia"
      state_topic: "miniHPC/data/tout"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota Výparníka"
      unique_id: "teplota_vyparnik"
      state_topic: "miniHPC/data/tsuc"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota na kompresore"
      unique_id: "teplota_kompresor"
      state_topic: "miniHPC/data/texh"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "ODU mód"
      unique_id: "odu_mod"
      state_topic: "miniHPC/data/outMode"
      device: *minihpc_device_info

    - name: "ODU stav"
      unique_id: "odu_stav"
      state_topic: "miniHPC/data/outState"
      value_template: >-
        {% if value == '1' %}
            ON
        {% else %}
            OFF
        {% endif %}
      device: *minihpc_device_info

    - name: "Frekvencia kompresora"
      unique_id: "frekvencia kompresora"
      state_topic: "miniHPC/data/outFrequency"
      device_class: frequency
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "Hz"
      device: *minihpc_device_info

    - name: "Rýchlosť ventilátora"
      unique_id: "rychlost_ventilatora"
      state_topic: "miniHPC/data/outFan"
      device_class: speed
      state_class: measurement
      value_template: "{{ value }}"
      unit_of_measurement: "RPM"
      device: *minihpc_device_info

    - name: "Príkon"
      unique_id: "prikon"
      state_topic: "miniHPC/data/outPower"
      device_class: power
      state_class: measurement
      unit_of_measurement: "W"
      value_template: "{{ value | float  | round (1) }}"
      device: *minihpc_device_info

    - name: "EEV poloha"
      unique_id: "eev_poloha"
      state_topic: "miniHPC/data/outEEV"
      state_class: measurement
      device: *minihpc_device_info

    - name: "ODU DC napätie"
      unique_id: "odu_dc_napetie"
      state_topic: "miniHPC/data/outDCbus"
      device_class: voltage
      state_class: measurement
      unit_of_measurement: "V"
      value_template: "{{ value | int }}"
      device: *minihpc_device_info

    - name: "ODU odmrazovanie"
      unique_id: "odu_odmrazovanie"
      state_topic: "miniHPC/data/outDefrost"
      value_template: >-
        {% if value == '1' %}
            ON
        {% else %}
            OFF
        {% endif %}
      device: *minihpc_device_info

    - name: "ODU DC prúd"
      unique_id: "odu_dc_prud"
      state_topic: "miniHPC/data/outDCcurrent"
      device_class: current
      state_class: measurement
      unit_of_measurement: "A"
      value_template: "{{ value | float  | round (1) }}"
      device: *minihpc_device_info

    - name: "prietok vody"
      unique_id: "prietok_vody"
      state_topic: "miniHPC/data/flow"
      device_class: volume_flow_rate
      state_class: measurement
      unit_of_measurement: "l/min"
      value_template: "{{ value | float  | round (2) }}"
      device: *minihpc_device_info

    - name: "Nastavená teplota"
      unique_id: "nastavena_teplota"
      state_topic: "miniHPC/data/tset"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value | float  | round (2) }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "ODU Tpreset"
      unique_id: "odu_tpreset"
      state_topic: "miniHPC/data/tIDUroom"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value | float  | round (2) }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "ODU Tamb"
      unique_id: "odu_tamb"
      state_topic: "miniHPC/data/tIDUset"
      device_class: temperature
      state_class: measurement
      value_template: "{{ value | float  | round (1) }}"
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Výkon"
      unique_id: "vykon"
      state_topic: "miniHPC/data/pwrOutHP"
      device_class: power
      state_class: measurement
      unit_of_measurement: "W"
      value_template: "{{ value | float  | round (1) }}"
      device: *minihpc_device_info

    - name: "Čas - kompresor počas kúrenia"
      unique_id: "cas_kurenie_kompresor"
      state_topic: "miniHPC/data/heatTimeHP"
      device_class: duration
      state_class: measurement
      unit_of_measurement: "s"
      device: *minihpc_device_info

    - name: "Čas - el. dohrev R2"
      unique_id: "cas_el_dohrev_r2"
      state_topic: "miniHPC/data/heatTimeELH"
      device_class: duration
      state_class: measurement
      unit_of_measurement: "s"
      device: *minihpc_device_info

    - name: "Čas - odmrazovanie"
      unique_id: "cas_odmrazovanie"
      state_topic: "miniHPC/data/heatTimeDefr"
      device_class: duration
      state_class: measurement
      unit_of_measurement: "s"
      device: *minihpc_device_info

    - name: "Počet - kompresor počas kúrenia"
      unique_id: "pocet_kurenie_kompresor"
      state_topic: "miniHPC/data/heatCountHP"
      state_class: measurement
      device: *minihpc_device_info

    - name: "Počet - el. dohrev R2"
      unique_id: "pocet_el_dohrev_r2"
      state_topic: "miniHPC/data/heatCountELH"
      state_class: measurement
      device: *minihpc_device_info

    - name: "Počet - odmrazovanie"
      unique_id: "pocet_odmrazovanie"
      state_topic: "miniHPC/data/heatCountDefr"
      state_class: measurement
      device: *minihpc_device_info

    - name: "Čas - kompresor počas chladenia"
      unique_id: "cas_chladenie_kompresor"
      state_topic: "miniHPC/data/coolTimeHP"
      device_class: duration
      state_class: measurement
      unit_of_measurement: "s"
      device: *minihpc_device_info

    - name: "Počet - kompresor počas chladenia"
      unique_id: "pocet_chladenie_kompresor"
      state_topic: "miniHPC/data/coolCountHP"
      state_class: measurement
      device: *minihpc_device_info

    - name: "Dátum - program anti-legionela"
      unique_id: "datum_antilegionela"
      state_topic: "miniHPC/data/dhwLegTime"
      device_class: timestamp
      value_template: "{{ (value | int) | timestamp_local }}"
      device: *minihpc_device_info

    - name: "Čas - kompresor počas TPV"
      unique_id: "cas_tpv_kompresor"
      state_topic: "miniHPC/data/dhwTimeHP"
      device_class: duration
      state_class: measurement
      unit_of_measurement: "s"
      device: *minihpc_device_info

    - name: "Čas - el. dohrev R1"
      unique_id: "cas_el_dohrev_r1"
      state_topic: "miniHPC/data/dhwTimeELH"
      device_class: duration
      state_class: measurement
      unit_of_measurement: "s"
      device: *minihpc_device_info

    - name: "Počet - kompresor počas TPV"
      unique_id: "pocet_tpv_kompresor"
      state_topic: "miniHPC/data/dhwCountHP"
      state_class: measurement
      device: *minihpc_device_info

    - name: "Počet - el. dohrev R1"
      unique_id: "pocet_el_dohrev_r1"
      state_topic: "miniHPC/data/dhwCountELH"
      state_class: measurement
      device: *minihpc_device_info

    - name: "Spotreba energie - kúrenie"
      unique_id: "spotreba_energie_kurenie"
      state_topic: "miniHPC/data/heatPwrIn"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "Spotreba energie - chladenie"
      unique_id: "spotreba_energie_chladenie"
      state_topic: "miniHPC/data/coolPwrIn"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "Spotreba energie - TPV"
      unique_id: "spotreba_energie_tpv"
      state_topic: "miniHPC/data/dhwPwrIn"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "Vyrobená energia - kúrenie HP"
      unique_id: "vyrobena_energia_kurenie_hp"
      state_topic: "miniHPC/data/heatPwrOutHP"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "Vyrobená energia - kúrenie ELH"
      unique_id: "vyrobena_energia_kurenie_elh"
      state_topic: "miniHPC/data/heatPwrOutELH"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "Odobraná energia - chladenie"
      unique_id: "odobrana_energia_chladenie"
      state_topic: "miniHPC/data/coolPwrOut"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "Vyrobená energia - TPV"
      unique_id: "vyrobena_energia_tpv"
      state_topic: "miniHPC/data/dhwPwrOut"
      device_class: energy
      state_class: measurement
      unit_of_measurement: "kWh"
      value_template: "{{ ((value | float) / 1000000) | round(3) }}"
      device: *minihpc_device_info

    - name: "BT - vlhkost"
      unique_id: "bt_vlhkost"
      state_topic: "miniHPC/data/BThum"
      device_class: humidity
      state_class: measurement
      unit_of_measurement: "%"
      value_template: "{{ value | float  | round (2) }}"
      device: *minihpc_device_info

    - name: "BT - bateria"
      unique_id: "bt_bateria"
      state_topic: "miniHPC/data/BTbat_lev"
      device_class: battery
      state_class: measurement
      unit_of_measurement: "%"
      device: *minihpc_device_info

    - name: "BT - RSSI"
      unique_id: "bt_rssi"
      state_topic: "miniHPC/data/BTrssi"
      device_class: signal_strength
      state_class: measurement
      device: *minihpc_device_info

# =======================
# 2) binary (binárny senzor)
# =======================

  - binary_sensor:
    - name: "relé R1"
      unique_id: "rele_r1"
      state_topic: "miniHPC/data/R1"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

    - name: "relé R2"
      unique_id: "rele_r2"
      state_topic: "miniHPC/data/R2"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

    - name: "relé R3"
      unique_id: "rele_r3"
      state_topic: "miniHPC/data/R3"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

    - name: "relé R4"
      unique_id: "rele_r4"
      state_topic: "miniHPC/data/R4"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

    - name: "relé R5"
      unique_id: "rele_r5"
      state_topic: "miniHPC/data/R5"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

    - name: "vstup S1"
      unique_id: "vstup_s1"
      state_topic: "miniHPC/data/S1"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

    - name: "vstup S2"
      unique_id: "vstup S2"
      state_topic: "miniHPC/data/S2"
      payload_on: "1"
      payload_off: "0"
      device: *minihpc_device_info

# =======================
# 3) Select (rozbalovacie menu)
# =======================

  - select:
    - name: "Mód"
      unique_id: "selest_mod"
      command_topic: "miniHPC/set/mode"
      state_topic: "miniHPC/config/mode"
      options:
        - "off"
        - "heat"
        - "cool"
      command_template: >-
        {% if value == 'off' %}
          0
        {% elif value == 'heat' %}
          1
        {% elif value == 'cool' %}
          2
        {% endif %}
      value_template: >-
        {% if value == '0' %}
          off
        {% elif value == '1' %}
          heat
        {% elif value == '2' %}
          cool
        {% else %}
          off
        {% endif %}
      device: *minihpc_device_info

    - name: "ODU Obmedzenie vykonu"
      unique_id: "odu_power_limit"
      command_topic: "miniHPC/set/odu_power_limit"
      state_topic: "miniHPC/config/odu_power_limit"
      options:
        - "off"
        - "70%"
        - "50%"
      command_template: >-
        {% if value == 'off' %}
          0
        {% elif value == '70%' %}
          1
        {% elif value == '50%' %}
          2
        {% endif %}
      value_template: >-
        {% if value == '0' %}
          off
        {% elif value == '1' %}
          70%
        {% elif value == '2' %}
          50%
        {% else %}
          off
        {% endif %}
      device: *minihpc_device_info

    - name: "ODU Nočný rezim"
      unique_id: "odu_nocny_rezim"
      command_topic: "miniHPC/set/odu_night_mode"
      state_topic: "miniHPC/config/odu_night_mode"
      options:
        - "off"
        - "on"
        - "časovač"
      command_template: >-
        {% if value == 'off' %}
          0
        {% elif value == 'on' %}
          1
        {% elif value == 'časovač' %}
          2
        {% endif %}
      value_template: >-
        {% if value == '0' %}
          off
        {% elif value == '1' %}
          on
        {% elif value == '2' %}
          časovač
        {% else %}
          off
        {% endif %}
      device: *minihpc_device_info

# =======================
# 4) Switch (ovládanie prepínania)
# =======================

  - switch:

    - name: "TPV"
      unique_id: "tpv"
      state_topic: "miniHPC/config/dhw_onoff"
      command_topic: "miniHPC/set/dhw_onoff"
      payload_on: "1"
      payload_off: "0"
      state_on: "1"
      state_off: "0"
      retain: false
      qos: 0
      device: *minihpc_device_info

# =======================
# 5) Number (nastavovanie číselnej hodnoty)
# =======================

  - number:

    - name: "Teplota miestnosti T1"
      unique_id: "teplota_miestnosti_t1"
      state_topic: "miniHPC/config/temperature_T1"
      command_topic: "miniHPC/set/temperature_T1"
      min: 10
      max: 30
      step: 0.1
      unit_of_measurement: "°C"
      command_template: "{{ value|float * 10 }}"
      value_template: "{{ value|float / 10 }}"
      device: *minihpc_device_info

    - name: "Teplota vody T2/T3 - kúrenie"
      unique_id: "teplota_vody_t3_kurenie"
      state_topic: "miniHPC/config/temperature_T3"
      command_topic: "miniHPC/set/temperature_T3"
      min: 15
      max: 55
      step: 1
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Teplota vody T3 - chladenie"
      unique_id: "teplota_vody_t3_chladenie"
      state_topic: "miniHPC/config/temperature_T3_cool"
      command_topic: "miniHPC/set/temperature_T3_cool"
      min: 10
      max: 55
      step: 1
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "Ofset - ekvitermická regulacia"
      unique_id: "ofset_ekvitermicka_reg"
      state_topic: "miniHPC/config/heating_eqtr_offset"
      command_topic: "miniHPC/set/heating_eqtr_offset"
      min: -9
      max: 9
      step: 1
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "TPV - spinaci rozdiel"
      unique_id: "tpv_spinaci_rozdiel"
      state_topic: "miniHPC/config/dhw_temp_diff"
      command_topic: "miniHPC/set/dhw_temp_diff"
      min: 5
      max: 50
      step: 1
      unit_of_measurement: "°C"
      device: *minihpc_device_info

    - name: "TPV - teplota"
      unique_id: "tpv_teplota"
      state_topic: "miniHPC/config/dhw_temp_target"
      command_topic: "miniHPC/set/dhw_temp_target"
      min: 20
      max: 80
      step: 1
      unit_of_measurement: "°C"
      device: *minihpc_device_info


Príklad yaml kódu pre pridanie termostatu do Home Assistant.

Termostat prepína módy chladenia/kúrenia, číta teplotu T1 a nastavuje hodnotu temperature_T1 v konfigurácii.

mqtt:
  - climate:
    - name: "Termostat"
      unique_id: termostat
      device: *minihpc_device_info
      modes:
        - "off"
        - "heat"
        - "cool"

      # ====================
      # 1) Ovládanie režimu
      # ====================
      mode_command_topic: "miniHPC/set/mode"
      mode_state_topic: "miniHPC/config/mode"

      # Z Home Assistanta do zariadenia
      # (keď v Lovelace prepneš "off" -> pošle sa "0", "heat" -> "1", "cool" -> "2")
      mode_command_template: >-
        {% if value == 'off' %}
          0
        {% elif value == 'heat' %}
          1
        {% elif value == 'cool' %}
          2
        {% endif %}

      # Zo zariadenia do Home Assistanta
      # (ak príde "0" -> off, "1" -> heat, "2" -> cool, inak default off)
      mode_state_template: >-
        {% if value == '0' %}
          off
        {% elif value == '1' %}
          heat
        {% elif value == '2' %}
          cool
        {% else %}
          off
        {% endif %}

      # ====================
      # 2) Aktuálna teplota
      # ====================
      current_temperature_topic: "miniHPC/data/t1"
      current_temperature_template: "{{ value|float }}"
      temperature_unit: "C"

      # ====================
      # 3) Nastavenie cieľovej teploty
      # ====================
      temperature_command_topic: "miniHPC/set/temperature_T1"
      temperature_state_topic: "miniHPC/config/temperature_T1"
      temperature_command_template: "{{ value|float * 10 }}"
      temperature_state_template: "{{ value|float / 10 }}"
      min_temp: 10
      max_temp: 30
      temp_step: 0.1
      # ====================
      # 4) Rýchlosť ventilátora (Obmedzenie výkonu)
      # ====================
      fan_modes:
        - "100%"
        - "70%"
        - "50%"
      fan_mode_command_topic: "miniHPC/set/odu_power_limit"
      fan_mode_state_topic: "miniHPC/config/odu_power_limit"
      fan_mode_command_template: >-
        {% if value == '100%' %}
          0
        {% elif value == '70%' %}
          1
        {% elif value == '50%' %}
          2
        {% endif %}
      fan_mode_state_template: >-
        {% if value == '0' %}
          100%
        {% elif value == '1' %}
          70%
        {% elif value == '2' %}
          50%
        {% endif %}
    

S nasledujúcim YAML kódom vytvoríme na dashboarde kartu termostatu

HomeAssistant termostat

type: thermostat
entity: climate.minihpc_termostat
features:
  - style: icons
    type: climate-hvac-modes
  - style: dropdown
    type: climate-fan-modes
show_current_as_primary: true

Režimy ventilátora sú použité na úpravu obmedzenia výkonu (100%, 70% a 50%).

Externý senzor T1

Príklad pre nastavenie Home Assistant automatizácie, ktorá urobí priemer z 5 teplotných senzorov umiestnených po dome a každú minútu pošle ich priemer ako teplotu T1 externého senzora do MiniHPC.

alias: MiniHPC teploty T1
description: ""
triggers:
  - minutes: /1
    trigger: time_pattern
actions:
  - data_template:
      topic: miniHPC/setsensor/T1
      payload: >
        {% set sensors = [
          states('sensor.teplomer_spalna'),
          states('sensor.teplomer_obyvacka'),
          states('sensor.teplomer_izba'),
          states('sensor.teplomer_chodba'),
          states('sensor.teplomer_kupelka')
        ] %}  {% set valid_sensors = sensors | select('is_number') | map('float') | list %} {% if valid_sensors | length > 0 %}
          {{ (valid_sensors | sum) / (valid_sensors | length) }}
        {% else %}
          0
        {% endif %}
    action: mqtt.publish
    

Výpočet COP

Pre výpočet COP je možné vytvoriť template v configuration.yaml, ktorý ho bude vypočítavať zo vzorca výkon/príkon

template:
  - sensor:
    - name: "MiniHPC COP"
      unique_id: "minihpc_cop"
      state: >
        {% set vykon = states('sensor.minihpc_vykon') | float(0) %}
        {% set prikon = states('sensor.minihpc_prikon') | float(1) %}
        {% if vykon == 0 or prikon == 0 or
              states('sensor.minihpc_vykon') in ['unavailable', 'unknown'] or
              states('sensor.minihpc_prikon') in ['unavailable', 'unknown'] %}
          unavailable
        {% else %}
          {{ (vykon / prikon) | round(2) }}
        {% endif %}
      icon: mdi:chart-line
      state_class: measurement
      device_class: power_factor