Can someone help me figure out how to show if my car is in the garage or not, I have it set up as 2 sensors, one a binary and one a sensor, I’m pretty sure thats wrong but here is my code. Any and all help would be greatly appreciated
- platform: mqtt
name: "My Car"
state_topic: "tele/garagesensor/SENSOR"
value_template: '{{ value_json.SR04.Distance }}'
- platform: template
sensors:
car_presence:
value_template: >-
{% if is_state('sensor.my_car','true') | int > 200 %}
Home
{% else %}
Away
{% endif %}
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.
Thank you so much @tom_l. I have been trying to figure this out for 2 weeks. Rearranging as a binary did the job! I actually understand this too. I will read up on post formatting… Once again, thank you so much