Skip to content
Arjen Hiemstra edited this page Mar 14, 2023 · 40 revisions

Integration with Home Assistant using MQTT

Objective

The objective is to control the (non-)CVE fan within Home Assistant and show relevant sensors.

An example of the CVE unit with humidity and other sensors looks like this:
Picture of configured Home Assistant entity card

Pre-requisite

  1. The "medium" setting needs to be enabled (see main setup for CVE)
  2. MQTT broker must be running and reachable by the add-on
  3. MQTT must be activated in Home Assistant in configuration.yaml.
  4. MQTT must be activated in "MQTT" page on the add-on Web interface Applies to pre-2.3 versions only: change "State topic" to itho/state and "Itho Status topic" to itho/ithostatus

Recommendation is to leave all MQTT defaults as-is and only enter IP-address, username & password. Username and password must match the one used for MQTT broker, add-on and Home Assistant.

Note: MQTT brokers can run without credentials but it's recommended as a best practice to secure it even on the local network.

MQTT enabling in Home Assistant

  1. Install a broker (e.g. mosquitto) manually or via Home Assistant Add-ons. MQTT broker configuration is out of scope for this project as this is covered in many tutorials already.

  2. Configure MQTT in Home Assistant by adding the following to configuration.yaml

# Example configuration.yaml entry which assumes MQTT_USERNAME and mysecretpassword are the credentials for the MQTT broker and created via mosquitto_passwd

mqtt:
  broker: "IP_ADDRESS_BROKER"
  username: "MQTT_USERNAME"
  password: !secret MQTT_PASSWORD

Create or edit secrets.yaml and add:

MQTT_PASSWORD: mysecretpassword
  1. Restart Home Assistant and verify there is no connection error by checking the logs (Configuration / Logs).

Adding device to Home Assistant

Integrating the add-on with Home Assistant can be done via different options.

Option 1: Auto-discovery (CVE only)

With MQTT Auto-discovery turned on in the "MQTT" menu of the add-on, the add-on should show up under Configuration -> Devices as a fan. Search for "Itho" and you should see 1 device. After clicking on it, you should see the fan registered as entity. Under "Device info" click on "MQTT Info" to see the received MQTT messages.

Option 2: Manual configuration (CVE only)

To manually add the fan, edit configuration.yaml and restart Home Assistant when done.


# Itho daalderop MV www.nrgwatch.nl
mqtt:
  fan:  
    - name: nrg-itho-1_fan
      availability_topic: itho/lwt
      unique_id: nrg-itho-1
      state_topic: itho/lwt
      state_value_template: '{% if value == ''online'' %}ON{% else %}OFF{% endif %}'
      json_attributes_topic: itho/ithostatus
      command_topic: itho/cmd/not_used/but_needed_for_HA
      percentage_command_topic: itho/cmd
      percentage_command_template: '{{ value * 2.54 }}'
      percentage_state_topic: itho/state
      percentage_value_template: '{{ ((value | int) / 2.54) | round}}'  

Option 3: Manual configuration (non-CVE only)

Auto-discovery for non-CVE (E.g. Demandflow/QualityFlow/HRU-350) today does not work as there is no fan speed. Edit configuration.yaml and add the following and adjust where needed. Comment the preset_mode_command_template if you want to control the device via an RF remotes. This is useful when you don't have the CC1101 module. This example uses a virtual remote.

The config below assumes:

  • Normalize keys is Off in the module’s System settings page
  • Home Assistant MQTT Discovery is Off in the module's MQTT settings page.
