# Check actual state

**URL:** <https://discourse.nodered.org/t/check-actual-state/25718>\
**Category:** General\
**Created:** [29 April 2020 06:33 UTC](https://discourse.nodered.org/t/check-actual-state/25718 "2020-04-29T06:33:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [29 April 2020 06:33 UTC](https://discourse.nodered.org/t/check-actual-state/25718/1 "2020-04-29T06:33:04Z")

</div>

Hi all!

Im working in my home lights project and i want to achive the following.

Im using sonoff with mqtt and homeassitant. All works fine!.  
With node-red im checking the actual state of my sonoff if it is ON or OFF. All works fine.

The thing is i want to get the value or string of the ON state and how much is it ON. For example, the light is ON for about 1 hour. Then make something with that.

Im using the state node of home assistant and the information describes this.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f93d010b30c6dc4d4cfc31d81b338c79d5a0ac2.png)

maybe i can use last\_change or so but how can i get the data property?  
If i put a debug the payload returns ON or OFF.

Thanks a lot in advance.

Regards!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 April 2020 07:06 UTC](https://discourse.nodered.org/t/check-actual-state/25718/2 "2020-04-29T07:06:30Z")

</div>

Did you set the debug node to output the `complete msg object` ?

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [29 April 2020 07:22 UTC](https://discourse.nodered.org/t/check-actual-state/25718/3 "2020-04-29T07:22:53Z")

</div>

yes it is like this.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c1322ede031895a84855eea26903e644ac03930.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 April 2020 07:30 UTC](https://discourse.nodered.org/t/check-actual-state/25718/4 "2020-04-29T07:30:03Z")

</div>

Read up on "[working with messages](https://nodered.org/docs/user-guide/messages)"

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 April 2020 09:21 UTC](https://discourse.nodered.org/t/check-actual-state/25718/5 "2020-04-29T09:21:30Z")

</div>

check out this thread, it may give you some ideas [Dashboard pie chart to show Raspberry pi GPIO history](https://discourse.nodered.org/t/dashboard-pie-chart-to-show-raspberry-pi-gpio-history/25666)

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [29 April 2020 13:15 UTC](https://discourse.nodered.org/t/check-actual-state/25718/6 "2020-04-29T13:15:06Z")

</div>

Thanks a lot folks!!

I will give it a read.

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [2 May 2020 21:48 UTC](https://discourse.nodered.org/t/check-actual-state/25718/7 "2020-05-02T21:48:51Z")

</div>

Thanks a lot to all who answered.

I'm working on this feature and i find it a little bit complicated, maybe i'm complicating it too.

The thing is that i want to get the last time that the state was changed to ON. When that happens i have to compare that time and date with the actual time and date so i can get how many hours the light is ON because i could forget to turn it off o anything...

So, the debug tells me this.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/857db2160f14f86181ad351f2dff63025c222392.png)

How can i transform that to normal time and date?. I've read about the Change Node but i don't know.

Any ideas?

Thanks!

---

<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:** [2 May 2020 21:53 UTC](https://discourse.nodered.org/t/check-actual-state/25718/8 "2020-05-02T21:53:36Z")

</div>

if this is what it says, the time since the last change in milliseconds:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd6ad2a7a373217202edf4c2d65688fb4236f98b.jpeg)  
wouldn’t it be easier to convert this to something like minutes than to go down the way of date conversions?

Johannes

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [2 May 2020 22:20 UTC](https://discourse.nodered.org/t/check-actual-state/25718/9 "2020-05-02T22:20:15Z")

</div>

Ok, how can i access to that element? Maybe with a Change node?

---

<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:** [3 May 2020 08:15 UTC](https://discourse.nodered.org/t/check-actual-state/25718/10 "2020-05-03T08:15:46Z")

</div>

well you can click this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/6983d2785031ddcf339a3521e756698c728627f5.jpeg)  
next to the value to copy the path to this key of your msg object.  
You could than use a change node like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c9e7d72f6480cfac70bc7951250ae877a781c72.jpeg)  
where you paste your copied path in the first field of the move rule and use a [jsonata](http://docs.jsonata.org/overview) expression to convert to minutes and round the result.  
You would than have with one change node a nice msg.payload with the minutes since the last change.

Johannes

---

<div class="post-metadata">

**Author:** ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)\
**Post date:** [3 May 2020 19:58 UTC](https://discourse.nodered.org/t/check-actual-state/25718/11 "2020-05-03T19:58:57Z")

</div>

Thanks a lot! That worked perfectly.

Regards!

---

<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:** [2 July 2020 20:02 UTC](https://discourse.nodered.org/t/check-actual-state/25718/12 "2020-07-02T20:02:37Z")

</div>

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