Welcome to the forums. Please see point 11 about correct post formatting here: How to help us help you - or How to ask a good question
If you actually did this, then your indentation is way off.
e.g. should be:
sensor
- platform: mqtt
name: "My Car"
state_topic: "tele/garagesensor/SENSOR"
value_template: '{{ value_json.SR04.Distance }}'
Also binary sensor templates must evaluate to true or false. So either make this a sensor (instead of a binary sensor):
- platform: template
sensors:
car_presence:
value_template: >-
{% if states('sensor.my_car') | int > 200 %}
Home
{% else %}
Away
{% endif %}
Or (a better idea) rearrange the template to be a true / false template for a binary sensor:
- platform: template
sensors:
car_presence:
entity_id: sensor.my_car # this tells HA what to monitor for updates to the template
value_template: "{{ states('sensor.my_car') | int < 200 }}"
device_class: presence
The device class will convert the on/off state of the binary sensor to display as Home/Away. Though if using the state of this binary sensor in an automation still use the states on
or off
. Not Home or Away.
Device classes: https://www.home-assistant.io/components/binary_sensor/#device-class