How to update raster pixel values based on another raster with conditions in QGIS?

The QGIS raster calculator seems limited, but you can achieve a lot once you know a couple of tricks

These hold true for both SAGA and QGIS raster calculators

true = 1
false = 0

You can use addition to simulate boolean logic

X or Y : x+y > 0
X and y : x+y = 2

I've modified Joseph's answer to use these, and get around the lack of boolean logic in SAGA's grid calculator

ifelse(gt(eq(g1,30)+eq(g1,34),0),ifelse(eq(g2,0/0),g1,g2),g1)

This i've tested, the example below shows my two images. The first is a land cover classification, the second is a gradient based on latitude (generated in saga using ypos()). The final image, I've taken two of the classified values and replaced them with the gradient value.

enter image description here

Be careful doing this in SAGA itself, it's all to easy to overwrite your original raster. Probably safer to call from Processing, as Joseph suggested.

In QGIS the same would be as follows. I've assumed your rasters are a (first) and b (second), and you're only using band1 (@1)

"a@1" + ((((("a@1"=30)+("a@1"=34) >=1) + ("b@1">0)) =2) *("b@1"-"a@1"))

EDIT

Just realised I'm copying over all data pixels from the second image, including zeros. This slightly more complex expression should do the job...

ifelse(gt(eq(g1,30)+eq(g1,34),0),ifelse(eq(g2,0/0),a,ifelse(eq(g2,0),g1,g2)),g1)

I don't think the QGIS Raster Calculator supports conditional statements but the SAGA Raster Calculator does support the ifelse() statement which you can access from the Processing Toolbox.

I don't have an example raster to test but you could try something like the following formula which aims to follow your logic:

ifelse(eq(a,30 AND 34),ifelse(eq(b,!=0),a,b),a)

where:

a = first raster
b = second raster

Disclaimer: I rarely worked with rasters so this is more of a guess than anything else.