Saving a number or string state

i would like to have a state that i can set and read - it should not be in the UI. the purpose is to test its last value and based on that - perform another operation. i thought about using MQTT with “retained” and save it in the broker but it would be better to keep it in HASS.

what is the best method to use such state parameter?

I use MQTT. There are also a couple of ‘variables’ custom integrations:


Thanks - exactly what i was looking for