Set object rotation relative to other object

In this image you can see the overall setup. There is master object with the following axis layout and a child object with very similar axis layout. Child object is rotating around it’s Y axis. This makes it’s X and Z axis face different directions every frames. And this makes it problematic to do what I need.

Here you can see, how would it looks like when the child object has not yet rotated around y axis(and thus it’s Z axis faces more or less upwards). There is a value y which determines how much the child object is rotated around the X axis. This y value can change every frame. However, it must set the child’s rotation, not increase/decrease making it even more complex. How do I set the child object’s rotation based on y number correctly to yet allow it rotate freely around it’s Y axis?