Broken sensors based on attribute in HassOS

Since I moved to HassOS, a number of sensors are not showing up. They are in configuration.yaml like this:

  sensors:
    door_battery:
      friendly_name: "Door"
      unit_of_measurement: '%'
      value_template: "{{ states.binary_sensor.door_window_sensor_xxxxxxxxxxxxxx.attributes.battery_level }}"

They are displayed in frontend with the following in groups.yaml:

door_group:
  name: Doors
  control: hidden
  entities:
    - sensor.door_battery

Can anyone help me? Thank you very much.

Adam.

Does the binary_sensor.door_window_sensor_xxxxxxxxxxxxxx referenced exist in your states page? and does it have the battery attribute?

Yes they are all visible on the states page. And yes, it has a battery attribute, which is shown as:
battery_level: 51

Hopefully you can help me @finity :slight_smile:

This is happening in the log when I open the tab where the binary sensors are listed (one error for every binary sensor).

https://HOMEASSISTANTURL.duckdns.org:8123/frontend_latest/app-CODEc.js:CODE:CODETypeError: null is not an object (evaluating ‘e._stateDisplay’)

16:58 components/system_log/init.py (ERROR)

(at the places where I write CODE is a code listed, but I wasn’t sure it was safe to share :slight_smile: )

What kind of sensors are they?

I think the template looks correct. I have no idea what that code is telling you specifically.

Here is a battery sensor of mine:

sensors:
  batt_garagedoor1:
    friendly_name: 'Garage Door North Position Battery'
    value_template: >-
      {%- if states.zwave.garage_door_north_position -%}
        {{ states.zwave.garage_door_north_position.attributes.battery_level }}
      {%- else -%}
        n/a
      {%- endif -%}

You’re sure the binary_sensor Itself has the battery_level attribute?

As you can see from my z wave stuff the battery attribute isn’t in the sensor entity. It’s in the zwave entity.

Thank you very much @finity! Problem solved. I still don’t know what the problem was, but I replaced the code with yours and now it works again.