Hi all!
I have node red and homeassistant integrated and i’ve recently created a node with location check and works fine.
Now i want to check how long im at home according to homeassistant location. There is a state that change the location and behind that writes that change. How can i get that change with a string?
Maybe there is a node that can do this?
Thanks a lot!!
Normally, you might output the location change event to MQTT and use a flow in Node-RED to calculate the time difference. I do that with a couple of door-open sensors for example so that I can issue Telegram warnings if a door has been open too long.
uhm ok, what i dont want to use is MQQT and make it simple through one app, in this case homeassistant.
Maybe i didnt explaing too well, but the thing is that i want to do turn on a light as soon as i arrive home and that is solved with the node STATE of homeassitant. When the state change from AWAY to HOME it turn on the light. But what if im home for about 2 hours ago, well i have to check that somehow. The node has a an OUTPUT like this:
"last_changed": "2019-12-29T04:49:50.230660+00:00",
"last_updated": "2019-12-29T04:49:50.230660+00:00",
but i dont how to get that info so i can work it out.
Thanks a lot!!!
Sorry, I don't use HA so I don't know how it works.
However, a quick search through the Flows library may help:
If you say you have created the node, could you not just change what is spitted out? To a format you feel you can use? What you have shown is just two time stamps, with the same content. There is no info in there telling if AWAY or HOME
The thing is that i cannot get that time stamp coming from the node.
This is the home assistant node that track my ihphone and tells me where i am.
Regarding to this, let's say for example. I go out to buy something at about 5 blocks away from home, then the location state changes from HOME to AWAY because i'away.
When i return home and the GPS matches my location the node changes to HOME.
BUUUUTT here is the trick, what about if i don't want to turn on the light if i'm HOME during the daylight? and do that only in the nightime.
The node has this preferences to set up, the ones that i previously redacted.
How can i get that information and make a condition with it?
Any other idea?
thanks a lot!
I may have misunderstood you, you said you had CREATED a node but instead you seem to have CONFIGURED a node of some kind (you have not mentioned what node you are using???)
Anyway, based on your example, to get the time stamps from the data, in javascript you could use something like
let ts = msg.data.last_changed;
What you will get is the time stamp as a string. Next you need to compare this with your current time and to check if you should turn on the lights or not. To compare time stamps is what you can do in javascript. there are many examples on the net. To check if you should turn on the lights or not, you could use the suncalc node that will tell you if sun is up or down at your location. A bit of a javascript in a function node and you should be fine
But, you say you get events like HOME and AWAY. Where are they, you have not showed those? If you get them from HA, those you could use, no need to grab the timestamps, just take the events and compare with current sun state from suncalc node. Eventually setting up a time window when you anyway never want the lights to go on (like in the middle of the night and your phone goes off line, you may not want the lights to go on anyway)
Thanks a lot!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.