Mold sensor with dynamic calibration factor

Hello everyone, I’m currently tinkering with the mould sensor and I’m not really getting anywhere. My configuration currently looks like this:

        #######################################################################################################################################
        #
        #   Dachflächenfenster - "Kalibrierungsfaktor Bad":
        #   temp_indoor		    = sensor.0x00158d0004069a3f_temperature			    = Badtemperatur
        #   temp_outdoor		= sensor.niederschlagssensor_device_temperature		= Dachtemperatur
        #   temp_criticalpoint	= sensor.0x00158d000251ea28_device_temperature		= Fenstertemperatur
        #
    
        #######################################################################################################################################

    - platform: template
      sensors:
        calibration_factor_bathroom:
          friendly_name: "Kalibrierungsfaktor Bad"
          value_template: "{{ (states('sensor.0x00158d0004069a3f_temperature') | float - states('sensor.niederschlagssensor_device_temperature') | float) / (states('sensor.0x00158d000251ea28_device_temperature') | float - states('sensor.niederschlagssensor_device_temperature') | float) }}"
            
    -   platform: mold_indicator
        name: Schimmelsensor Bad
        indoor_temp_sensor: sensor.0x00158d0004069a3f_temperature
        indoor_humidity_sensor: sensor.0x00158d0004069a3f_humidity
        outdoor_temp_sensor: sensor.0x00158d000238a37c_temperature
        calibration_factor: sensor.calibration_factor_bathroom

My idea was to calculate the calibration factor for the sensor dynamically, as the conditions are constantly changing:

Mold Indicator - Home Assistant → calibration factor

calibration_factor = (temp_indoor - temp_outdoor) / (temp_criticalpoint - temp_outdoor)

I have the problem that the mould sensor expects the calibration factor as float and does not accept a template. Somehow I don’t understand how this is supposed to work - surely the calibration factor is constantly changing?

How did you solve this?

1 Like

Hmmmh, no idea? :confused:

Up! (10 Chars)

Hello hebang2,

this is quite an old topic, but since no solution has been provided yet, I’d like to share mine:

      - name: "Outdoor Temperature"
        unique_id: "outdoor_temperature"
        unit_of_measurement: "°C"
        state: "{{ state_attr('weather.forecast_zuhause', 'temperature') }}"
        unique_id: calibration_factor_schlafzimmer
        unit_of_measurement: ""
        state: >
          {% set temp_indoor = states('sensor.temperatursensor_zigbee_schlafzimmer_temperature') | float(0) %}
          {% set temp_outdoor = states('sensor.outdoor_temperature') | float(0) %}
          {% set temp_criticalpoint = states('sensor.temperatursensor_zigbee_schlafzimmer_fenster_temperature') | float(0) %}
          {% if temp_indoor == 0 or temp_outdoor == 0 or temp_criticalpoint == 0 or temp_outdoor >= temp_criticalpoint %}
            1
          {% else %}
            {{ (temp_indoor - temp_outdoor) / (temp_criticalpoint - temp_outdoor) }}
          {% endif %}

This approach works perfectly for me! :blush:

BR,
Julian

hi @TuxAT, cold you provide complete yaml? I have quite limited knowledge of code.

@TuxAT - can you help me understand as i am not following …

  1. not sure how the “outdoor temperature” is involved besides used in the mold indicator, right?
  2. you create a critical point calculation … which seems great… the problem, for me at least, is how to get it into the sensor mold indicator as it does not seem to accept template values ? (!) in either the helper or in the configuration.yaml

your clarification is appreciated!