Automation Change device to switch based on time

Hi,

I’m using a yeelight ceiling light with es-home firmware. So I have two device entities for normal light and night mode.
I also have a wall switch with a sensor. At the moment each time the wall switch is changed the ceiling light toggles the state.
I now want to specify that when it is after 23:00 an before sunrise or 6:00 the wall switch should toggle the night mode and between sunrise or 6:00 an 23:00 it should toggle the normal light.
I think this should work with a template but I have no clue how to set up this automation with a template.

can someone here help me set this up?

cheers and thanks for your possible help

for now I have this code snippet but it does not work …

- id: '1664105673904'
  alias: Bad Decke
  description: ''
  trigger:
  - type: powered
    platform: device
    device_id: 385e97658204df06034ed9db90597d58
    entity_id: binary_sensor.badezimmer_channel_2_input
    domain: binary_sensor
  - type: not_powered
    platform: device
    device_id: 385e97658204df06034ed9db90597d58
    entity_id: binary_sensor.badezimmer_channel_2_input
    domain: binary_sensor
  condition: []
  action:
  - type: toggle
    data_template:
        entity_id: >
            {%if (now().time().strftime("%H")| int > 6 ) and(now().time().strftime("%H")| int < 19 )%} 
            light.yeelight_bad_ceiling_light
            {% else %}
            light.yeelight_bad_night_light
            {% endif %}
    domain: light
  mode: single