Storing state in custom code


I’ve been trying to store state in custom code ( that can be run via a scheduled job ), but so far failed. Use-case is, for example, checing the change in state-of-charge.

I tried a global variable -

import requests

log = logging.getLogger(__name__)
count = 1

def test():
    global count

    bot_sendtext("Hello World! "+str(count))

    count += 1

    return {"msg": "Hello world!"}

but I guess the python instance is created each time the scheduled take is run.

Any thoughts ?

I found I could use the python pickle package to save and restore state.

Any better ideas ?

Hi Peter

I think your solution using pickle is very elegant.
I don’t currently have a better alternative.

Best regards