Skip to content
Jasper Slits edited this page Apr 3, 2022 · 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
fan:
  - platform: mqtt
    device:
      identifiers: nrg-itho-1
      model: ITHO Wifi Add-on
      name: ITHO-WIFI
    availability_topic: itho/lwt
    unique_id: nrg-itho-1
    name: nrg-itho-1_fan
    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, adjust where needed. Uncomment the preset_mode_command_template if you want to control the device via virtual remotes.

The config below assumes Normalize keys is Off in the module’s System settings page.

fan:
  - platform: mqtt
    name: "HRU 350"
    unique_id: "Itho_Fan"
    state_topic: "itho/lwt"
    state_value_template: "{% if value == 'online' %}ON{% else %}OFF{% endif %}" 
    command_topic: "itho/cmd"
    preset_mode_state_topic: "itho/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 == 24 %}
            auto
          {% else %}
            {{ am }}
          {% endif %}
    preset_mode_command_topic: "itho/cmd"
    preset_modes:
       - "low"
       - "medium"
       - "high"
       - "auto"
       - "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):

sensor: 
  - platform: mqtt
    name: "ITHO Temperature"
    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):

sensor: 
  - platform: mqtt
    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.

sensor: 
 - platform: mqtt
    name: Itho <unit> CO2
    state_topic: "itho/remotesinfo"
    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.

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_speed
      target:
        entity_id: fan.itho_fan
      data:
        speed: high
    - wait_template: ''
      timeout: '00:15:00' # trigger low speed after 15 minutes
      continue_on_timeout: true
    - service: fan.set_speed
      target:
        entity_id: fan.itho_fan
      data:
        speed: low
  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. It sets fan to high if humidity is 70% or higher for 5 minutes. If humidity decreases to 60% or lower, set preset to low.

  • id: '1636121777685' alias: Itho - Bathroom description: 'Humidity controlled fan speed' trigger:
    • platform: numeric_state entity_id: sensor.bathroom_hum above: '70' for: hours: 0 minutes: 5 seconds: 0 milliseconds: 0 condition: [] action:
    • service: fan.set_preset_mode data: preset_mode: high target: entity_id: fan.itho_fan
    • wait_for_trigger:
      • platform: numeric_state entity_id: sensor.bathroom_hum below: '60'
    • service: fan.set_preset_mode target: entity_id: fan.itho_fan data: preset_mode: low mode: single

### 2. TODO: Why is this needed?

```yaml
- 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_speed
      target:
        entity_id: fan.itho_fan
      data:
        speed: low

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

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

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