How to get presence detection to work (ping)?

Another question from me, once again proving that I have not really understood the overall (or general concept).

I am trying to find a way to figure out if I am home or not. These two seems not to be doing the trick as they are both registered as home, even if my phone is on flight mode:

- entity: person.person1
- entity: device_tracker.mi_mix_2

And then I found this: https://www.home-assistant.io/integrations/ping.

It starts off with saying:
To use this sensor in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
binary_sensor:
  - platform: ping
    host: 192.168.0.1

I assume 192.168.0.1 should be replaced by the correct IP for the thing I want to track, in this case 192.168.0.35.

And further down, under the heading “Presence Detection” writes:
To use this presence detection in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
device_tracker:
  - platform: ping
    hosts:
      hostone: 192.168.2.10

I then change 192.168.2.10 to 192.168.0.35 and copy all of this into the top of my configuration.yaml as per the below.

binary_sensor:
  - platform: ping
    host: 192.168.0.35
device_tracker:
  - platform: ping
    hosts:
      hostone: 192.168.0.35

But I am not sure how to proceed from there. On I'm NOT home (although that one is using nmap, which I do not know how to get to work on NUC), it says “You have to restart HA. A device will be created (when discovered for the first time on the LAN) starting with : “device_tracker.”, you can see it in the development tools (tab: states)… You can use that name in your automation.”
But I do not see anything like that in states, and see nothing in devices. Or in entities

What am I missing, does something also need to be installed somewhere to get ping to work? Or?

PS: And no, there is no tracker for my modem (Sagem). And no, I do not normally have Bluetooth on, so that is also a no go. And no, the zone thing does not work in my mobile, sees me as home all the time (others are having the same problem, eg here: Zone based tracking).

Really hope somebody can help. I am stuck.

here bro

this should help

  - platform: command_line
    name: BroadLink
    command: 'ping -W 1 -c 1 192.168.1.25 > /dev/null 2>&1 && echo success || echo fail'
    device_class: connectivity
    payload_on: "success"
    payload_off: "fail"

just place in side the binary_sensor:

1 Like

Thanks. I wonder how anybody like me would ever have figured that out, really difficult, I find. Anyhow, I have been trying this.

I assumed I should replace the binary sensor I had with yours, not adding.

So simply copying and pasting your suggestion (except ping 192.168.0.35 instead of 192.168.1.25). And keep the device_tracker part of it (I have a feeling I might get rid of that). So I will end up with this:

binary_sensor:
  - platform: command_line
    name: Broadlink
    command: ping -W 1 -c 1 192.168.1.35 > /dev/null 2>&1 && echo success || echo fail
    device_class: connectivity
    payload_on: success
    payload_off: fail
device_tracker:
  - platform: ping
    hosts:
      hostone: 192.168.0.35

Problem is though, it is not working. I do not see any integrations, devices, states or the like called ‘BroadLink’, or hostone for that matter. When I copy the code, the ’ in front of ping and after fail is not included. And so are the " " around success and fail, but I assume that’s how it should be. Any additional suggestions?

Any suggestions?

I wonder: I said running on NUC. But not under windows or anything like that. Saying that because the command_line, echo, etc looks like DOS. I am running hassos. Perhaps that explains why it is not working.

No luck here, but eventually got nmap to work after adding /32 to ip address, and 2 x reboot (not restart), but don’t know why/how. But works a charm:-) see details here How to get presence detection