Automation with a time trigger based on another entity

How can I make an automation with a time trigger based on the state of another entity.

Unfortunately, it doesn’t work this way, whether the time is in quotes or not.

alias: Switch on
description: ""
trigger:
  - platform: template
    value_template: |-
      {% if state_attr('input_boolean.is_specific_time', 'on') %}
        16:00:00
      {% else %}
        18:00:00
      {% endif %}
condition:
  - condition: state
    entity_id: input_boolean.is_time
    state: "on"
action:
  - type: turn_on
    device_id: 9060d45c25d64a300c351549a3887ac7
    entity_id: switch.tuya_power_strip_switch4
    domain: switch
mode: single

There are a few issues…

Time triggers do not accept templates, but you aren’t using one anyway…

A Template trigger only fires when the value it returns changes from “false” to “true”. Assuming you fixed the if statement, the template you have used will still never return “true”… only “16:00:00” or “18:00:00”, both of which count as false.

Here’s one way to make it work:

alias: Switch on
description: ""
trigger:
  - platform: time
    at:
      - "16:00:00"
      - "18:00:00"
condition:
  - condition: template
    value_template: |
      {% if is_state('input_boolean.is_specific_time', 'on') %}
        {{ trigger.now.hour == 16 }}
      {% else %}
        {{ trigger.now.hour == 18 }}
      {% endif %}
  - condition: state
    entity_id: input_boolean.is_time
    state: "on"
action:
  - type: turn_on
    device_id: 9060d45c25d64a300c351549a3887ac7
    entity_id: switch.tuya_power_strip_switch4
    domain: switch
mode: single

It looks great, I will test it.
Thank you:)