Help with automation!

hello again! and now im wokring on gettign something automate.

The deal im trying to do is as follows. When my wife’s phone is registered as home for the switch.dresser_fan to turn on.

This is what i put in my config file:

automation:
   trigger:
     platform: state
     entity_id: device_tracker.androidXXXX
     from: 'not_home'
     to: 'home'
   action:
     service: switch.turn_on
     enitity_id: switch.dresser_fan
```

So what am i missing here? im using my asus router to track presence, and ive watched it register changes in presence just fine.

once again, thanks for being such a helpful and welcoming community. once im good enough to know something ill do my best to help others out too!

EDIT: the switch im trying to turn on is a standard wemo switch

Are you getting any errors?
Or is nothing happen?

Are sure you have the right entity id for the phone?
Go to localhost:8123/devState and make sure you can find the phone

im not getting any errors, its just not happening.

and yes ive checked the entity_ids.

(I feel a little bit proud that im starting to catch on to this :D)

does the automation: header need to be in a specific place or in a certain order?

Is that your only automation? If you have more than one you’ll have to use a list of automations or automation: automation 2:

Tis my only one for now.

UPDATE: ive changed the code to now look like this:

automation:
    alias: 'Fan Test'
    trigger:
      platform: state
      entity_id: device_tracker.androidXXX
      from: 'not_home'
      to: 'home'
    action:
      service: switch.turn_on
      enitity_id: switch.dresser_fan
```

i figured it out!! thanks everyone!!

if u look at my final line of code…i had stupidly written entity as enitity with that extra “i”…oops…

ive gotta get better at my spell check

EDIT: quick question then…if i wanted to add an “or” to the trigger like “if this device OR this device is detected”…how would i do that?

Add a second trigger, either one will fire the event:

trigger:
  - platform: state
    entity_id: device_tracker.androidXXX
    from: 'not_home'
    to: 'home'
  - platform: state
    entity_id: device_tracker.device2
    from: 'not_home'
    to: 'home'

ah ok, i had gone and made it a whole separate alias.

i then want to make it so that if both devices arent there it turns off…i can do this just by saying

entity_id: device_1, device_2
from: 'home'
to: 'not_home'

and separating only with that comma right? that will make it so that if both devices are not_home it will switch.turn_off, but not only when one leaves.

I’ll have to defer to the crowd on that one. I’m not sure if comma separating the entities is treated as an “and” or “or”. If it’s “or” you could use that in place of what I recommended above, but in that case you would want to probably create a group with those 2 devices and use that as the trigger for your second problem, that way the group will only change to “not_home” when they are both away. Again, I’m not entirely clear on that.