Invalid config for [binary_sensor.template]: expected dictionary for dictionary value @ data

Hello y’all,

i’ve been trying this intedations now for a while but still can’t figure out whats wrong witch that code snip.

Located in /config/binary_sensor.yaml.

I am getting these errors:

Invalid config for [binary_sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘icon’]. Got ‘mdi:speedometer’
expected dictionary for dictionary value @ data[‘sensors’][‘name’]. Got ‘LAN Ping’
expected dictionary for dictionary value @ data[‘sensors’][‘state’]. Got “{{ state_attr(‘binary_sensor.Router_Ping’, ‘round_trip_time_avg’)|round(2) }}”
expected dictionary for dictionary value @ data[‘sensors’][‘unit_of_measurement’]. Got ‘ms’. (See ?, line ?).
Invalid config for [binary_sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘icon’]. Got ‘mdi:speedometer’
expected dictionary for dictionary value @ data[‘sensors’][‘name’]. Got ‘WAN Ping’
expected dictionary for dictionary value @ data[‘sensors’][‘state’]. Got “{{ state_attr(‘binary_sensor.google_dns_ping’, ‘round_trip_time_avg’)|round(2) }}”
expected dictionary for dictionary value @ data[‘sensors’][‘unit_of_measurement’]. Got ‘ms’. (See ?, line ?).

Cann you assist me what is wrong?

- platform: template
  sensors:
    name: "LAN Ping"
    icon: "mdi:speedometer"
    unit_of_measurement: "ms"
    state: "{{ state_attr('binary_sensor.Router_Ping', 'round_trip_time_avg')|round(2) }}"



- platform: template
  sensors:
    name: "WAN Ping"
    icon: "mdi:speedometer"
    unit_of_measurement: "ms"
    state: "{{ state_attr('binary_sensor.google_dns_ping', 'round_trip_time_avg')|round(2) }}"

Thanks in advance :slight_smile:

EDIT:
even with this code it’ showing another error:

- platform: template
  sensors:
  - name: "LAN Ping"
    icon: "mdi:speedometer"
    unit_of_measurement: "ms"
    state: "{{ state_attr('binary_sensor.Router_Ping', 'round_trip_time_avg')|round(2) }}"



- platform: template
  sensors:
  - name: "WAN Ping"
    icon: "mdi:speedometer"
    unit_of_measurement: "ms"
    state: "{{ state_attr('binary_sensor.google_dns_ping', 'round_trip_time_avg')|round(2) }}" 

Invalid config for [binary_sensor.template]: expected dictionary for dictionary value @ data[‘sensors’]. Got [OrderedDict([(‘name’, ‘LAN Ping’), (‘icon’, ‘mdi:speedometer’), (‘unit_of_measurement’, ‘ms’), (‘state’, “{{ state_attr(‘binary_sensor.Router_Ping’, ‘round_trip_time_avg’)|round(2) }}”)])]. (See ?, line ?).
Invalid config for [binary_sensor.template]: expected dictionary for dictionary value @ data[‘sensors’]. Got [OrderedDict([(‘name’, ‘WAN Ping’), (‘icon’, ‘mdi:speedometer’), (‘unit_of_measurement’, ‘ms’), (‘state’, “{{ state_attr(‘binary_sensor.google_dns_ping’, ‘round_trip_time_avg’)|round(2) }}”)])]. (See ?, line ?).

You are mashing legacy and new template formats together. Use one or the other:

Legacy:

sensor:
  - platform: template
    sensors:
      lan_ping:
        friendly_name: "LAN Ping"
        unit_of_measurement: "ms"
        icon_template: "mdi:speedometer"
        value_template: "{{ state_attr('binary_sensor.Router_Ping', 'round_trip_time_avg')|round(2) }}"

New:

template:
  - sensor:
      - name: "LAN Ping"
        unit_of_measurement: "ms"
        icon_template: "mdi:speedometer"
        state:  "{{ state_attr('binary_sensor.Router_Ping', 'round_trip_time_avg')|round(2) }}"

Note the new format goes in configuration.yaml. Not sensors.yaml

1 Like

Hi @tom_l,

SO in sensors.yaml i need to work with legacy method :slight_smile: thanks

Now i am getting another error if using

unit_of_measurement: “ms”

Invalid config for [binary_sensor.template]: [unit_of_measurement] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->sensors->lan_ping->unit_of_measurement. (See ?, line ?).

can you help with that issue also?

Only sensors have a unit of measurement. Not binary sensors.

1 Like

That’s not really the case. The new format can be used in sub-template files. But the inclusion method “!include_ …” matters.

I also bumpeiinto this issue:

Best regards,

That was exactly the case. This is not valid:

It is a mishmash of old and new formats. Exactly like I said it was.

What you linked to is a completely different error using the new format.

Sorry, i referred to:

The new format doesn’t have to be in the configuration file. It can be a sub-config file.

The top level integration still has to go there, even if you use an include, e.g. this goes in configuration.yaml not sensors.yaml:

template: !include...

That is what I was referring to.