Blueprint Domain:Template Help

Howdy all, I’m trying to get my blueprint going but I may have a fundamental misunderstanding of how this is supposed to work as I’ve been at this all day.

configuration.yaml:

template: !include templates.yaml

templates.yaml:

- use_blueprint:
    path: petlibro/dockstream_wifi_signal_strength_with_icon.yaml
    input:
      wifi_status_sensor: binary_sensor.dockstream_fountain_wi_fi
      wifi_signal_sensor: sensor.dockstream_fountain_wi_fi_signal_strength
      unique_id: dockstream_testing
      friendly_name: Dockstream Testing

/homeassistant/blueprints/template/petlibro/dockstream_wifi_signal_strength_with_icon.yaml:

blueprint:
  name: Dockstream WiFi Signal Sensor
  description: Creates a binary sensor with an RSSI-strength icon
  domain: template

  input:
    wifi_status_sensor:
      name: WiFi binary sensor
      description: The binary sensor that reports whether the WiFi is connected
      selector:
        entity:
          domain: binary_sensor

    wifi_signal_sensor:
      name: WiFi signal strength sensor
      description: The sensor that reports RSSI signal strength
      selector:
        entity:
          domain: sensor

    unique_id:
      name: Unique ID
      description: Unique ID of the Entity
      selector:
        text:

    friendly_name:
      name: Friendly sensor name
      description: Friendly Name of the Entity
      selector:
        text:


variables:
  wifi_status_sensor: !input wifi_status_sensor
  wifi_signal_sensor: !input wifi_signal_sensor

sensor:
  - name: !input friendly_name
    unique_id: !input unique_id
    device_class: connectivity

    state: >
      {{ 'on' if is_state(wifi_status_sensor, 'on') else 'off' }}

    availability: >
      {{ states(wifi_signal_sensor) not in ['unknown', 'unavailable', None] }}

    icon: >
      {% if is_state(wifi_status_sensor, 'off') %}
        mdi:wifi-off
      {% else %}
        {% set rssi = states(wifi_signal_sensor) | int(-100) %}
        mdi:wifi-strength-{{
          4 if rssi >= -60 else
          3 if rssi >= -70 else
          2 if rssi >= -80 else
          1
        }}
      {% endif %}

I’ve tried a lot of different variations, sometimes I get errors like

The system cannot reload because the configuration is not valid: Unexpected error calling config validator: pop expected at most 1 argument, got 2

sometimes

Invalid config for ‘template’ at templates.yaml, line 22: expected SensorDeviceClass or one of ‘date’, ‘enum’, ‘timestamp’,… for dictionary value ‘sensor->0->device_class’, got None Invalid config for ‘template’ at templates.yaml, line 22: invalid template (TemplateSyntaxError: unexpected char ‘!’ at 10) for dictionary value ‘sensor->0->availability’, got None Invalid config for ‘template’ at templates.yaml, line 22: invalid template (TemplateSyntaxError: unexpected char ‘!’ at 12) for dictionary value ‘sensor->0->state’, got None Invalid config for ‘template’ at templates.yaml, line 22: invalid template (TemplateSyntaxError: unexpected char ‘!’ at 21) for dictionary value ‘sensor->0->icon’, got None

Among others.
So, I’m hoping someone can point me in the right direction, I’ve asked AI but that guy’s crazy.

There are a few things that need to be addressed:

  • You need to remove the - under sensor (I’ve been bitten by this one too, it yields errors that are difficult to understand)
  • I would put name and unique_id in the templates.yaml entry. It may work as you had it (I’ve never tested doing it that way) but it doesn’t really make sense to put them in the input section when you could just use them directly.
  • The class connectivity is not a valid device class for sensor entities… Did you mean to create a binary sensor… that would make sense with the state template?

With those things in mind, this is how I would do it:

#/homeassistant/blueprints/template/petlibro/dockstream_wifi_signal_strength_with_icon.yaml

blueprint:
  name: Dockstream WiFi Signal Sensor
  description: Creates a binary sensor with an RSSI-strength icon
  domain: template
  input:
    wifi_status_sensor:
      name: WiFi binary sensor
      description: The binary sensor that reports whether the WiFi is connected
      selector:
        entity:
          domain: binary_sensor
    wifi_signal_sensor:
      name: WiFi signal strength sensor
      description: The sensor that reports RSSI signal strength
      selector:
        entity:
          domain: sensor
variables:
  wifi_status_sensor: !input wifi_status_sensor
  wifi_signal_sensor: !input wifi_signal_sensor
binary_sensor:
  state: "{{ is_state(wifi_status_sensor, 'on') }}"
  availability: "{{ has_value(wifi_signal_sensor) }}"
  icon: >
    {% if is_state(wifi_status_sensor, 'off') %}
      mdi:wifi-off
    {% else %}
      {% set rssi = states(wifi_signal_sensor) | int(-100) %}
      mdi:wifi-strength-{{
        4 if rssi >= -60 else
        3 if rssi >= -70 else
        2 if rssi >= -80 else
        1 }}
    {% endif %}
#templates.yaml
  - unique_id: dockstream_testing
    name: Dockstream Testing
    use_blueprint:
      path: petlibro/dockstream_wifi_signal_strength_with_icon.yaml
      input:
        wifi_status_sensor: binary_sensor.dockstream_fountain_wi_fi
        wifi_signal_sensor: sensor.dockstream_fountain_wi_fi_signal_strength

Finally, the blueprint needs to be correct and loaded before you load the template configuration entry. You may want to comment out the template configuration entry, restart HA, then un-comment it, and then reload Template entities.

Dang that worked perfectly.

And yeah, I did mean to do binary sensor, it’s even a binary sensor in my original non-blueprint template.yaml code. Not sure how I ended up mangling that in the process.

I had quite a few misconceptions that you helped me clear up.
Thanks a lot, I appreciate it!