I’m trying to learn best practice for creating a new template sensor within configuration.yaml
Are these two sensors entirely equivalent ?
Is one form preferred over the other ?
# Method 1
sensor:
- platform: template
sensors:
windy_tommorow_01:
friendly_name: "Windy Tomorrow 01"
value_template: "{{ state_attr('weather.home', 'forecast')[0].wind_speed > 10 }}"
# Method 2
template:
- binary_sensor:
- name: "Windy Tomorrow 02"
state: "{{ state_attr('weather.home', 'forecast')[0].wind_speed > 10 }}"
Not equivalent-
For binary_sensor, the sensor is on
if the template evaluates as True
and off
otherwise. So can only have 2 possible outcome, on or off.
For sensor, you define a template to get a value for the sensor. So you can get various result based on your template.
OR did you misspell binary_sensor for sensor in the first method?
Anyway, you should use the recommended method to create template sensors, not legacy method.
1 Like
Great answer !
You’re correct, I overlooked the obvious difference between “sensor” and “binary_sensor”. The real gem in your answer is that link to the “legacy method”. That was the source of my confusion, the two apparent formats for accomplishing the same sensor.
Thanks for the quick reply !