Input boolean

i have this automation

- id: Avvio_HA_posizione_angela_fuori
  alias: 'Avvio HA posizione angela fuori'
  trigger:
  - event: start
    platform: homeassistant
  - platform: time_pattern
    minutes: "/30"
  condition:
  - condition: state
    entity_id: device_tracker.life360_angela
    state: 'not_home'
  action:
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.presenza_casa_angela

Is it possible to put a condition inside the automation that if I am at home the boolean input goes on, and if i’m not at home it switches off?
thanks

      - service_template: {{ input_boolean.turn_on if is_state('device_tracker.life360_matteo', 'home') else input_boolean.turn_off }}
        entity_id: input_boolean.presenza_casa_angela
1 Like

Why are you using a time_pattern trigger? Why not use a state trigger based on the device_tracker?

Like this:

- id: Avvio_HA_posizione_angela_fuori
  alias: 'Avvio HA posizione angela fuori'
  trigger:
  - event: start
    platform: homeassistant
  - platform: state
    entity_id: device_tracker.life360_angela
    to: 'not_home'
  condition:
  - condition: state
    entity_id: device_tracker.life360_angela
    state: 'not_home'
  action:
  - service_template: "input_boolean.turn_{{ 'on' if is_state('device_tracker.life360_matteo', 'home') else 'off' }}"
    entity_id: input_boolean.presenza_casa_angela

This will trigger the instant angela’s device_tracker indicates not_home as opposed to anywhere from 0 to 30 minutes after (because that’s how it works using the time_pattern trigger).

is correct this??