# Saving a single value to context

**URL:** <https://discourse.nodered.org/t/saving-a-single-value-to-context/46670>\
**Category:** General\
**Created:** [3 June 2021 20:59 UTC](https://discourse.nodered.org/t/saving-a-single-value-to-context/46670 "2021-06-03T20:59:17Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [3 June 2021 22:47 UTC](https://discourse.nodered.org/t/saving-a-single-value-to-context/46670/10 "2021-06-03T22:47:32Z")

</div>

I blame Julian (@TotallyInformation ) it's all his fault 😉😉😉

> [@Calculate the time of operation between ON and OFF given Boolean](https://discourse.nodered.org/t/calculate-the-time-of-operation-between-on-and-off-given-boolean/46494/4):
>
> Bit late to the conversation but I store last\_on and last\_off as part of any IoT switch, this is also sent to MQTT. When the state changes, I record the on\_duration and off\_duration: The calculations are done by a single function node that enriches the known\_devices data both in the global variable and MQTT. The updated and updated\_by properties are ones that I now use as standard all over the place since my flows have got a bit complex. grinning It means that it is much quicker t…

---

_[View the full topic](https://discourse.nodered.org/t/saving-a-single-value-to-context/46670)._
