Help with template sensor and negative state

- platform: template
  sensors:
    presence:
      friendly_name: "Giannis Home"
      value_template: >-
        {% if is_state('person.elena', 'not_home') and is_state('person.giannis', 'home') %}
           on
        {% else %}
           off
        {% endif %}

Is there anyway to configure the fisrt part of this sensor to be true if person.elena is not at home? I mean like this it works, but as soon as person.elena enters one other zone then it wont be true even if person.elena is not home. I need something like this

- platform: template
  sensors:
    presence:
      friendly_name: "Giannis Home"
      value_template: >-
        {% if is_state('person.elena', =! 'home') and is_state('person.giannis', 'home') %}
           on
        {% else %}
           off
        {% endif %}

{% states('person.elena') != 'home' and is_state('person.giannis', 'home') %}``Preformatted text

1 Like

Or might be better with …

{{ not is_state('person.elena', 'home') and is_state('person.giannis', 'home') }}
1 Like

Isn’t this just the state of person.giannis?

That is to say that you have giainis at home, or you have elena at home, or both, or none.

So rather than having 4 template sensors for these eventualities, just use the individual person entities for the first 2, and a group for the latter two.

I don’t think so … I think they want the sensor true when giannis is home and elena is not home (i.e. when giannis is home alone).

That’s the way I read it.

Yeah I see that, but I’m trying to see where this would be used, and if you had a group with giainis and elena in it, then either both are home (group is home), neither are home (group is not_home), or one person is home (whichever person is). So the 4 template sensors that would otherwise establish these states are redundant imo.

I suppose you could use the sensors as a shortcut for a trigger/condition or two, but realistically for the number of times these sensors are actually going to be used it’s just duplicating data that’s already there.

One template sensor that returns a result of ‘all’, ‘Gianni’, ‘Elena’ or ‘none’ would probably be a better fit if there’s actually likely to be a number of uses.

I guess it would help to know more about their specific use case.

This is just an example, i have many other sensor that i want to use with a similar expression .

Jonah1970 gave me the right syntax i guess.