Please help me with the template configuration

This is my template value:

  • platform: template
    sensors:
    • name: “Sleep Breath Average Yesterday”
      unique_id: sleep_breath_average_yesterday
      unit_of_measurement: bpm
      state: >
      {{ states.sensor.sleep_quality.attributes.yesterday.breath_average }}
      icon: “mdi:lungs”

I’m getting this error:

Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’]. Got [OrderedDict([(‘name’, ‘Sleep Breath Average Yesterday’), (‘unique_id’, ‘sleep_breath_average_yesterday’), (‘unit_of_measurement’, ‘bpm’), (‘state’, ‘{{ states.sensor.sleep_quality.attributes.yesterday.breath_average }}\n’), (‘icon’, ‘mdi:lungs’)])]. (See ?, line ?).

Here’s the attributes from the sensors:

What am I doing wrong here?

Reference:

You are mixing the configuration of the new template sensor integration with the legacy template sensor platform.

e.g. you are using the platform structure but integration state option.

Pick one (I would suggest the new integration as it supports new features) and stick with only those available options.

Also please format your pasted configuration as per point 11 here.

1 Like

Hi @chintito4ever

I agree, you are mixing formats:

You can either use the old template platform in he sensors section, like this:

  - platform: template
    sensors:
      yst_sleep_avg:
        friendly_name: "Sleep Breath Average Yesterday"
        unique_id: sleep_breath_average_yesterday
        unit_of_measurement: 'bpm'
        value_template: "{{ state_attr('sensor.sleep_quality', 'yesterday.breath_average') }}"
        icon: mdi:lungs

Or the new way in the templates section:

  - sensor: 
    - name: "Sleep Breath Average Yesterday"
      unique_id: sleep_breath_average_yesterday
      unit_of_measurement: bpm
      state: "{{ state_attr('sensor.sleep_quality', 'yesterday.breath_average') }}"
      icon: mdi:lungs

I guess you are aiming at the last one, so in stead of

  - platform: template

You simply need to create/use the platform section in your configuration.yaml

template:

And correct the way you extract the attribute value as I suggest.

I am actually not sure whether the yesterday attribute includes other attributes, and in such case whether you need to call the state_attr twice. like this

      state: "{{ state_attr(state_attr('sensor.sleep_quality', 'yesterday') , 'breath_average') }}"

Give it a try.

1 Like

Thank you so much for your help, I really appreciate that but unfortunately none of the configurations worked you have suggested me. Is there any other way I can try?

sensor.sleep_quality has no attribute yesterday.breath_average.

Try:

value_template: "{{ state_attr('sensor.sleep_quality', 'yesterday').breath_average }}"

This will only work if the attribute yesterday contains a list, not a string that looks like a list.

2 Likes

Thank you, Tom. You appear to be quite knowledgeable and active on this forum; could you perhaps assist me in integrating Bouncie with HA, or at the very least direct me to someone who can? I’m happy to provide my account details with any developer that is interested in working on this project but does not have access to a device.

Here’s the link to the request of the integration:

New Integration Request: Bouncie - OBD2 vehicle tracking - Feature Requests - Home Assistant Community (home-assistant.io)

Bank account details :slight_smile:

No I can’t help with that sorry.