Check actual state

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.

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!

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

yes it is like this.
image

Read up on "working with messages"

check out this thread, it may give you some ideas Dashboard pie chart to show Raspberry pi GPIO history

Thanks a lot folks!!

I will give it a read.

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

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!

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


wouldn’t it be easier to convert this to something like minutes than to go down the way of date conversions?

Johannes

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

well you can click this:


next to the value to copy the path to this key of your msg object.
You could than use a change node like this:

where you paste your copied path in the first field of the move rule and use a jsonata 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

1 Like

Thanks a lot! That worked perfectly.

Regards!

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