Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95468

Is it possible to use template to avoid repeating automation code?

$
0
0

@ccmtozzi wrote:

I’m building an automation to mark a room occupied if there was movement in the last 30 minutes, but I need to this to 10 different rooms, so far I’m just copying past the code, but I wonder if there is a way to this better.

Right now the code for 1 item looks like this:

input_boolean:
  living_room_occupancy:
    name: 'Living Room Occupancy'
    initial: off

automation:
  ## Living Room
  - alias: Living Room Occupied
    trigger:
      platform: state
      entity_id: binary_sensor.living_room_sensor
      to: 'on'
    action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.living_room_occupancy

  - alias: Living Room Away
    trigger:
      platform: state
      entity_id: binary_sensor.living_room_sensor
      to: 'off'
      for:
        minutes: 30
    action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.living_room_occupancy

I do get that I would need to create the 10 input_boolen, and that is not a big deal, but copy/past 10 time the automation is kind of annoying sine the name are the same!

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95468

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>