# Write event to persistence switch

**URL:** <https://discourse.nodered.org/t/write-event-to-persistence-switch/35990>\
**Category:** General\
**Created:** [16 November 2020 08:52 UTC](https://discourse.nodered.org/t/write-event-to-persistence-switch/35990 "2020-11-16T08:52:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chura](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chura/32/32051_2.png) [@Chura](https://discourse.nodered.org/u/Chura)\
**Post date:** [16 November 2020 08:52 UTC](https://discourse.nodered.org/t/write-event-to-persistence-switch/35990/1 "2020-11-16T08:52:26Z")

</div>

Hi,

On my flow I want to check if a switch in my home is on.  
The switch send event ON or OFF once its triggered.

How should I do that ? write that even to variable and check the variable ? will this variable reset on each deployment ?

What i'm trying to do is check if lights needed with sun elevation, if dark enough, check if lights already on manually by wall switch, if not, turn them on.  
So I need to be able to determine if lights are on already, I can't check them becuase they report on MQTT once and do not keep state.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [16 November 2020 08:59 UTC](https://discourse.nodered.org/t/write-event-to-persistence-switch/35990/2 "2020-11-16T08:59:21Z")

</div>

You could definitely store it in a context variable:

> **[Working with context : Node-RED](https://nodered.org/docs/user-guide/context)**

  
If you want the variable to be persisted across restarts of nodered you will need to add file system based context storage which is also described in the link above further down.

Johannes

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 January 2021 08:59 UTC](https://discourse.nodered.org/t/write-event-to-persistence-switch/35990/3 "2021-01-15T08:59:25Z")

</div>

Closed on 15 January 2021 08:59 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
