Service template in automation

this is incorrect and should be

- service_template: > 
    {% if is_state('switch.mybraviatv', 'on') %} switch.turn_off 
    {% endif %}

you’d need an else clause though to be safe, in case the template doesnt evaluate to anything…

And yes, as @Tediore says, you can simply use the turn_off service, even when the entity would already be off, no harm done.
If you use a service_template always use If, else.

added to all that, I suspect your automation is made by the built-in editor? Id strongly suggest to write it like this, for readability’s sake:

- alias: When last person leave home
  id: '1522011348560'
  trigger:
    - platform: state
      entity_id: group.home_booleans
      from: 'on'
      to: 'off'
  condition: []
  action:
    - service: script.1545874111381 # <-- can call the script directly
    - service_template: >
        {% if is_state('switch.coffiemachine', 'on') %}  switch.turn_off
        {% endif %}
      entity_id: switch.coffiemachine
    - service_template: >
        {% if is_state('state.switch.mybraviatv', 'on') %}
          switch.turn_off
        {% endif %}
      entity_id: switch.mybraviatv

but, since you’d need an else clause for both service_templates, and there’s no builtin ‘do nothing’ service with that entity_id, you can’t use the service_template like this.

Creating 2 small scripts you call in the automation could solve that.