I have 3 old templates that are completely unlike each other. I tried my best to convert/consolidate them to the new template integration. Can someone please confirm the new consolidated templates are effectively identical to the legacy? Once I know these are functionally identical to each other (including their respective names), I can proceed with migrating all my other similar templates.
Legacy templates:
sensor:
- platform: template
sensors:
horizon_c_drive_read_bytes:
value_template: >-
{% set read_byte = state_attr('sensor.diskio_0', 'read_bytes') %}
{% set time_since = state_attr('sensor.diskio_0', 'time_since_update') %}
{% if (read_byte != None ) and (time_since != None ) %}
{{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
{% endif %}
availability_template: >-
{{ states("sensor.diskio_0") not in ["unknown", "unavailable", "none"] }}
unit_of_measurement: 'MB/s'
sensor:
- platform: template
sensors:
tautulli_total_bandwidth:
friendly_name: 'Total bandwidth'
value_template: "{{ (states('sensor.total_bandwidth') | int / 1000) | round(2) }}"
availability_template: >-
{{ states("sensor.total_bandwidth") not in ["unknown", "unavailable", "none"] }}
unit_of_measurement: "Mbps"
binary_sensor:
- platform: template
sensors:
plex_plex_for_android_mobile_galaxy_note9_is_visible:
value_template: >
{{ states('media_player.plex_plex_for_android_mobile_galaxy_note9') in ['on', 'playing', 'paused'] }}
New template integration: (consolidated)
template:
- sensors:
- name: "horizon c drive read bytes"
state: >
{% set read_byte = state_attr('sensor.diskio_0', 'read_bytes') %}
{% set time_since = state_attr('sensor.diskio_0', 'time_since_update') %}
{% if (read_byte != None ) and (time_since != None ) %}
{{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
{% endif %}
availability: "{{ states('sensor.diskio_0') not in ['unknown', 'unavailable', 'none'] }}"
unit_of_measurement: "MB/s"
- name: "tautulli total bandwidth"
state: "{{ (states('sensor.total_bandwidth') | int / 1000) | round(2) }}"
availability: "{{ states('sensor.total_bandwidth') not in ['unknown', 'unavailable', 'none'] }}"
unit_of_measurement: "GB"
- binary_sensor:
- name: "plex plex for android mobile galaxy note9 is visible"
state: "{{ states('media_player.plex_plex_for_android_mobile_galaxy_note9') in ['on', 'playing', 'paused'] }}"
For example, I’m not even sure which binary sensor below uses the correct format (to function identically to my old-format respective binary sensor). If they are both correct, maybe someone could suggest which way would be more common/preferred:
- binary_sensor:
- name: "plex plex for android mobile galaxy note9 is visible"
state: "{{ states('media_player.plex_plex_for_android_mobile_galaxy_note9') in ['on', 'playing', 'paused'] }}"
- binary_sensor:
- name: "plex plex for android mobile galaxy note9 is visible"
state: >
{{ states('media_player.plex_plex_for_android_mobile_galaxy_note9') in ['on', 'playing', 'paused'] }}"
…also, I’m not sure if I’m using parenthesis correctly in the line below:
state: "{{ (states('sensor.total_bandwidth') | int / 1000) | round(2) }}"