Thanks very much! I've had a go at implementing your solution but I think I've misunderstood. Do I need to change the global variables to Json?
Here's the flow:
[{"id":"c6eea34d387d13e4","type":"tab","label":"Vacuum","disabled":false,"info":"","env":[]},{"id":"59f9f0610947de5d","type":"server-state-changed","z":"c6eea34d387d13e4","name":"","server":"8a644e13.f9644","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"vacuum.roborock_s6_maxv","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"cleaning","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":220,"wires":[["f12cdf4c3c57a4c8"],[]]},{"id":"f12cdf4c3c57a4c8","type":"api-current-state","z":"c6eea34d387d13e4","name":"Total cleaned area","server":"8a644e13.f9644","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.roborock_s6_maxv_total_clean_area","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":530,"y":160,"wires":[["73e371be0976c0c5","9a22bdeb6618f0f3"]]},{"id":"73e371be0976c0c5","type":"ha-wait-until","z":"c6eea34d387d13e4","name":"Wait until returning to docl","server":"8a644e13.f9644","version":2,"outputs":1,"entityId":"vacuum.roborock_s6_maxv","entityIdFilterType":"exact","property":"state","comparator":"is","value":"Returning to dock","valueType":"str","timeout":"0","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":940,"y":180,"wires":[["bffbc608a513909c"]]},{"id":"bffbc608a513909c","type":"api-current-state","z":"c6eea34d387d13e4","name":"Total cleaned area","server":"8a644e13.f9644","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.roborock_s6_maxv_total_clean_area","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1370,"y":180,"wires":[["5c43ee8169094f0b"]]},{"id":"92607ca65b38ebbd","type":"inject","z":"c6eea34d387d13e4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":120,"wires":[["f12cdf4c3c57a4c8"]]},{"id":"f4803adf40a1cfd3","type":"inject","z":"c6eea34d387d13e4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1080,"y":100,"wires":[["bffbc608a513909c"]]},{"id":"9a22bdeb6618f0f3","type":"change","z":"c6eea34d387d13e4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Area_Before_Clean","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":260,"wires":[["14012b24ac7d9bbc"]]},{"id":"5c43ee8169094f0b","type":"change","z":"c6eea34d387d13e4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Area_After_Clean","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1580,"y":240,"wires":[["14012b24ac7d9bbc"]]},{"id":"14012b24ac7d9bbc","type":"switch","z":"c6eea34d387d13e4","name":"","property":"Area_After_Clean - Area_Before_Clean","propertyType":"jsonata","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1310,"y":400,"wires":[["30a355bcf03586cd"]]},{"id":"30a355bcf03586cd","type":"debug","z":"c6eea34d387d13e4","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1560,"y":660,"wires":[]},{"id":"8a644e13.f9644","type":"server","name":"Home Assistant","addon":true}] ```