Trying to template device_tracker as an automation trigger based on input_select

Hello all;

So as the title says, I am trying to template my automation trigger to start when a particular device, or group of devices arrive at home - based on an input_select on my front end. This would eventually trigger my vaporizer to start when one or both of us come home - based on who filled the device and is feeling in the mood.

I have been playing with this for the last few days and can’t seem to get it to work. Any help would be greatly appreciated.

This is what I have so far for the automation trigger:

- id: 'au_Arizer_Balloon_Fill'
  alias: "au_Arizer_Balloon_Fill"
  trigger:
    platform: template
    value_template: >-
        {% if is_state('input_select.vape_select', 'Stiofán') %}
        entity_id: device_tracker.sdg_iphone
        from: 'not_home'
        to: 'home'
        {% elif is_state('input_select.vape_select', 'Gab') %}
        entity_id: device_tracker.gabs_droid
        from: 'not_home'
        to: 'home'    
        {% elif is_state('input_select.vape_select', 'Both') %}
        entity_id: group.vape_select_group
        from: 'not_home'
        to: 'home'
        {% endif %}

Yeah, that’s not going to work. A template trigger needs to evaluate to true/false.

It would be better to just trigger on all of the devices and have a condition check if they are all home.

- alias: "au_Arizer_Balloon_Fill"
  trigger:
    # Trigger on all devices
    platform: state
    entity_id:
      - device_tracker.sdg_iphone
      - device_tracker.gabs_droid
    to: 'home'
  condition:
    # Now compare the devices home to those in the input select
    condition: template
    value_template: > 
      {% set v = state('input_select.vape_select') %}
      {% set g = is_state('device_tracker.gabs_droid', 'home') %}
      {% set s = is_state('device_tracker.sdg_iphone', 'home') %}
      {% if v == 'Both' %}   {{ g and s }}
      {% elif v == 'Gab' %} {{ g }}
      {% elif v == 'Stiofán' %} {{ s }}
      {% else %} False
      {% endif %}
  action:
     ...
1 Like

Hello Jim!

Thanks for your reply. I’ll give that a shot and see how it goes.

Thanks very much!

I guess, there is one thing to consider.

If you have it set to ‘Gab’ and she is home, then you go home, this will fire again because “Gab is set and g is home”

Hmmmmm, the 'input_select.vape_select' should define which one the automation seeks to detect - rather than who’s home or not. I’m still trying to wrap my head around the automation actually. Your code is a seriously good start for me though. I wouldn’t have come up with that in years.

It does that. But the trigger is what was messing you up.

this does the same thing whenever any phone comes home. It looks at the input select to see if the person(s) in the select are home.

But, as is, there is no redundancy checking. So if g is already home and the automation already ran, then you came home, it would run again because it’s only looking to see if Gab is home when the trigger happens.

I would just add another condition. Like, make sure the switch is off. If it’s already on, don’t do anything.

condition:
  - "{{ is_state('switch.vape', 'off') }}"
  - condition: template
    value_template: > (same as above)

Either that, or Gab will be vaping a lot! :dizzy_face:

Thanks for your help, I’ll give that a try.