Mixing is_state and time in a value_template condition

I want to exchange the last is_state (in between the pairs of “**”) to a condition:time before: 05:10, how would that like like?

  data_template:
    value: >-
      {% if is_state('timer.upper_hall_way_3_min', 'idle') and **is_state('input_boolean.away_mode', 'on'**`)%}`

The following means (time < 05:10) AND (away_mode == on)

  condition:
    - condition: time
      before: '05:10'
    - condition: state
      entity_id: 'input_boolean.away_mode'
      state: 'on'

If you prefer to explicitly indicate it is an AND operation, you can write it like this:

condition:
  condition: and
  conditions:
    - condition: time
      before: '05:10'
    - condition: state
      entity_id: 'input_boolean.away_mode'
      state: 'on'

Thanks for replying, but I think that will not help me, since it is part of a big if-statement:

  data_template:
    value: >-
      {% if is_state('timer.upper_hall_way_3_min', 'idle') and is_state('input_boolean.away_mode', 'on')%}
        scene.huset_natter_away
      {% elif is_state('timer.upper_hall_way_3_min', 'active') and is_state('input_boolean.away_mode', 'on')%}
        scene.sensor_upper_hall_way_nights_on_away
      {% elif is_state('timer.upper_hall_way_3_min', 'active') and is_state('input_boolean.away_mode', 'off')%}
        scene.sensor_upper_hall_way_nights_on
      {% elif is_state('timer.upper_hall_way_3_min', 'active') and **is_state('input_boolean.away_mode', 'off'**)%}
        scene.house_nights         
	  {% else %}
        scene.house_no_change
      {% endif %}

Without seeing the entire automation, or knowing what is your ultimate goal, it’s difficult to provide you with additional assistance.

Good luck adding a time constraint to the automation.

You need to convert the current time and the value to check against into a common number. Doesn’t matter what, hours, minutes, or seconds.

Time conversions

hours = hours + minutes / 60 + seconds / 3600
minutes = hours * 60 + minutes + seconds / 60
seconds = hours / 3600 + minutes / 60 + seconds

Here is the comparison using hours as the common time units:

   {% set current_time = now().hour + now().minute / 60 + now().second / 3600 %}
   {% set t510 = 5 + 10 / 60 %}
   {% if is_state('timer.upper_hall_way_3_min', 'idle') and current_time < t510 %}

Inside your yaml:

  data_template:
    value: >-
      {% set current_time = now().hour + now().minute / 60 + now().second / 3600 %}
      {% set t510 = 5 + 10 / 60 %}
      {% if is_state('timer.upper_hall_way_3_min', 'idle') and is_state('input_boolean.away_mode', 'on')%}
        scene.huset_natter_away
      {% elif is_state('timer.upper_hall_way_3_min', 'active') and is_state('input_boolean.away_mode', 'on')%}
        scene.sensor_upper_hall_way_nights_on_away
      {% elif is_state('timer.upper_hall_way_3_min', 'active') and is_state('input_boolean.away_mode', 'off')%}
        scene.sensor_upper_hall_way_nights_on
      {% elif is_state('timer.upper_hall_way_3_min', 'active') and current_time < t510 %}
        scene.house_nights         
	  {% else %}
        scene.house_no_change
      {% endif %}

ahh, that I would not have figured out myself, thanks a lot!

/Martin