Problems with template

Hello

I’m trying to track my phone using the android app and ibeacons. It all works but having problems with a template for the binary sensor. The value works in dev, but I keep getting this error

Configuration warnings
Invalid config for 'template' from integration 'binary_sensor' at binary_sensor.yaml, line 53: 'state' is an invalid option for 'binary_sensor.template', check: sensors->beacon_detected->state

I have this in binary_sensor.yaml

  - platform: template
    sensors:
      beacon_detected:
          friendly_name: Beacon Detected
          device_class: presence
          value_template: >-
          state: >
            {% if (state_attr('sensor.marks_s22_ultra_beacon_monitor', 'a0b13730-3a9a-11e3-aa6e-0800200c9a66_56780_63704') != None) 
            %}
              on
            {% else %}
              off
            {% endif %}

Any ideas please? It has been a long time since I played with my HA yaml

Since you are using the legacy format, you should not have the state: > in there… you can also get rid of the if:

- platform: template
  sensors:
    beacon_detected:
      friendly_name: Beacon Detected
      device_class: presence
      value_template: >-
        {{ state_attr('sensor.marks_s22_ultra_beacon_monitor', 'a0b13730-3a9a-11e3-aa6e-0800200c9a66_56780_63704') != None }}
1 Like

Thank you so much! I need to get all my automations re-done to the newer way of running them

You can always use the UI to create a template binary sensor helper, avoiding YAML and the legacy / modern complication.

Assuming your template works ( not sure about the != None bit…):

1 Like