Simplify automation for greenhouse vent timer

Hi. I am new here. Still learning the automations.
I created simple code for my greenhouse vents timer. I would like to turn the vents at 8.00 AM (or maybe 1-2 hour after sunrise). The vents should be turned on each half hour for 5 minutes if the temperature rises over 20 deg C. I followed the solution of smartynov Simple Automation to Cycle Through Turning a Switch On and Off Regularly.
All runs on PC, Windows 10, VirtualBox, HA with ZHA. Now, the automation works good.

alias: Vklop ventilatorjev Lesenjak
description: Časovni vklop ventilatorjev glede na temperaturo
trigger:
  - platform: time_pattern
    minutes: /30
condition:
  - condition: time
    after: "08:00:00"
    before: "22:00:00"
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.termometer_lesenjak_th02_temperature
        above: 15
      - condition: numeric_state
        entity_id: sensor.termometer_lesenjak_th02_humidity
        above: 80
action:
  - service: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.stikalo_lesenjak_minizb_light
  - delay:
      minutes: 5
  - service: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.stikalo_lesenjak_minizb_light
mode: restart

I dont’t know if I need mode:restart.
The automation should run always and be active even the computer and/or HA is rebooted, so I have also to find a solution to start this it over windows.
Now I would like to add temperature condition: if temperature goes over 35 degC. the vents should turn on each 15 minutes for 5 minutes, or better, the bigger temperature, more frequently and longer the vents should run.
Maybe some of you have better solution?

First of all, please format your code properly. See here — in summary, surround your code with three backticks (```) before and after.

You can do all of what you want. For example:

Trigger with "/15" as the time pattern, and add two conditions ORed together:

  - or:
    - condition: numeric_state
      entity_id: sensor.termometer_lesenjak_th02_temperature
      above: 35
    - "{{ now().minute % 30 == 0 }}"

That will only let flow past if the temperature is above 35 (each 15 minutes) or if the time is divisible by 30 (every 30 minutes).

Thanks Troon. Corrected, I didn’t know how to put the code correctly in.
I am short on templates, I will try to solve it.

1 Like