Change/overwrite device tracker state

Our mobile devices are connected to the access point TP-Link that is connected to the LAN, the WAN router is further away.
Devices work and are known in the LAN, but HA does not recognize them as ‘home’, only ‘not_home’ is displayed.

with Node Red I can ping the devices successfully (false or e.g. 10), unfortunately I don’t know how to overwrite the status of the devices.

Can someone help me?

As a test I asked OpenAI to provide a response to your question, please test and let me know if it worked.

If you are using Node-RED to ping the devices on your local network and determine their status, you can use the ping response data to update the status of the devices in Home Assistant.

To do this, you can create a Node-RED flow that uses the ping response data to trigger a Home Assistant API call to update the device status. For example, you can create a function node that uses the http node to make a POST request to the Home Assistant API endpoint for updating device states.

Here is an example of a Node-RED flow that uses the ping response data to update the status of a device in Home Assistant:

Copy code

[{"id":"f9d8c1e7.72c3e","type":"function","z":"caa61b7e.d936c","name":"Update Device Status","func":"// Get the device ID and ping response data from the msg object\nvar deviceId = msg.payload.deviceId;\nvar pingResponse = msg.payload.pingResponse;\n\n// Set the device status based on the ping response data\nvar status = (pingResponse ? 'home' : 'not_home');\n\n// Set up the HTTP request to update the device status in Home Assistant\nmsg.method = 'POST';\nmsg.url = 'http://HASS_SERVER_IP:8123/api/states/' + deviceId;\nmsg.headers = {'Content-Type': 'application/json'};\nmsg.payload = {\n'state': status\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":300,"wires":[["78d5b0ce.e0f5f8"]]}]

In this flow, the Update Device Status function node takes the device ID and ping response data from the msg object and uses them to determine the device status. It then sets up a POST request to the Home Assistant API endpoint for updating device states, using the device ID and the updated device status as the payload of the request.

As an experiment I ask OpenAI to provide an answer, please le me know if this worked for you.

To use this flow, you will need to modify the HASS_SERVER_IP placeholder in the msg.url line of the Update Device Status function to the IP address of your Home Assistant server. You can also customize the flow to change the logic for determining the device status or to add additional processing for the ping response data.

Thank you for your help,

I tried, unfortunately without success.
I use my example code to ping a device, which works reliably and quickly.

Is there a way to create an entity that can be used as a tracking device?

Output:

Galaxy-XCover-4.fritz.box : msg : Object
object
payload: "home"
topic: "Galaxy-XCover-4.fritz.box"
_msgid: "f8dd5bd081e09929"
11.12.2022, 15:56:14tracker.seesent data : msg :
object
domain: "device_tracker"
service: "see"
data: object
mac: "DEVICE-MAC-ADDRESS"

Code:

[{"id":"ba5031d2daad6ad4","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"6e7286b25b1aa667","type":"ping","z":"ba5031d2daad6ad4","protocol":"Automatic","mode":"timed","name":"","host":"Galaxy-XCover-4.fritz.box","timer":"10","inputs":0,"x":130,"y":160,"wires":[["7e65e5c9b477b6d3"]]},{"id":"37e4d49039002c19","type":"debug","z":"ba5031d2daad6ad4","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":160,"wires":[]},{"id":"26d507d6f669eb6f","type":"api-call-service","z":"ba5031d2daad6ad4","name":"tracker.see","server":"da8200ca.e9886","version":5,"debugenabled":true,"domain":"device_tracker","service":"see","areaId":[],"deviceId":[],"entityId":[],"data":"{\"mac\":\"DEVICE-MAC-ADDRESS\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":770,"y":160,"wires":[["37e4d49039002c19"]]},{"id":"ba4bec15c649372e","type":"change","z":"ba5031d2daad6ad4","name":"home","rules":[{"t":"set","p":"payload","pt":"msg","to":"home","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":140,"wires":[["26d507d6f669eb6f"]]},{"id":"7e65e5c9b477b6d3","type":"switch","z":"ba5031d2daad6ad4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"},{"t":"regex","v":"^false(.*)$","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":160,"wires":[["ba4bec15c649372e"],["4740afea3128be18"]]},{"id":"4740afea3128be18","type":"change","z":"ba5031d2daad6ad4","name":"not_home","rules":[{"t":"set","p":"payload","pt":"msg","to":"not_home","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":180,"wires":[["26d507d6f669eb6f"]]},{"id":"368eaf4c56d0d4fa","type":"comment","z":"ba5031d2daad6ad4","name":"change MAC Address!","info":"","x":760,"y":120,"wires":[]},{"id":"8f4fa535b5752a71","type":"comment","z":"ba5031d2daad6ad4","name":"change Target IP/Hostname","info":"","x":140,"y":120,"wires":[]},{"id":"da8200ca.e9886","type":"server","name":"http://192.168.100.32:8123","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"id","deviceSelector":"id","entitySelector":"id","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

To create a tracking device in Home Assistant, you can use the device_tracker.see service. This service allows you to manually trigger updates for a device tracker entity, specifying the MAC address of the device and its current location.

Here is an example of how you can use the device_tracker.see service in your automation flow:

- id: '12345678'
  alias: Ping device
  trigger:
    - platform: mqtt
      topic: 'Galaxy-XCover-4.fritz.box'
  action:
    - service: device_tracker.see
      data_template:
        mac: '{{ trigger.payload }}'
        location_name: 'home'

In this example, the flow is triggered when a message is received on the MQTT topic Galaxy-XCover-4.fritz.box. When this happens, the flow calls the device_tracker.see service, using the mac address specified in the message payload and setting the device’s location to home.

You can adjust the flow to suit your specific requirements and use the data available in the trigger to set the appropriate values for the mac and location_name parameters.

@bastero

I didn’t know that something like ping scanner already existed.
powerful tool nmap can do that, probably for a long time.

https://www.home-assistant.io/integrations/nmap_tracker/