Create sensor ( Binary or otherwise ) based on multiple time ranges

New to homeassistant so pardon my ignorance.

I am trying to create a single binary sensor that will be ‘ON’ IFF

  • if is between 4:00 and 9:00 OR
  • if it is between 15:00 and 20:100:

From some basic searching it seemed like the recommendation was to have multiple binary sensors ( one for each time range ) and then have another that is determined by the state of the individuals.

I have already created the two time based binary sensors

- platform: tod
  name: 'plant_fan_4am_to_9am'
  after: '4:00'
  before: '9:00'

but when I try to create the combined binary sensor it gets stuck at the first value.

- platform: template
  sensors:
    plant_fan_expected_state:
      friendly_name: "Plant Fan Expected State"
      value_template: >-
        {% if is_state( 'binary_sensor.plant_fan_4am_to_9am', 'on' ) %}
          on
        {% elif is_state( 'binary_sensor.plant_fan_3pm_to_8pm', 'on' ) %}
          on
        {% else %}
          off
        {% endif %}

Any thoughts on how I get the combined binary sensor to update when the individual sensors update?

My long term goal is to feed the combined binary sensor into an automation that controls a plant fant that triggers when its state changes.

I like this format to allow me to change the state of the plant fan manually then I can manually trigger the automation and it will resume the “expected” state.

My only other thought ( might be easier ) is to keep the individual binary sensors.
but have the automation trigger off of any state change of any of them, and then set the plant fan based on if any of the binary sensors are ‘ON’

The part that confuses me here though is detecting what state I need to change to.

For the sake of completeness.
I later found this https://www.home-assistant.io/integrations/binary_sensor.template/#combining-multiple-sensors
and gave it a try to combine the binary sensors using or instead of and, however it seemed like the sensors did not update after the first state change.

Eventually I migrated over to node-red instead and had the automation working within a few minutes.