As Mikefila says, you can use the Get history node.
This node can be a little tricky to set up and to process the return (usually an array) so I have put an example flow together that may help you. If you pass an identical startDate and endDate as the boundary time period, the Get History node should return an array of just one item with the state value as it was at that exact timestamp.
The following flow will allow you to set the timestamp in the inject node (this must be ISO format) and it will read both the history and the current state value, and do the calculation for you.
Note that Home Assistant stores history for a default 10 days only, so if you try to read earlier than this the result will be ‘undefined’ as there is no history to return.
[{"id":"17a1219784662b39","type":"api-get-history","z":"776c027950fc8c3f","name":"Read history","server":"","version":1,"startDate":"","endDate":"","entityId":"","entityIdType":"equals","useRelativeTime":false,"relativeTime":"","flatten":true,"outputType":"array","outputLocationType":"msg","outputLocation":"payload","x":570,"y":6260,"wires":[["a8a6ad3739951f80"]]},{"id":"11b6d6430440b56f","type":"inject","z":"776c027950fc8c3f","name":"Set datetime","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"(\t $time:= \"2024-02-10T18:00\";\t {\"startDate\": $time,\t \"endDate\": $time }\t)","payloadType":"jsonata","x":190,"y":6260,"wires":[["0ae6472768e514d8"]]},{"id":"8214b83dbbb1ca36","type":"debug","z":"776c027950fc8c3f","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":6260,"wires":[]},{"id":"0ae6472768e514d8","type":"api-current-state","z":"776c027950fc8c3f","name":"Get current state","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.help_ri_grid_energy_export","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"payload ~> |$|{\"entityId\": $entity().entity_id}|","valueType":"jsonata"},{"property":"state","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":370,"y":6260,"wires":[["17a1219784662b39"]]},{"id":"a8a6ad3739951f80","type":"change","z":"776c027950fc8c3f","name":"Calculate difference","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round(state - $number(payload[0].state),3)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":6260,"wires":[["8214b83dbbb1ca36"]]}]
The flow has been scrubbed to remove the HA server, so you will need to edit the node configuration to put this back again, and of course set you own sensor ID.
I have made no allowance for time zone differences, and HA will store history using UTC, so you may have to experiment a little with the timestamp to get this right.
Yes, you can read the current state from the Global context homeassistant variable, but I have included both a current state node and a get history node together here. The timestamp is set in the inject node (you can therefore set this from a variable if you like). The entity id is set in the current state node, then captured and passed to the get history node (so you only have to set it in one place). The calculation is done in a change node using JSONata.
I hope this helps!