Page 1 of 1

Devel : Is there a way to save data using javascript API?

Posted: 10 Nov 2016 00:30
by Nander2
Hi everyone.

I wonder if there is a way to save data of a module and load it back at module startup.

I'm thinking about automatic leanring module (ex : the module change one of it parameters (ex: a table of integer [4,5,..]) save it and load it back when the z-way server start the module.). a sort of non volatile memory in short.

I think this could be done using the module Id to create a file and save data to it, but i wonder if there is a smarter way to do it (using the Z-way API for exemple). If this options should be use I also wonder where is the perfect location to save this file?

if somebody can answer any of this questions to give me a hint...

thanks

Re: Devel : Is there a way to save data using javascript API

Posted: 10 Nov 2016 04:02
by gsaw
Yes, you can. Look at other modules. For logging for example.

Re: Devel : Is there a way to save data using javascript API

Posted: 10 Nov 2016 20:53
by Nander2
Ok thank.

I looked at DeviceHistory.
To save an object and load it i have to call :

Code: Select all

// to save object :
saveObject("history", self.history);
// to load object :
this.history = loadObject('history') || [];
Great!

Re: Devel : Is there a way to save data using javascript API

Posted: 14 Nov 2016 12:22
by Nander2
Hi everybody.

I'm working on an presence auto learning modules. it will permits to anticipate your presence to launch heating for exemple.

So for now i'm able to create and save presence data when the module is running. I tried to uninstall the module and install it back but the saved object is reload from the last install. So how to remove the saved object when the module is uninstalled (removed from active modules)?

Thanks.

Re: Devel : Is there a way to save data using javascript API

Posted: 14 Nov 2016 13:03
by pz1
I have done that in the past as follows:
- stop Zway
- open /opt/z-way-server/automation/storage/configjson-xxxxxxxx.json
- delete the offending virtualDevice(s)

I do use Notepad++ with the JSTool plugin. A bit clumsy, but afaik the only possibility at the moment