Automation Sun Offset Error

I am trying to add an offset to a existing automation. The YAML code is correct, but I get a notification in HA “invalid config”.

Here is the code:

  trigger:
    platform: state
    entity_id:  device_tracker.android
    from: 'not_home'
    to: 'home'
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
    offset: "-00:45:00"
  action:
  - service: switch.turn_on
    entity_id:
      - switch.honeywell_unknown_type_4952_id_3036_switch
      - switch.0220036060019472dce9
      - switch.0220036060019472da94

Thank you for any suggestions.

You can’t have an offset in a state condition, that doesn’t make any sense.
The offset is used in combination with a condition from the sun platform not from the state platform.

Do you want the condition to be from 45 minutes before sunset until sunrise?
If so then use this:

condition:
  condition: or 
  conditions:
    - condition: sun
      after: sunset
      after_offset: "-00:45:00"
    - condition: sun
      before: sunrise

Here it is explained in detail

Thank you so much! I was just reading the same page you supplied before your post.

I confused Condition with Trigger:

https://www.home-assistant.io/cookbook/automation_sun/

Thank you again for your help!

If it works now, please mark the topic as solve, this way other people may benefit from this in the future.

I also added an additional trigger to eliminate a second automation that was identical except for the entity_id.

  trigger:
    - platform: state
      entity_id:  device_tracker.android
      from: 'not_home'
      to: 'home'
    - platform: state
      entity_id:  device_tracker.android_2
      from: 'not_home'
      to: 'home'     
  condition:
    condition: or 
    conditions:
      - condition: sun
        after: sunset
        after_offset: "-00:45:00"
      - condition: sun
        before: sunrise
  action:
  - service: switch.turn_on
    entity_id:
      - switch.honeywell_unknown_type_4952_id_3036_switch
      - switch.0220036060019472dce9
      - switch.0220036060019472da94

The new automation editor added code that is not explained in the conditions.

before: sunrise
before_offset: '01:00:00'
condition: sun

Before there was just offset. Does the before change the meaning to before the event or does this mean the same and '01:00:00 means an hour after sunrise or does the before change the meaning?

I want 1 hour before sunrise? Do I continue to use the -1?

What do you mean it is not explained in the conditions? It’s right there in the first example of the sun condition part of the condition docs. There’s also a chart explaining the offsets there.

To get 1 hour before sunrise you need this:

before: sunrise
before_offset: '-01:00:00'
condition: sun

In the link for conditions:

https://www.home-assistant.io/docs/scripts/conditions/#sunsetsunrise-condition

Thanks for clearing it up.
All the examples in the chart are for + values. I always have a hard time seeing before a time as a minus. (Two negatives (before & minus) , gives me a positive). As long as I know how it is suppose to work, I can work with it.

I agree it is a bit confusing until you get a grasp for it.