Building a template - dont get it

Hi guys,

I just want to have single buttons for switching on and off several light groups and my covers. I understood that I need a template for that but to be honest that seems two levels about what I can or better what I understood. There are several examples in the doc but I have the feeling none of them are what I´m looking for.

Also what is the difference between a template and script?

Hope someon can help me with my confusion :slight_smile:

Thanks a lot,

Flo

I don’t understand what your “single buttons” should do exactly. Turn on/off multiple entities? Or turn on/off different things based on the state of another thing?

A script executes multiple actions in a sequence. A template is used for multiple things, to extract values and from an input/entity and modify them or to create advanced conditions/trigger/actions in automations.

It’s meant just to turn on the ground floor lights on or if with a single button. Same for my covers. I want to create a HomeKit Like Button with the custom button card to do so.

And thanks for the explanation :slight_smile:

Write an automation that turns on/off what you need and link it to an input boolean switch.

eg.

input_boolean.yaml

vacuum:
  initial: off

automation.yaml

# VACUUM START #
- alias: Vacuum Start
  initial_state: true
  hide_entity: true
  trigger:
    platform: state
    entity_id: input_boolean.vacuum
    from: 'off'
    to: 'on'
  action:
    service: vacuum.start
    entity_id: vacuum.xiaomi_vacuum_cleaner

# VACUUM STOP #
- alias: Vacuum Stop
  initial_state: true
  hide_entity: true
  trigger:
    platform: state
    entity_id: input_boolean.vacuum
    from: 'on'
    to: 'off'
  action:
    service: vacuum.return_to_base
    entity_id: vacuum.xiaomi_vacuum_cleaner

This is probably easily solved with a light gorup ant the light.toggle service.

For the covers try @kanga_who suggestion or maybe you can write a JS template in lovelace ttat determines the needed service based on the states of the entities.

Yeah, a template light is easy as well. This example uses a scene to active a group of lights, called “bedroom lights”, but you can easy make a group and just call the light.turn_on service in place of homeassistant.turn_on

eg:

lights.yaml

- platform: template
  lights:
    bedroom_lights:
      friendly_name: Bedroom Lights
      value_template: "{{ is_state('group.bedroom_lights', 'on') }}"
      turn_on:
        service: scene.turn_on
        entity_id: homeassistant.bedroom_lights
      turn_off:
        service: homeassistant.turn_off
        entity_id: group.bedroom_lights
1 Like

Thanks guys :slight_smile:

“Easy” is relative :wink: for me it’s currently hard to dig into this stuff because of Kids, Job and despite i understand English to a certain level when it comes to this I need to surrender :slight_smile:

I will try it in the evening and give you guys feedback.