Newbie to Automation

I am new to automations but I am trying to do something basic.

I would like one of my sonoff relay to turn on if someone is home and it is 45 mins before sunset. I would also like the relay to turn off if there is no one home or it is after 10:30pm. Below is what I have so far but for some reason it is not triggering properly.

- id: no_one_home
  alias: No one home
  trigger:
  - entity_id: device_tracker.iphone1
platform: state
state: not_home
  - entity_id: device_tracker.iphone2
platform: state
state: not_home
  action:
  - data:
entity_id: switch.extension_cord
service: light.turn_off

- id: lights_on_at_sunset
  alias: Lights on at sunset
  trigger:
  - event: sunset
offset: -00:45:00
platform: sun
  - entity_id: device_tracker.laurensiphone
platform: state
state: home
  - entity_id: device_tracker.codysiphone
platform: state
state: home
  action:
  - data:
entity_id: switch.extension_cord
service: light.turn_on

- id: turn_lights_off_at_night
  alias: Turn lights off at night
  trigger:
  - hours: 22
minutes: 30
platform: time
  action:
  - data:
entity_id: switch.extension_cord
service: light.turn_off

Any assistance would be amazing!

Welcome!!! I think this will do what you need… Feel free to ask questions below!

Edit: If these work I challenge you to add conditions to the first and last automations so that they only trigger if the Sonoff is already on!

- id: no_one_home
  alias: No one home
  trigger:
  - platform: state
     entity_id: device_tracker.iphone1
     from: home
     to: not_home
  - platform: state
     entity_id: device_tracker.iphone2
     from: home
     to: not_home      
  action:
  - service: light.turn_off
    entity_id: switch.extension_cord

- id: lights_on_at_sunset
  alias: Lights on at sunset
  trigger:
    platform: sun
    event: sunset
    offset: -00:45:00
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.laurensiphone
        state: home
      - condition: state
        entity_id: device_tracker.codysiphone
        state: home
  action:
    - service: light.turn_on
      entity_id: switch.extension_cord

- id: turn_lights_off_at_night
  alias: Turn lights off at night
  trigger:
    platform: time
    after: 22:29:59
  action:
    service: light.turn_off
    entity_id: switch.extension_cord

Thank you so much!

For the conditions that you mentioned. Would it be something like this for all three automations:

- id: turn_lights_off_at_night
  alias: Turn lights off at night
  trigger:
    platform: time
    after: 22:29:59
condition:
     - condition: state
        entity_id: switch.extension_cord
        state: 'off'
  action:
    service: light.turn_off
    entity_id: switch.extension_cord

Very close. You’ll want the condition to check that the switch is on. Also, make sure the condition line is the same indent level as trigger and action. Nicely done!

- id: turn_lights_off_at_night
  alias: Turn lights off at night
  trigger:
    platform: time
    after: 22:29:59
  condition:
    condition: state
    entity_id: switch.extension_cord
    state: 'on'
  action:
    service: light.turn_off
    entity_id: switch.extension_cord

Thank you again for looking at this. I think this should be correct now.

I am still having issues and I am not sure what is causing it. This is the error code that I am receiving. I sarched the forums but everything I tried failed. This is the error.

2017-05-24 22:25:05 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Invalid time specified: 80999 for dictionary value @ data['trigger'][0]['after']. Got None. (See /home/pi/.homeassistant/configuration.yaml, line 108). Please check the docs at https://home-assistant.io/components/automation/

This is my configuration:

- id: no_one_home
  action:
    - entity_id: switch.extension_cord
      service: light.turn_off
  alias: "No one home"
  trigger:
    - entity_id: device_tracker.siphone1
      from: home
      platform: state
      to: not_home
    - entity_id: device_tracker.iphone2
      from: home
      platform: state
      to: not_home

- id: lights_on_at_sunset
  action:
    - entity_id: switch.extension_cord
      service: light.turn_on
  alias: "Lights on at sunset"
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.iphone2
        state: home
      - condition: state
        entity_id: device_tracker.iphone1
        state: home
  trigger:
    event: sunset
    offset: -00:45:00
    platform: sun

- id: turn_lights_off_at_night
  action:
    - entity_id: switch.extension_cord
      service: light.turn_off
  alias: "Turn lights off at night"
  trigger:
    after: 22:29:59
    platform: time

This is line 108 from configuration.yaml as the error says.

#Automations
automation: !include automations.yaml
config:

Strangely the No one home automation seems to be valid though I have not been able to test that it works successfully yet.

You have everything backwards. It should go:

triggers:
conditions:
actions: