I have several templates in my configuration (from multiple source) that work but are written differently
So I wonder what is the difference/best pratrice between .
Thanks for reminding me! I need to start updating my config file.
Any tips on making this change in a config that’s got lots of templates under sensor:?
Will automations, scripts and Lovelace cards need to be changed, or will the name: just be used same as it was in the old-style entry under sensors:? Will the Recorder database entries remain the same?
Just make sure the “name” of the “new” sensor matches the name of the old one… Everything else will be transparent… History is kept if name is the same…
Be careful about the changes: no “friendly name” allowed and “value”/“value_template” are becoming “state”…
From your sensor.yaml file, you can only migrate the entries defined with - platform: template. Your existing - platform: rest sensors should remain as is.
As you copy your - platform: template entries, remove the friendly_name properties, and change value: and/or value_template: to state: so they fit the new format of templates.yaml.
I recommend to try it with one simple template sensor – comment it out in the old place, then paste it in the new place, with the new syntax in mind.
I’m starting this migration mainly so that I can get stats on some of the sensors. Can you mix and match? i.e. i have sensors defined in 4 different files. Can 2 files be -platform: template and 2 files be template: -sensor? or do I have to migrate all -platform: template sensors at once across all files?
From everything I’ve seen, currently there isn’t a plan to deprecate the legacy format. As long as you set your files up using the correct top-level configuration keys and the files are properly included in your configuration.yaml file, you can have both formats… if you use packages, you can even have both formats working in the same file.
template:
- sensor:
- name: "Total Current Power Production"
# solar_power_total_current_production:
unique_id: 9fb71580-0687-434e-96c0-efc58cdc43cd
unit_of_measurement: "W"
state: "{{(states('sensor.envoy_current_power_production')|float) + (states('sensor.envoy_current_power_production')|float)}}"
When I left them included via sensor:, vscode gives me an error indicating “missing property “platform”” deriving from “Property template is not allowed.yaml-schema: http://schemas.home-assistant.io/integration-sensor”
Maybe no deprecation announced yet, but for example state_class: can be defined in the new format only.
This might be important in order to make statistics working.
Likely, there was no need or advantage to switching them over. The trigger-based functionality that was added with the newer method for sensors, etc doesn’t really make sense for Locks, Lights, Switches…