Obtain retained MQTT message
Once a message has passed through an MQTT broker there is not a way to retrieve it from the broker.

Consider instead deciding upon the action at the time the message is received by the subscriber.  If this decision needs to be made at a later time consider storing the state in the of the payload of the message on the subscriber.

Also consider running Node-RED.  If the platform running the MQTT broker can support Node-RED (such as a Raspberry Pi), it turns out to be convenient to run both on the same computer.  Node-RED contains nodes (graphical programming blocks) which can subscribe to and publish to MQTT topics.  By connecting other nodes to these, the topic and payload can be manipulated.  Of interest is an option within the Output MQTT node.  Here you can select Retain True.  This page explains how this option works:


  Once you have sent a retained message to a topic, all subscribers will
  receive that message when they subscribe.
  
  To clear a previously retained topic from the broker, send a blank
  message to that topic with the retain flag set.