Template: better than sensor:? (difference in config between template, rest, sensor, binary_sensor)

Should I move sensors to template: or doesn’t it matter? It looks like I can only set unique_ids in template. I read that template is the new way to do it, but I am not sure how to move thing like that:

This is under binary_sensor:

  - platform: ping
    host: google.ch
    count: 1
    scan_interval: 60
    name: Internet

There are also “rest:” sensors that are binary_sensors or sensors. It is a bit confusing.

That is not a template sensor. Only sensors created with the template platform,

- platform: template

Can be moved to the new template integration.

Ah I understand, so basically back in the days the templates were handled as “platforms”.

Is there a real difference or is it just more tidy like that?

The new integration can be reloaded without restarting, it supports state_class (for LTS or the energy dashboard), and a unique_id (so you can assign the sensor to an area).

You can still use the sensor platform with LTS or the energy dashboard but but you have to use customize.

1 Like

Thanks, that makes sense.

I do hope the other platforms will support unique_id as well at some soonish time.

I’ve seen you post this in another thread but, unless I am misunderstanding what you mean, that is not a benefit of the “new” method since you can also reload the “legacy” method without restarting too.

I’m pretty sure the “template entities” button under the “YAML Config reloading” section will reload both the “new” & “legacy” templates.

I use it all the time. I only have a few “new” style templates but both styles get reloaded with that service call.

1 Like

Well I don’t use the platform and if it’s the topic I’m thinking of the person couldn’t reload the platform, only the integration.

I’ll take your word for it though.

Yeah, actually the reload for the template sensor platform even pre-dated the introduction of the template integration.

1 Like