Unable to create Sensor in configuration.yaml

Hi,

i have spend several attempts on detecting if my iPhone is on the wifi. I have been looking for guides and tutorials but I can’t get it to work.

I have tried two ways of detecting, where both won’t even show me a new entity. Please help!

  1. Try: ping
device_tracker:
  - platform: ping
    hosts:
      My_iPhone: 123.456.7.890
      another_phone: phone_hostname
  1. Try - home assistant app + ssid
sensor:
  - platform: template
    sensors:
      My_iPhone_home:
        value_template: >-
          {% if states('sensor.my_iphone_ssid') == 'Routername' %}
            home
          {% else %}
            not_home
          {% endif %}
        friendly_name: 'My_iPhone Home (SSID = Routername)'

I pasted the code pretty much anywhere in the configuration.yaml. I had the impression that it should not make a difference, where I put the code, but please enlighten me, if it doesn’t.

Thank you very much guys <3

Ping sensors are only set up via the UI now:

Template sensor should work if you have only one sensor: heading in your file. However, you should use modern format (docs), and that sensor should be a binary sensor.

You can now set these up via the UI too:

Settings > Devices & Services > Helpers > Create Helper

then

Template > Template a binary sensor

then

If you’re desperate to use YAML, modern format version of the above would be:

template:
  - binary_sensor:
      - name: "My iPhone home"
        state: "{{ states('sensor.my_iphone_ssid') == 'Routername' }}"
        device_class: presence

Paste that in configuration.yaml and restart — but ensure that you only have one template: heading. If there’s already a line like:

template: !include template.yaml

then the code goes in template.yaml without the first line (so starting from “- binary_sensor:”).

All of this assumes that your sensor.my_iphone_ssid sensor is working as you imply.

Always read the official documentation, at least as a cross-reference and check. HA evolves, and guides and tutorials go out of date.

thanks alot!

1 Like