After: ?variable? (yaml)

there is way to use a variable after " after: ?
My variable is “vtramonto”


  - condition: time
    before: '06:00:00'
    after: vtramonto   <----**** how is the correct syntax??? ***
mode: single
  vtramonto: >-

Hi and welcome to the forum.

Please have a read of point 11 here, then edit your post to correctly format your configuration examples.

You can only use input_datetime helpers in that position.

This example is from the Time condition documents:

  condition: time
  after: input_datetime.house_silent_hours_start
  before: input_datetime.house_silent_hours_end
1 Like

Thanks Tom.
I tried with this code but it does not work (I need ‘tramonto_cest’):

    has_time: true
    has_date: false
    initial: '{{(as_timestamp(state_attr("sun.sun","next_setting"))|timestamp_local)}}'
    has_time: true
    has_date: false
    initial: '21:50'

In event editor the string

{{ states("input_datetime.tramonto_cest") }}

returns “unkwnows”.

and the string

{{ states("input_datetime.tramonto_cest2") }}

returns 21:50:00

The first input_datetime doesn’t work because you used a template for initial but if you check the documentation for the initial option you will see it doesn’t support templates.

The second input_datetime works because you used a time string for initial which is the only thing it supports.

You’re making an erroneous assumption that every option supports a template. Only some options support templates and the documentation usually tells you which ones do.

1 Like

Ok Tars, many thanks.
Sorry, I am newbie…

Workaround for what exactly? If you mean for the Time Condition then consider using a Template Condition. Let me know if you need help composing the template.

1 Like

I need to turn light (after open door) if time is between sunset and sunrise.

    platform: sun
    after: sunset
    before: sunrise

The problem is that “sunset” and “sunrise” are UTC time, not CEST time.
So I found the way to convert them in CEST, using


but it not works with input_datetime.

So I need to use CEST sunrise and sunset in my condition.
See rows code with “???”

Many Thanks

alias: mc_Ingresso (2)
description: turn on only after sunset and before sunrise
  - platform: state
    entity_id: binary_sensor.sonoff_a480011888
    from: 'off'
    to: 'on'
    for: '00:00:00'
  - condition: time
    before: ??? sunrise-time-cest (not utc)
    after: ??? sunset-time-cest (not utc)
  - service: switch.turn_on
      entity_id: switch.sonoff_1000ca80a3
mode: single

They are displayed in UTC but converted to local time when used by sun.sun to determine when sunrise and sunset occur in your location. It uses the timezone you set in Configuration > General to determine your local time.

are you sure? My location is correct (Italy, CEST) but the value sun.sun are Utc!
(the sunset of today is 20.23)
Many thanks for your help !!!
PS: I will try with sunset & sunrise value.


Me too and my timezone is in North America. Both Sun Trigger and Sun Condition work correctly for my location.

1 Like