Template dependent on other template

Hi!
I have two templated Binary Sensors to track two persons presence (person1_home_sensor and person2_home_sensor), and a third one (away_mode) depending on the state of the two first. Like this:

binary_sensor:
  - platform: template
    sensors:
      person1_home_sensor:
        friendly_name: Person1 Home
        device_class: occupancy
        value_template: '{{ is_state("device_tracker.person1_iphone", "home") }}'
      person2_home_sensor:
        friendly_name: Person2 Home
        device_class: occupancy
        value_template: '{{ is_state("device_tracker.person2_iphone", "home") }}'
      away_mode:
        friendly_name: Away Mode
        device_class: occupancy
        value_template: >-
          '{{ "on" if (is_state("binary_sensor.person1_home_sensor", "off") and 
          is_state("binary_sensor.person2_home_sensor", "off")) else "off" }}'

The two first works just like they should, but the away_mode sensor does not update correctly. Testing the templates in the Developer Tools, everything works as I would like, but not with the actual sensors.

Is it not possbile to have a template sensor dependent on other template sensors like this? It would of course be possible with an automation, but this would be much more elegant…

Best regards,
Jonas

because you aren’t returning true/false and you’re using multiline templates but also wrapping your template in quotes. Use one or the other.

      away_mode:
        friendly_name: Away Mode
        device_class: occupancy
        value_template: >
          {{ is_state("binary_sensor.person1_home_sensor", "off") and 
          is_state("binary_sensor.person2_home_sensor", "off") }}

Super! Thanks for the quick response! I guess it is time to start getting into the syntax and not only copying and modifying examples.

Best regards,
Jonas