Two conditions in one condition - tricky part

Hello,
from a few hours I’m trying to make the conditions which allows me to do this:
if trigger.from state and trigger.to_state doesnt’ have a word ‘ONLINE’ in state then it’s true

or the other way:
if trigger.from_state is ‘ONLINE’ and trigger.to_state is ‘BOOST ONLINE’ than it’s false
else if trigger.from_state is ‘BOOST ONLINE’ and trigger.to_state is ‘ONLINE’ than it’s false
else is true
for example:

         - condition: template
            value_template: >-
              {% if states('trigger.from_state') != "ONLINE" and states('trigger.to_state') != "BOOST ONLINE" %}
                true
              {% elif states('trigger.to_state') != "ONLINE" and states('trigger.from_state') != "BOOST ONLINE" %}
                true
              {% else %}
                false
              {% endif %}

but it doesn’t work as expected. Where I’m wrong?
Please help :frowning:

Try it with:

{% if trigger.from_state.state != "ONLINE" and trigger.to_state.state != "BOOST ONLINE" %}
...

because you don’t need to use states with trigger, it’s already there.

Try this (EDITED - should be and, not or)

- condition: template
   value_template: >-
     {{ not (trigger.from_state.state.count("ONLINE") and trigger.to_state.state.count("ONLINE")) }}

or, more readable

- condition: template
  value_template: >-
    {% set state = 'ONLINE' %}  
    {{ not (state in trigger.from_state.state and state in trigger.to_state.state) }}
1 Like

Your solution is true if any trigger doesn’t have ‘ONLINE’ word in the state. But when I’ve changed ‘or’ to ‘and’ it’s working what’ I’m expected. Thank you very much! :slight_smile:
My solution is:

  condition:
          - condition: template
            value_template: >-
              {{ not (trigger.from_state.state.count("ONLINE") and trigger.to_state.state.count("ONLINE")) }}

Thank you for suggestion, after my modificatoin it’s also working :slight_smile:

  condition:
          - condition: template
            value_template: >-
              {% if trigger.from_state.state == "ONLINE" and trigger.to_state.state == "BOOST ONLINE" %}
                false
              {% elif trigger.from_state.state == "BOOST ONLINE" and trigger.to_state.state == "ONLINE" %}
                false
              {% else %}
                true
              {% endif %}

ok, I thought your

is just another way to explain the same condition.

Looking at your original post, it’s definitely and, not or :wink: