Assuming the correct state topic is mqtt/out
and published messages always contain either CMD=ON
or CMD=OFF
then this should be all that’s needed.
mqtt:
binary_sensor:
- name: PIR Test
state_topic: "mqtt/out"
value_template: "{{ 'ON' if 'CMD=ON' in value else 'OFF' }}"