Brightness based on motion and time of the night

I would like to add to my automation brightness and timing

  • if is between 20 and 22 full brightness; betweeen 22 and 23 50% brightness, between 23 and sunset 30% brightness

how to add?

Thanks.
Corridor is long so I have 2 sensors

# Turns on lights at sunset for stairways
  - alias: 'Motion hallway upstairs right'
    initial_state: 'on'
    trigger:
      platform: state
      #motion sensor right
      entity_id: binary_sensor.motion_sensor_158d000112e1de
      from: 'off'
      to: 'on'
    condition:
      - condition: sun
        after: sunset
    action:
      - service: light.turn_on
        entity_id: light.hallway_right
      - service: mqtt.publish
        data:
          topic: sensor/hallway
          payload: "on"
          retain: "true"
      - delay: '00:01:00'
      - service: light.turn_off
        entity_id: light.hallway_right
      - service: mqtt.publish
        data:
          topic: sensor/hallway
          payload: "off"
          retain: "true"
  - alias: 'Motion hallway upstairs left'
    initial_state: 'on'
    trigger:
      platform: state
      #motion sensor stairs
      entity_id: binary_sensor.motion_sensor_158d000129a3c4
      from: 'off'
      to: 'on'
    condition:
      - condition: sun
        after: sunset
    action:
      - service: light.turn_on
        entity_id: light.hallway_right
      - service: mqtt.publish
        data:
          topic: sensor/hallway
          payload: "on"
          retain: "true"
      - delay: '00:01:00'
      - service: light.turn_off
        entity_id: light.hallway_right
      - service: mqtt.publish
        data:
          topic: sensor/hallway
          payload: "off"
          retain: "true"
#