Challenged with making a sensor open/closed

Hi, I’m having difficulty changing the attribute of a Monoprice door/window sensor. The sensor currently shows 22 for open and 23 for close. I know I can use template to make the changes :

- platform: template
  sensors:
        fdstatus:
          value_template: '{% if is_state("sensor.front_door_sensor_access_control", "23") %}closed{% else %}open{% endif %}'
          friendly_name: 'FD'

but what I would like to do in customize.yaml

sensor.front_door_sensor_access_control:
  device_class: opening

It’s my understanding by reading “Customizing entities” that I can do it that way and it should convert it to open/closed or at least on/off.

Am I misunderstanding how this function works?

The device_class only works with binary sensors and sensor.front_door_sensor_access_control is not a binary sensor.

I have one of those mono price sensors.

This is what my Template Binary Sensor looks like:

- platform: template
  sensors:
    deck_door:
      friendly_name: "Deck Door"
      value_template: "{{ is_state('sensor.deck_door_access_control', '22') }}"
      device_class: opening

I see that your template is formatted differently than mine, does your setup show as open/closed or on/off?

I have it setup under binary_sensor instead of just sensor.

For binary sensors you just need to define the true or on value and any other value will be defined as false or off.

For doors, the true/on value is when the door is opened (so when its 22).

Sorry it got formatted above weird for some reason. The full code would be:

binary_sensor:
  - platform: template
    sensors:
      deck_door:
        friendly_name: "Deck Door"
        value_template: "{{ is_state('sensor.deck_door_access_control', '22') }}"
        device_class: opening

I now understand, thank you for taking the time to explain it. Off I go to test this!

It doesn’t seem to work for me, I’m getting the following error when I restart
2017-11-21 20:37:03 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 115). Please check the docs at https://home-assistant.io/components/sensor/

I copied and pasted your template into my sensors.yaml and only changed the sensor name. I commented out everything else I had in it, I no clue as to why it errors out on me…

binary_sensor:
  - platform: template
    sensors:
      deck_door:
        friendly_name: "Deck Door"
        value_template: "{{ is_state('sensor.front_door_sensor_access_control', '22') }}"
        device_class: opening

I figured out my issue. I had forgotten I had a separate binary_sensors.yaml I created back sometime for another project, after inserting the new line into it, it is working as expected!!

Thanks for your help!!

No problem, glad you got it working!

I have a d’link DCH-Z110 door sensor wich also shows 23/22 value for closed/open door.
I added your code at the end of my config.yaml but I’m getting this error

2018-01-16 16:14:42 ERROR (SyncWorker_0) [homeassistant.util.yaml] mapping values are not allowed here
in “/home/homeassistant/.homeassistant/binary_sensors.yaml”, line 3, column 12
2018-01-16 16:14:42 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in “/home/homeassistant/.homeassistant/binary_sensors.yaml”, line 3, column 1

configuration.yaml

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
sensor: !include sensors.yaml
binary_sensor: !include binary_sensors.yaml

binary_sensors.yaml:

# Porta/finestra cucina
- platform: template
    sensors:
      prova1:
        friendly_name: "Porta Finestra Cucina"
        value_template: "{{ is_state('sensor.cucina_access_control', '22') }}"
        device_class: opening

entity data:

I got it. After some test I found a working config. thats what I put in my binary_sensors.yaml

 - platform: template
   sensors:
     porta_cucina:
       friendly_name: "Porta Finestra Cucina"
       device_class: opening
       value_template: >-
         {{  states('sensor.cucina_access_control')|float == 22 }}

1

Hope this can help

1 Like