Temperature condition motion sensor does not work

I would like to turn on a smart plug (connected to a heater) in a room based on when motion is detect and the temperature is below a certain threshold. I’ve created an automation that when motion is detected, under the condition that the temperature is less then 18 degrees celsius, the smart plug should be turned on. But this does not work. Every time motion is detected, the smart plug is turned on, regardless of the temperature.
How can I fix this?