I have built a water flow monitor hooked up to a rPi which sends flow rate information to Home Assistant using MQTT, and where an MQTT sensor picks it up. This all works well.
Actual flows are intermittent, but the watch dog on the rPi sends periodic MQTT status keepalives where flow rate is often zero. This means that flow rate values are regularly overwritten, and most of the time the mqtt sensor state value is zero.
Unless there’s a better way, I want to build an automation which triggers when the mqtt flow sensor is non zero, and where the action is to copy the state value from the mqtt sensor to a template sensor, such that the template sensor indicates the last non zero flow rate. (Deviation from a baseline helps me identify leaks.)
Building the trigger is easy enough, but how do I create the action to copy the mqtt sensor state value to the template sensor state in the automation?