Help - Proper format of sensors.yaml file

Hello everyone,
Can you please help me solve this riddle i’ve been battling all weekend?

If i use following format in my sensors.yaml file everything is working fine

platform: template
sensors:
  front_yard_motion_sensor_battery:
    friendly_name: Front Yard Motion Sensor Battery Level
    unit_of_measurement: '%'
    value_template: "{{ state_attr('zwave.zooz_zse29_outdoor_motion_sensor_2', 'battery_level') }}"
    device_class: battery

binary_sensor.yaml:

platform: template
sensors:
  front_yard_motion_sensor:
    friendly_name: "Front Yard Motion Sensor"
    device_class: motion
    value_template: "{{ is_state('sensor.front_yard_motion_sensor_burglar_2', '8') }}"

if i try to change it to:

- platform: template
  sensors:
    front_yard_motion_sensor_battery:
      friendly_name: Front Yard Motion Sensor Battery Level
      unit_of_measurement: '%'
      value_template: "{{ state_attr('zwave.zooz_zse29_outdoor_motion_sensor_2', 'battery_level') }}"
      device_class: battery

My Zwave network does not comes up & all zwave devices are in unkown state. If i revert the format back and restart HA, everything is back to normal and working.

Can you please tell me what i am doing wrong? I am a novice HA user & trying to add more sensors/devices & it seems i have to use "- platform: " name format for additional devices.

Also can somebody explain to me if its better to use one big file for all my sensors or start using folder called sensors and individual file for each sensor/device (Pros and Cons)? Or if you could point me to documentation where his is explain. I was not able to find it.
Thank you very much!

also, strangely, when i add following entry in my configuration.yaml file my Zwave network dies.

weather:
  - platform: darksky
    api_key: !mysecretkey
    mode: daily

I am sure i am doing something wrong, but no clue what. Why this entry for darkSky would mess up with my zwave network ?

what errors are you getting in the home-assistant.log file found in your config directory?

I do not see any errors in the logs and HA comes up.

are there any errors in the ozw_log.txt when it’s not working?

I assume you’re using an include, with a separate sensors.yaml? If so, remove “sensors:” from the config. I.E.

`platform: template
 front_yard_motion_sensor_battery:
   friendly_name: Front Yard Motion Sensor Battery Level
   unit_of_measurement: '%'
   value_template: "{{ state_attr('zwave.zooz_zse29_outdoor_motion_sensor_2', 'battery_level') }}"
   device_class: battery`

btw, spaces and indentation matter.

What’s your configuration.yaml look like?

Hi,
here is my configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123
# Text to speech
tts:
  - platform: google_translate
#zone: !include zones.yaml
discovery:
#  enable:
#    - philips_hue
# wemo: Example configuration.yaml entry with automatic discovery enabled (by explicitly setting the discovery configuration item)
wemo:
  discovery: false
  static:
    - 192.168.110.24
    - 192.168.110.25
    - 192.168.110.29
    - 192.168.110.27
    - 192.168.110.28
tplink:
  discovery: true
 # light:
 #   - host: 
 #   - host:
 # switch:
 #   - host: 192.168.110.22
 #   - host: 192.168.110.13
 # dimmer:
 #   - host: 
 #   - host: 
solaredge:
  api_key: !mykey
  site_id: 111111
# Roomba
vacuum:
  - platform: roomba
    host: 192.168.110.6
    name: Rosie
    username:  username
    password: :1:1511628462:
#Shield
cast:
  media_player:
    - host: 192.168.10.38
#InfluxDB
influxdb:
  host: 192.168.110.10
  port: 8086
# uncomment if you used a password
#  username: admin  
#  password: !secret influxdb_password
  database: home_assistant
  default_measurement: state
# exclude stuff that is pointless to log
  exclude: 
    domains:
      - group 
    entities:
      - sensor.other_junk_you_dont_care_about
#device:
 # config_path: /srv/homeassistant/lib/python3.6/site-packages/python_openzwave/ozw_config
#  usb_path: /dev/ttyACM1
#  device_config: !include zwave_device_config.yaml
geo_location:
  - platform: usgs_earthquakes_feed
    feed_type: 'past_hour_m25_earthquakes'
# Z-Wave
zwave:
  usb_path: /dev/serial/by-id/usb-0658_0200-if00
  network_key: "0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10"
#Panel Custom
panel_custom:
  - name: zwavegraph2
    sidebar_title: Z-Wave Graph
    sidebar_icon: mdi:access-point-network
    url_path: zwave
# System health
system_health:
timer:
    outside:
      duration: '00:05:00'
# DarkSky - Weather
#weather:
#  - platform: darksky
#    api_key: 39e1176c3820cde86ceb89094521c0f0
#    mode: daily
sensor: !include sensors.yaml
binary_sensor: !include binary_sensor.yaml
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

Okay, look at my first post above. You need to remove the “sensors:” from your sensors.yaml, it’s redundant.

thank you, but when I make that change and change my binary sensor.yaml to

platform: template
front_yard_motion_sensor:
  friendly_name: "Front Yard Motion Sensor"
  device_class: motion
  value_template: "{{ is_state('sensor.front_yard_motion_sensor_burglar_2', '8') }}"

i get an error when i do the configuration validation:

Invalid config for [sensor.template]: [front_yard_motion_sensor_battery] is an invalid option for [sensor.template]. Check: sensor.template->front_yard_motion_sensor_battery. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/template/
Invalid config for [binary_sensor.template]: [front_yard_motion_sensor] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->front_yard_motion_sensor. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/template/

Eh, I think I was wrong. For a template sensor you do need the sensors. Try this:

platform: template
sensors:
  front_yard_motion_sensor:
    friendly_name: "Front Yard Motion Sensor"
    device_class: motion
    value_template: "{{ is_state('sensor.front_yard_motion_sensor_burglar_2', '8') }}"

And not sure you can have a template sensor as a binary sensor, if that’s what you’re trying. Should just be a sensor

I think so & that one is working. ie when motion is detected the value changes from 0 to 8 and my automation is working fine.

Now, for whatever reason, everything seems to be working. Hopefully it stays this way but i wish i cloud explain why.

1 Like

no that’s wrong.

And that’s wrong too.

It’s great to want to help others since that is the main thrust of this forum but you really have to make sure that you aren’t giving out wrong information. It just confuses people even more.

Read the whole thread. I corrected myself, and learned something too.

I appreciate this forum very much.

Can somebody explain to me if its better to use one big file for all my sensors or start using folder called sensors and create individual file for each sensor/device (Pros and Cons)? Or if you could point me to documentation where his is explained so I can understand it better. I was not able to find it.

Breaking your configuration up into multiple files makes it easier to maintain, because you can quickly get to what you want to modify. Also, if you’re using an include directory, then you don’t have to constantly update a master file, you just create a new file with the information you need and restart, and it’ll be included.

The downside is that it also makes it more complex. As you found out, there are some subtleties with how you use included files that aren’t completely obvious.

I for one split up my configuration.yaml into sub-files for each device type (sensors, binary_sensors, alerts, groups, input_selects, input_booleans, lights, notify, scenes, sensors, switches, zones). The only include directories I have are around automations, so I can easily drop a new automation in the directory and just re-load those. I wouldn’t personally recommend breaking sensors into a bunch of sub-files.

1 Like

I tend to use packages where everything… templates, sensors, automations related to one component all live… There’s really no best way, only what you want and what is most manageable for you

You can go through some of these and see which you prefer.