Doorbell at front and back of house only works when the basement lights are on, controlled by a light switch at the top of the stairs.
In the attached photo the power goes directly from the panel to the light fixture via an old sheathed cable. The doorbell transformer is wired to the light fixture. From that light fixture, power also continues via a newer white wire (exits on the right, partially obscured) to another light fixture, and also via an older green wire (on the left) which must be the switch leg.
The doorbell transformer has two black wires.
The top black transformer wire goes to the red cap on the left. Inside that cap, it's connected to:
black from the light fixture;
black from the green switch leg cable; and
black from the white outgoing cable for the 2nd light fixture.
The bottom black transformer wire goes to the black cap. Inside that cap, it's connected to:
black from the power; and
white from the green switch leg cable
The other red cap (on the right) connects:
white from the light fixture;
white from the white wire going to the next light fixture; and
white from the original power source.
Based on that, how do I wire this to stay on regardless of whether or not the lights are on?