Unless I’m misunderstanding something, you don’t need a service template for this. You can just call switch.turn_off for any entities you want to turn off, or use entity_id: all if you want all of them turned off.
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.
thats because you dont have a service after the else which is the point of my post above. to quickly test if its working add the same service switch.turn_off so in both cases it switches off
the added scripts I mention would use a do-nothing script, and a sub script with your current settings:
- service_template: >
script.{{'mybraviatv' if is_state('switch.braviatv', 'on') else 'continue'}}