Anamico / node-red-contrib-alarm

Nodes to build your own home alarm system. Designed to work easily with (but does not require) homekit.
MIT License
24 stars 8 forks source link

add contextStore option to make the storage for global states selectable #23

Closed cupracer closed 1 year ago

cupracer commented 3 years ago

The alarm panel defaults to a hard-coded 0 state ("Home" mode), which immediately would result in an alarm after restarting Node-RED in case a "Home"-sensor triggers at this time.

A workaround for this is documented in https://github.com/Anamico/node-red-contrib-alarm/issues/19#issuecomment-774623392 which consists of defaulting to file-based context storage in the whole Node-RED environment.

I would like to avoid enabling the default use of persistent storage for global context variables just because a single node depends on it, so I extended the alarm panel node. With this adjustment the storage to use becomes selectable.

The new menu item uses the default Node-RED storage , but could be extended by using multiple context stores as documented here: https://nodered.org/docs/user-guide/context#using-multiple-context-stores

Demo:

settings.js

contextStorage: {
    default: {
        module:"memory"
    },
    memory: { module: 'memory' },
    file: { module: 'localfilesystem' }
},

Admin GUI AnamicoAlarmPanel:

image