mqtt:
    fan:
     - name: "Itho HRU 350 "
       unique_id: "Itho_hru_Fan"
       state_topic: "ithohru/lwt"
       state_value_template: "{% if value == 'online' %}ON{% else %}OFF{% endif %}" 
       command_topic: "ithohru/cmd"
       preset_mode_state_topic: "ithohru/ithostatus"
       preset_mode_command_template: "{ vremote: '{{ value }}'}"
       preset_mode_value_template: >
        {% set am = value_json['Actual Mode'] | int %}
          {% if am == 1 %}
            low
          {% elif am == 2 %}
            medium 
          {% elif am == 3 %}
            high
          {% elif am == 13 %}
             timer
          {% elif am == 24 %}
            auto
          {% elif am == 25 %}
            autonight
          {% else %}
            {{ am }}
          {% endif %}
       preset_mode_command_topic: "ithohru/cmd"
       preset_modes:
        - "low"
        - "medium"
        - "high"
        - "auto"
        - "autonight"
        - "timer1"
        - "timer2"
        - "timer3"

Sensors in Home Assistant

The above configuration only makes the fan available as entity. Additional sensors might be available to report CO2 (via Remote), Humidity percentage and temperature.

Temperature sensor

Add following to sensor configuration (e.g. sensors.yaml or configuration.yaml):

mqtt:
  sensor:
    - name: "ITHO Temperaturee"
      state_topic: "itho/ithostatus"
      unit_of_measurement: "°C"
      value_template: "{{ value_json.temp }}"
      device_class: "temperature"
      unique_id: "itho_temp"

Humidity sensor

To display humidity (if supported by the unit), add following to sensor configuration (e.g. sensors.yaml or configuration.yaml):

    - name: "ITHO Humidity"
      state_topic: "itho/ithostatus"
      unit_of_measurement: "%"
      value_template: "{{ value_json.hum }}"
      device_class: "humidity"
      unique_id: "itho_hum"

CO2 sensor

MQTT home assistant setup for CO2 sensor (via Itho remote) If you have a remote that also shows the CO2 level, this can be visualised in Home Assistant.

mqtt:
 sensor: 
  - name: Itho <unit> CO2
    state_topic: "itho/remotesinfo"
    unit_of_measurement: "ppm"
    value_template: "{{ value_json.<unit>.co2 }}"
    device_class: "carbon_dioxide"
    unique_id: "itho_<unit>_co2"

Replace with the name given in the Add-on RF Remotes page.

Extracting values from labels with special characters

To ensure the correct parsing of JSON labels you can use the bracket notation. ie. value_json['Fan speed (rpm)'] for the value of label 'Fan speed (rpm)'. This also works nested. For a JSON {"first level":{"nested level":10}} the statement value_json['first level']['nested level'] would pass the value 10 to home assistant.

mqtt:
  sensor:
    - name: "ITHO rpm sensor"
      state_topic: "itho/ithostatus"
      unit_of_measurement: "rpm"
      value_template: "{{ value_json['Fan speed (rpm)'] }}"
      unique_id: "itho_rpm"

Show in UI (Lovelace)

While it is possible to add the sensors and fan via YAML to the dashboard, doing this via the UI is easier. To add the Entities card to your user interface, click the Lovelace menu (three dots at the top right of the screen) and then Edit Dashboard. Click the “Add Card” button in the bottom right corner and select Entities from the card picker. You can filter for them by typing 'itho'.

Automation examples

Examples

Some examples for integrating the fan and other data with Home Assistant

1. Increase fan speed when humidity increases (e.g. showering)

This assumes that the CVE Itho unit has a built-in humidity sensor

-----Bathroom humidity and increasing fan speed
- id: "Fan up when showering"
  alias: fan UP when showering
  description: Bathroom humidity and increasing fan speed
  trigger:
    - platform: template   
      value_template: "{{ is_state_attr('fan.itho_fan', 'hum', '50') }}"
      for: "00:10:00" # only triggers if humidity is >50% for 10 minutes or more
  condition: []
  action:
    - service: fan.set_percentage
      target:
        entity_id: fan.itho_fan
      data:
        percentage: 100
    - wait_template: ''
      timeout: '00:15:00' # trigger low speed after 15 minutes
      continue_on_timeout: true
    - service: fan.set_percentage
      target:
        entity_id: fan.itho_fan
      data:
        percentage: 33
  mode: single

