Help turn two automations into one

Hi,
I’m trying to clean up all my automation and in some cases turn two into one…

- alias: Home Status David
  trigger:
    - platform: state
      entity_id: input_boolean.occupancy_david_home
      from: 'off'
      to: 'on'
  action:
    - service: device_tracker.see
      data:
        dev_id: david
        location_name: home
        source_type: bluetooth

- alias: Not Home Status David
  trigger:
    - platform: state
      entity_id: input_boolean.occupancy_david_home
      from: 'on'
      to: 'off'
  action:
    - service: device_tracker.see
      data:
        dev_id: david
        location_name: not_home
        source_type: bluetooth

is it possible to combine the two above into one?

if the input changes complete the correct action.

Yep, you could do something like this:

- alias: Home Status David
  trigger:
    - platform: state
      entity_id: input_boolean.occupancy_david_home
  action:
    - service: device_tracker.see
      data_template:
        dev_id: david
        location_name: "{{ 'home' if trigger.to_state.state == 'on' else 'not_home' }}"
        source_type: bluetooth

This will trigger whenever the state of that flippy boi input boolean changes and update the location name appropriately: home if it changes to on, not_home if it changes to off (technically anything else, but an input_boolean can only be on or off).

1 Like

wow super clean.

thank you

1 Like