Another sensor.yaml question

I am embarrassed to be asking this question, having tried for weeks to get things to work. But despite all my reading and trialling I am still failing and get nothing but errors referring to lines in the sensor.yaml file.

This all started around the time when I was attempting to connect a reed switch to a GPIO pin on my Raspberry Pi and interface it to HA (see below reference to ReedSwitch). I had everything in my configuration.yaml file but for some weird reason the reed switch would not show up in HA or even developer tools? So far I’ve had reasonable success in setting up various sensors etc, but this has me stumped?

So here goes my search for help…

In my configuration.yaml I have the obligatory:

sensor: !include sensor.yaml

And in my sensor.yaml file I have the following…

# Separate yaml file for sensors

# Reed Switch Sensor
binary_sensor:
  - platform: rpi_gpio
    unique_id: "studiodoor"
    invert_logic: true
    ports:
      24: ReedSwitch

# Temperature Sensors
sensor:
  - platform: onewire
    names:
      28-02131b13f9aa: Outside_Temp
      28-02131b3fdeaa: Inside_Temp

sensor:
  - platform: command_line
    name: "CPU Temperature"
    command: "cat /sys/class/thermal/thermal_zone0/temp"
 # If errors occur, make sure configuration file is encoded as UTF-8
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }'

# MQTT Sensors

#binary_sensor:
  - platform: mqtt
    name: "AC Status"
    state_topic: "GregoInc1/AirCon/Status"
    unique_id: "acstat"
    payload_on: "1"
    payload_off: "0"

#sensor:
  - platform: mqtt
    name: "ESP Outside Temp"
    state_topic: "GregoInc1/Temp2/Temp"
    unique_id: "espouttemp"

I have no doubt the answer to my issues will be a simple one… or maybe I just getting too old for this stuff :yum:

Remove all sensor: line in the sensor.yaml file. It’s not needed.

sensor:

binary_sensor should not be in the sensor.yaml file. It’s an integration on it’s on. Place it in the configuration.yaml file.

Hi Duceduc,

I made the changes and now I receive the following errors…

2021-03-05 14:12:39 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] mapping values are not allowed here
in "/config/sensor.yaml", line 20, column 11
2021-03-05 14:12:39 ERROR (MainThread) [homeassistant.bootstrap] Failed to parse configuration.yaml: mapping values are not allowed here
in "/config/sensor.yaml", line 20, column 11. Activating safe mode

Here is the revised sensor.yaml file…

# Separate yaml file for sensors

# Reed Switch Sensor
#binary_sensor:
#  - platform: rpi_gpio
#    unique_id: "studiodoor"
#    invert_logic: true
#    ports:
#      24: ReedSwitch

# Temperature Sensors

  - platform: onewire
    names:
      28-02131b13f9aa: Outside_Temp
      28-02131b3fdeaa: Inside_Temp

  - platform: command_line
      name: "CPU-Temp"
      command: "cat /sys/class/thermal/thermal_zone0/temp"
      # If errors occur, make sure configuration file is encoded as UTF-8
      unit_of_measurement: "°C"
      value_template: '{{ value | multiply(0.001) | round(1) }'

# MQTT Sensors

#binary_sensor:
#  - platform: mqtt
#    name: "AC Status"
#    state_topic: "GregoInc1/AirCon/Status"
#    unique_id: "acstat"
#    payload_on: "1"
#    payload_off: "0"

# MQTT Interface
#mqtt:
#  broker: 192.168.0.27
#  port: 1883
#  keepalive: 30

  - platform: mqtt
      name: "ESP Outside Temp"
      state_topic: "GregoInc1/Temp2/Temp"
      unique_id: "espouttemp"

You’ll note I commented out the binary_sensor lines.

Also, here is my configuration.yaml file…


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensor.yaml

# Relay Control
switch:
  - platform: rpi_gpio
    invert_logic: true
    ports:
      17: FanRelay
      27: DamperRelay
      22: SpareRelay

# Reed Switch Sensor
binary_sensor:
  - platform: rpi_gpio
    unique_id: "studiodoor"
    invert_logic: true
    ports:
      24: ReedSwitch

# MQTT Interface
mqtt:
  broker: 192.168.0.27
  port: 1883
  keepalive: 30

binary_sensor:
  - platform: mqtt
    name: "AC Status"
    state_topic: "GregoInc1/AirCon/Status"
    unique_id: "acstat"
    payload_on: "1"
    payload_off: "0"

In your sensor.yaml, your spacing is off and you forgot one more } for the vaule_template:
This should pass validation.

  - platform: onewire
    names:
      28-02131b13f9aa: Outside_Temp
      28-02131b3fdeaa: Inside_Temp

  - platform: command_line
    name: "CPU-Temp"
    command: "cat /sys/class/thermal/thermal_zone0/temp"
      # If errors occur, make sure configuration file is encoded as UTF-8
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'


  - platform: mqtt
    name: "ESP Outside Temp"
    state_topic: "GregoInc1/Temp2/Temp"
    unique_id: "espouttemp"

There should not be ANY indentation…

- platform: onewire
  names:
    28-02131b13f9aa: Outside_Temp
    28-02131b3fdeaa: Inside_Temp
- platform: command_line
  name: "CPU-Temp"
  command: "cat /sys/class/thermal/thermal_zone0/temp"
    # If errors occur, make sure configuration file is encoded as UTF-8
  unit_of_measurement: "°C"
  value_template: '{{ value | multiply(0.001) | round(1) }}'
- platform: mqtt
    name: "ESP Outside Temp"
    state_topic: "GregoInc1/Temp2/Temp"
    unique_id: "espouttemp"

Thanks Duceduc and David, much appreciated, will try that now and see what happens.

Lol duh, already answered. Should’ve kept scrolling, sorry!

Looking good so far… now I just need to get the binary sensor working… but perhaps that’s a separate post :wink:

Binary sensors are a different integration from sensors, that was why they couldn’t be in your sensors file. To add the binary sensor just add it to your configuration.yaml like this:

# Reed Switch Sensor
binary_sensor:
  - platform: rpi_gpio
    unique_id: "studiodoor"
    invert_logic: true
    ports:
      24: ReedSwitch

Or put all of them in a separate file as well if you want by adding this to configuration.yaml

binary_sensor: !include binary_sensor.yaml

And then this in binary_sensor.yaml:

  - platform: rpi_gpio
    unique_id: "studiodoor"
    invert_logic: true
    ports:
      24: ReedSwitch
1 Like

Hi Mike,

Thanks, made the changes as suggested. Unfortunately the reed switch still doesn’t show up anywhere i.e. not in developer tools or anywhere else?

Here’s the code I used in the binary_sensor.yaml file.

- platform: rpi_gpio
  invert_logic: true
  ports:
    24: ReedSwitch

HA did complain about the unique_id, so I removed it.

Not sure why it’s still not working?

Wait, is it actually a binary sensor or is it a switch? I’m looking at the doc for rpi_gpio and it looks like the integration supports the binary_sensor, cover and switch platforms. I had assumed it was binary sensor based on what you put up top but I’m realizing the name says switch.

The configuration looks correct for a binary sensor based on the doc. But if you’re expecting a switch then that’s a different platform, you need to drop that configuration under switch: in your configuration.yaml.

Otherwise not sure since the config looks correct. But it also depends on an external device so it may not be a config problem. I’m not really familiar with that particular integration so may be better off with a separate post in that case.

1 Like

I think I solved it… but dont know how? It suddenly decided to show up in the Developer Tools. I’ll do some more testing and see what happens. Thanks again for the help Mike.

1 Like