After coming across the fact that I can now create template sensors in Helpers, I decided to switch over to using the Helper construct rather than definining the sensors in YAML.
I had created a lot of template sensors and still have a few because the Helpers don’t allow the definition of attributes for template sensors.
I deleted the sensors I wanted to shift over to the Helper construct from the sensors.yaml
file, and then rebooted HA, thinking that this would delete the template sensors from HA. I then started creating the template sensors as Helpers.
The problem is that for some reason the unique_id
for some of the sensors has been retained, although the state is unavailable
. When I recreate the template sensors in Helper a _2
is appended to the unique_id
.
The problem is that I have a lot of Automations
that use the template sensors. Editing all the automations to add the _2
is infeasible.
How do I get rid of the sensors associated with the original unique_id
so that I can reuse the original unique_id?
Below are my remaining template sensors created in YAML.
configuration.yaml:
sensor: !include sensors.yaml
sensors.yaml:
- platform: template
sensors:
pws_report_details:
unique_id: "pws_report_values"
friendly_name: "PWS Report"
value_template: '{{ states.sensor.pws_report.attributes.observations[0]["stationID"] }}'
attribute_templates:
obs_time: '{{ states.sensor.pws_report.attributes.observations[0].obsTimeLocal }}'
solar_radiation: '{{states.sensor.pws_report.attributes.observations[0].solarRadiation }}'
wind_dir: '{{ states.sensor.pws_report.attributes.observations[0].winddir }}'
humidity: '{{ states.sensor.pws_report.attributes.observations[0].humidity }}'
temperature: '{{ states.sensor.pws_report.attributes.observations[0].metric.temp }}'
heat_index: '{{ states.sensor.pws_report.attributes.observations[0].metric.heatIndex }}'
dewpt: '{{ states.sensor.pws_report.attributes.observations[0].metric.dewpt }}'
windchill: '{{ states.sensor.pws_report.attributes.observations[0].metric.windChill }}'
wind_speed: '{{ states.sensor.pws_report.attributes.observations[0].metric.windSpeed }}'
wind_gust: '{{ states.sensor.pws_report.attributes.observations[0].metric.windGust }}'
pressure: '{{ states.sensor.pws_report.attributes.observations[0].metric.pressure }}'
precip_rate: '{{ states.sensor.pws_report.attributes.observations[0].metric.precipRate }}'
precip_total: '{{ states.sensor.pws_report.attributes.observations[0].metric.precipTotal }}'
stair_brightness:
unique_id: "stair_brightness"
friendly_name: "Stair Brightness"
value_template: >-
{% set result = namespace(brightness=0.0) %}
{% if states.sensor.stair_top_brightness.last_changed >
states.sensor.stair_bottom_brightness.last_changed %}
{% set result.brightness = states('sensor.stair_top_brightness') | float(0) %}
{% else %}
{% set result.brightness = states('sensor.stair_top_brightness') | float(0) %}
{% endif %}
{{ result.brightness }}
attribute_templates:
which: >-
{% set result = namespace( which='') %}
{% if states.sensor.stair_top_brightness.last_changed >
states.sensor.stair_bottom_brightness.last_changed %}
{% set result.which = 'top' %}
{% else %}
{% set result.which = 'bottom' %}
{% endif %}
{{ result.which }}
unavailable_entities:
friendly_name: "Unavailable Entities"
value_template: >-
{{ states | selectattr('state','eq', 'unavailable') | list | count }}
attribute_templates:
which: >-
{{ states | selectattr('state','eq', 'unavailable') | map(attribute='name') | list | join(';\n') }}
Below is a small sample of the issue exposed through Developer Tools → States.