Split a string of a Location Payload from Datacake and pass it to Home Assistant as coordinates

I get a location payload from Datacake as a string separated by the coma. I want to separate it to two single values to pass it on to Home Assistant as single values latitude and longitude. Does anyone know how I separate it? Or even better, how I can use it directly as coordinates in Home Assistant?

msg :
type: "nodered/discovery"
server_id: "f6acf75c.eea248"
node_id: "293d1e9a4137bd51"
component: "sensor"
config: object
name: "GPS"
state: "(48.102704,11.412253)"
attributes: object
id: 22

Pass the msg through a function node

v1: Return Array...

msg.payload = msg.payload.state.replace('(','').replace(')','').split(',').map(Number)
return msg


v2: Return object...

const coords = msg.payload.state.replace('(','').replace(')','').split(',').map(Number)
msg.payload = {
  latitude: coords[0],
  longitude: coords[1],
return msg

Most of the regulars I know on here dont use HA - you should try the forum.


When copying a payload to show on the forum, please use the copy value button so that it is valid JSON...

Assuming you have the Home Assistant add-on for Node Red installed then you will have Event Node installed


This allows you to generate an event into HA against an entity.

So you will need to work out "where" i.e. which entity you want to send this to and from there you then push the data across (as Steve has documented above) by including it in the message payload - the tricky bit will be working out what format the entity you are planning on passing this data to supports.

As Steve has said there are very few on here who use NR and HA (i am one of the few) - you would be better off trying this question in the NR subforum of third party integrations on the HA forum - there are a couple of very switched on guys there.

If you did not want to use the HA nodes - you can just pump this data out from NR through MQTT and have HA monitoring (subscribe) to the channels you are using


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