Hard time understanding different ways to create template sensors

I see it has been asked before, and I see there have been help articles written that explain this, but I am just not getting it (I promise, I’m not usually slow to understand things).

What is the difference between these entries (A, B and C – all actual working entries of mine) in configuration.yaml?

Can someone explain it in simple terms please?

Thank you!

A:

binary_sensor:

  • platform: ping
    host: 192.168.70.161
    name: “ping_THR316-125attic”
    scan_interval: 00:05:00

B:

template:

  • binary_sensor:

    • name: Workshop no_power
      state: “{{ ‘No Power’ in states(‘sensor.workshop_heuristics’) }}”
  • sensor:

    • name: “Home Temperature”
      unit_of_measurement: “°F”
      device_class: temperature
      state: “{{ state_attr(‘weather.home’, ‘temperature’) }}”

C:

sensor:

  • platform: template
    sensors:
    371_2nd_floor_heat_graph:
    friendly_name: “371 2nd Floor Heat Graph”
    unit_of_measurement: “”
    value_template: "{% if is_state_attr(‘climate.371_2nd_floor’, ‘equipment_running’,‘auxHeat1’) -%} {{states(‘sensor.371_2nd_floor_temperature’) }} {%- else -%} 0 {%- endif %} "

That’s not a template sensor, it’s a ping sensor:

That’s the current method for creating template sensors and is how you should create them going forward.

That’s the ‘legacy’ way of making template sensors. As you can see, it still works and I suspect will indefinitely into the future, but you’ll have more features/options using the current method.

Everything you could want to know about template sensors is here:

Thank you!

What is it called (or what does it mean) when “binary_sensor:” starts in column 1?

You called it a “ping sensor” but I assume that is because the “platform:” says it’s type “ping”

I just make this as my first attempt to convert old to new template format.

The syntax requirements are onerous (single and double quotes, parenthesis, “state:” vs “states”, etc.).

template:

  • sensor:
    • name: “farm_uni_converted_new”
      unit_of_measurement: “V”
      state: “{{ (states(‘sensor.hoophouse_shelly_uni_tasmota_1_analog_a0’) |float) /70.1}}”

Please format your code blocks properly by placing 3 backticks (```) above and below the block or use the “preformatted text” function button:

image

It’s one of many possible binary sensors you could add to your configuration, the ping sensor is just one of them.

Do you have a question?

No question on my converted format. Just wanted to share my excitement.

Thank you for your help – very much appreciated.

Glad you got it sorted out!