3. Set preset to high for high humidity (non-CVE)

Non-CVE without Demandflow/Qualityflow don't have a built-in humidity sensor. This example uses a separate humidity sensor sensor.badkamer_humidity

It sets fan to high if humidity is 70% or higher for 1 minute. If humidity decreases to 60% or lower for 3 minutes, set preset to auto. The timeout ensures it goes to auto after 2 hours regardless of the current humidity.

alias: Itho - Badkamer
description: ''
trigger:
  - platform: numeric_state
    above: '70'
    for:
      hours: 0
      minutes: 1
      seconds: 0
    entity_id: sensor.badkamer_humidity
action:
  - service: fan.set_preset_mode
    data:
      preset_mode: high
    target:
      entity_id: fan.itho_hru_350
  - wait_for_trigger:
      - platform: numeric_state
        below: '60'
        for:
          hours: 0
          minutes: 3
          seconds: 0
        entity_id: sensor.badkamer2_humidity
    timeout: '00:02:00'
  - service: fan.set_preset_mode
    data:
      preset_mode: auto
    target:
      entity_id: fan.itho_hru_350
mode: single

2. TODO: Why is this needed?

- alias: "Set fan slider Itho F"
  trigger:
    platform: mqtt
    topic: 'itho/state'
  action:
    service: input_number.set_value
    data:
      entity_id: input_number.itho_fan_nr
      value: "{{ trigger.payload }}"
- alias: "Fan slider itho<description> moved"
  trigger:
    platform: state
    entity_id: input_number.itho_fan_nr
  condition:
    condition: template
    value_template: "{{ states('sensor.itho_status_<unit2>_fan') | int != states('input_number.itho_0b08_fan') | int }}"
  action:
    service: mqtt.publish
    data:
      topic: 'itho/cmd'
      retain: true
      payload: "{{ states('input_number.itho_fan') | int }}"

When showering (rising humidity) increase fan speed


To create a 3 button interface (scripts.yml)

#-----Mechanical ventilation presets
mv_preset_low:
  alias: MV preset low
  icon: mdi:fan-speed-1
  sequence:
    - service: fan.set_percentage
      target:
        entity_id: fan.itho_fan
      data:
        percentage: 33

mv_preset_medium:
  alias: MV preset medium
  icon: mdi:fan-speed-2
  sequence:
    - service: fan.set_percentage
      target:
        entity_id: fan.itho_fan
      data:
        percentage: 50

mv_preset_high:
  alias: MV preset high
  icon: mdi:fan-speed-3
  sequence:
    - service: fan.set_percentage
      target:
        entity_id: fan.itho_fan
      data:
        percentage: 100

The Lovelace part for using the buttons on the UI

            - title: Mechanische ventilatie
              type: entities
              entities:
                - entity: input_number.fan_itho_speed
                  name: Fan
                  icon: mdi:fan
                - entity: sensor.fan_itho_state
          
            - type: horizontal-stack
              cards:
                - type: button
                  show_name: false
                  show_state: false
                  icon_height: 75px
                  entity: script.mv_preset_low
                  tap_action:
                    action: call-service
                    service: script.turn_on
                    service_data:
                      entity_id: script.mv_preset_low

                - type: button
                  show_name: false
                  show_state: false
                  icon_height: 75px
                  entity: script.mv_preset_medium
                  tap_action:
                    action: call-service
                    service: script.turn_on
                    service_data:
                      entity_id: script.mv_preset_medium

                - type: button
                  show_name: false
                  show_state: false
                  icon_height: 75px
                  entity: script.mv_preset_high
                  tap_action:
                    action: call-service
                    service: script.turn_on
                    service_data:
                      entity_id: script.mv_preset_high
Clone this wiki locally