Default longitude/lattitude


Searched the forums and the web, but I can’t find a way to set the default long. and lat. in the Node-Red add-on. Can somebody lead me the way ?

Thx !

You can use the values that are defined in home assistant and use the value from the sun component from HA.
So, no absolute need to redefine those in NR.
If, you want to use lat/lon in NodeRed for more advances features, you can add eg. node-red-contrib-sunevents and there in the configuration module you can add lat/lon.
Hope this helps.

I do need em when i want to use BigTimer, ezTimer, …

@devastator did you manage to find a reasonable way to do it?
I am also interested in this. Don’t want to enter geo data everytime I add a node that depends on it, all my nodes should use my default location unless different is entered manually. I guess it should be possible to use env variables but still you would need to reference them in all nodes.

I don’t know for sure, but I’d guess this is about who wrote the node and if they force it to reference a global variable. Big timer does not as far as I can tell… Coder competence rather than the potential within NodeRed…

Big Timer definitely requires geo information to operate. Has anyone found a way to get that from home assistant and into node-red?

You can access Home Assistant entities and states in Node-RED’s Global context. In Node-Red, simply navigate to the “Context Data” menu and you can explore all Home Assistant context information and even copy specific path’s to Global context variables. More info here.

Here’s a simple example of how to get Latitude and Longitude into Node-RED from Home Assistant.

As you can see in the debug pane on the right, the latitude and longitude is correctly fetched from Home Assistant. So basically you can get all Home Assistant states and data in Node-RED as part of the Global context.

I understand this thread is a little old, but I hope this helps someone looking for answers in the future. :slightly_smiling_face:


1 Like

Hey @D4vy - thanks for highlighting this - I’m the dev of eztimer and it’s always been an issue to me having to re-enter lat/long (or copy nodes to keep it). As someone said above - ‘coder [in]competence’… :slight_smile:.

Anyway, this thread was highlighted to me, and this gives me something I can implement so users can select a HA zone instead of having to enter lat/long every time. Again, thanks!

@bnutt Glad I could help! :slightly_smiling_face:

I will definitely give eztimer a try once this is implemented. I’ve tried using nodes like bigtimer, but none of the timer nodes I researched on has the capability to use global context data. Like you said, I’m reluctant to hard code the coordinates everywhere when it’s already available in HA context data.

Good luck with eztimer! :slightly_smiling_face:

Ok, but currently geo location is fetched from some var inside NR. Where can I edit/set this variable so all nodes are updated automatically ?

Simple function to get lat/long from home assistant home zone. Takes as input the zone you want to use. Outputs msg.longitude and msg.latitude. requires that you have setup longitude and latitude correctly in your home assistant configuration.

[{"id":"a0c680019e59c743","type":"inject","z":"d31bf3ae8018a0d0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"home","payloadType":"str","x":90,"y":3800,"wires":[["afe45e964c505110"]]},{"id":"3b41dc7624dc6fe3","type":"debug","z":"d31bf3ae8018a0d0","name":"debug 97","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":3800,"wires":[]},{"id":"afe45e964c505110","type":"function","z":"d31bf3ae8018a0d0","name":"get HA lat-long","func":"var long\nvar lat\nlet zone = 'zone.' + msg.payload\nlong=global.get(\"homeassistant.homeAssistant.states['\" + zone + \"'].attributes.longitude\");\nlat=global.get(\"homeassistant.homeAssistant.states['\" + zone + \"'].attributes.latitude\");\nmsg.long=long;\;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":3800,"wires":[["3b41dc7624dc6fe3"]]}]
1 Like