Different actions depends on given condition - is it possible? - SOLVED

I’m trying to setup an automation to take care of my Thermostats. For the beginning I would like to start with something simple like changing temperature at some specific hours to achieve day and night mode.
My understanding is that I can trigger the automation twice a day simply using time platform and “or” in trigger section. Next should come Condition and finally an Action and here is where I’m having a problem. Is it possible to have two different actions executed (set_temp1 and set_temp2)base on given condition? From HA documentation I understand we can check either single condition either combinations with “or” nad “and”. What I’m missing here is something like “else” in other programming languages. This would allow me to execute second action in case Condition is giving FALSE result.

Her is what I’m trying to get:

Trigger: time_1 or time_2
Condition: if time = time_1 do this else do that

Any idea on how to handle it?

Something like…

automation:
  alias: 'set temperature based on time'
  trigger:
    - platform: time
      at: [TIME_1]
    - platform: time
      at: [TIME_2]
  action:
    service: climate.set_temperature
    data_template:
      entity_id: [YOUR_THERMOSTAT]
      temperature: >
      {% if now().hour == 'TIME_1_HOUR' }
        TEMP_1
      {% else %}
        TEMP_2
      {% endif %}

Thanks a lot. This is exactly what I needed, and I don’t mean a ready solution but template example. I’m totally new in templating but have some old times programming experience. After your reply I went through Jinija2 documentation and I think I finally got an idea on how to use it. I was playing with template module in HA and finally came up with a working automation - thanks again for your help.

1 Like