Please check my "dehumidification automation"

Hello,
I am new to the world of HA and am trying to port my FHEM scripts.
In FHEM I had a well-functioning dehumidification automation.
The script looked like this:

`+*00:29 IF ((ReadingsVal('OUT_THSensor','humidity',0) < 80) && (ReadingsVal('Wk_THSensor','dewpoint',0) > (ReadingsVal('OUT_THSensor','dewpoint',0) + 3) || ReadingsVal('Wk_THSensor','dewpoint',0) > (ReadingsVal('OUT_THSensor','dewpoint',0) + 3)) && ReadingsVal('Wk_THSensor','humidity',0) > 70) (set Wk_dehumi on) ELSE (set Wk_dehumi off)`

In HA I have now implemented this as follows:

  alias: ' check dehumidification WK @ every 30 min'
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /30
  condition:
  - condition: or
    conditions:
    - condition: template
      value_template: '{% if (states(''sensor.out_thsensor_humidity'') | float < 80)
        and (states(''sensor.in_thsensor_dewpoint'') | float) > (states(''sensor.out_thsensor_dewpoint'')
        | float + 3) %}{%- endif %}'
    - condition: template
      value_template: '{% if (states(''sensor.out_thsensor_humidity'') | float < 80)
        and (states(''sensor.in_thsensor_dewpoint'') | float) > (states(''sensor.out_thsensor_dewpoint'')
        | float + 3) %}{%- endif %}'
  action:
  - type: turn_on
    device_id: f708750669066116f7a5a38adf9fd2c6
    entity_id: switch.ventilator_decke_wk
    domain: switch
  - service: switch.turn_on
    data: {}
    entity_id: switch.ventilator_wand_wk
  - wait_template: ''
    timeout: 00:35:00
  - type: turn_off
    device_id: f708750669066116f7a5a38adf9fd2c6
    entity_id: switch.ventilator_decke_wk
    domain: switch
  - service: switch.turn_off
    data: {}
    entity_id: switch.ventilator_wand_wk
  mode: single

I built this with the development tool.
At least there are no error messages. will that work?

best regards
Dominik

Pretty close.

Your condition templates need to return a boolean true or false result though. What you have is empty if statements that return nothing. Try it like this instead:

  condition:
  - condition: or
    conditions:
    - condition: template
      value_template: >
        {{ ( states('sensor.out_thsensor_humidity')|float < 80 ) and 
        ( states('sensor.in_thsensor_dewpoint')|float ) > ( states('sensor.out_thsensor_dewpoint')|float + 3 ) }}
    - condition: template
      value_template: >
        {{ (states('sensor.out_thsensor_humidity') | float < 80) and 
        (states('sensor.in_thsensor_dewpoint')|float) > (states('sensor.out_thsensor_dewpoint')|float + 3) }}

The comparison operations ==, >, <, >= and <= return boolean true or false results. And you have combiled them correctly with logic (and) so the templates will now return boolean results and the conditions will pass if either of the templates returns true (“do if true”).

You also had your templates over multiple lines, (I assume for for readability). In this case you must use the multi-line character > on a line by itself and remove the quotes from around your template.

I have also removed the escaped single quotes inside the template as these are no longer necessary as there are no quotes outside a multi line template. The alternative is to use double quotes outside and single quote inside the template for a single line template, e.g.

      value_template: "{{ (states('sensor.out_thsensor_humidity') | float < 80) and (states('sensor.in_thsensor_dewpoint')|float) > (states('sensor.out_thsensor_dewpoint')|float + 3) }}"
1 Like

That’s great. Many thanks.
I also built in my condition twice. That is of course wrong.
My condition now looks like this:

"{{ (states('sensor.in_thsensor_humidity') | float > 70) and (states('sensor.in_thsensor_dewpoint')|float) > (states('sensor.out_thsensor_dewpoint')|float + 3) }}"
"{{ (states('sensor.out_thsensor_humidity') | float < 80) and (states('sensor.in_thsensor_dewpoint')|float) > (states('sensor.out_thsensor_dewpoint')|float + 3) }}"