TTS notification when people leave a zone, and when they should be home

I have this automation, and it works well. I just want to add a condition that keeps this from triggering when the person has left home. I figure I already know they left home.

Thought this would be useful for others though, just want that one condition. I think I would want
trigger.from_state.state to =! home? But not 100% sure of the syntax. Looking through the community, I saw a few similiar examples, but was confused because the other examples had the condition as part of the action??

I’m using the waze commute tracker to provide the how long to home, and I’m using the new custom component for TTS, but any TTS component would work.

- alias: PersonTravel Notice
  trigger:
  - platform: state
    entity_id: device_tracker.person_iphone
    to: 'not_home'
  condition:
  - condition: numeric_state
    entity_id: sensor.ha_runtime_in_minutes
    above: 1
  - condition: state
    entity_id: binary_sensor.me_presence
    state: 'on'
  action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.commute_start_zone_person
      value: '{{ trigger.from_state.state }}'
  - service: script.audio_notify
    data_template:
      tts_msg: "Person left {{ states('input_text.commute_start_zone_person') }} at {{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} and should be home in approximately {{ states('sensor.person_time_to_home') }} minutes."
      mplayer: "all"

I know this wont work, but basically this concept. I want this to run for leaving any zone other than home

condition:
    - condition: state
      entity_id: trigger.from_state.state
      state: was not home (not the same as not_home, haha)

Would this work?

  - condition: template
    value_template: "{{ 'trigger.from_state.state' != 'Home') }}"

Close:

  - condition: template
    value_template: "{{ trigger.from_state.state != 'home') }}"
1 Like

Awesome,thanks. .

For anyone else using the alexa TTS or similar who would like a TTS when someone leaves a zone.

- alias: Person Travel Notice
  trigger:
  - platform: state
    entity_id: device_tracker.person_iphone
    to: 'not_home'
  condition:
  - condition: numeric_state
    entity_id: sensor.ha_runtime_in_minutes
    above: 1
  - condition: state
    entity_id: binary_sensor.me_presence
    state: 'on'
  - condition: template
    value_template: "{{ trigger.from_state.state != 'home' }}"
  action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.commute_start_zone_person
      value: '{{ trigger.from_state.state }}'
  - service: script.audio_notify
    data_template:
      tts_msg: "Person left {{ states('input_text.commute_start_zone_person') }} at {{ as_timestamp (now()) | timestamp_custom('%I:%M %p') }} and should be home in approximately {{ states('sensor.person_time_to_home') }} minutes."
      mplayer: "main"

Requirements:
A sensor for travel time - sensor.person_time_to_home (i’m using waze)
Some sort of TTS (or other notification option)
Device tracker and zones set up.

No go on the template for !home, need to check again, received this error

2018-08-15 18:02:16 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected ‘)’) for dictionary value @ data[‘condition’][2][‘value_template’]. Got None
not a valid value for dictionary value @ data[‘condition’][2][‘condition’]. Got None
required key not provided @ data[‘condition’][2][‘entity_id’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 287). Please check the docs at https://home-assistant.io/components/automation/

Oops, I missed you had an extra paren … should be:

  - condition: template
    value_template: "{{ trigger.from_state.state != 'home' }}"
1 Like

Thanks. I totally missed it myself. Updated above. And it should work not. :slight_smile: