Create custom binary sensor based on boolean

I am trying to integrate a motion sensor from a Control4 via Webhooks. I have an input boolean that is working great that C4 calls on a change of state of the motion detector. Now I want to be able to use that boolean in a binary sensor. I have read several threads on the matter example and I am not getting anywhere. I tried this based heavily on that thread:

binary_sensor:
  - platform: template
    sensors:
      master_bath_motion:
        value_template: "{{ is_state('input_boolean.master_bath_motion_state', 'on') }}"
        friendly_name: Master Bath Motion Sensor
        device_class: motion

This gives me the error

Invalid config for [binary_sensor]: required key not provided @ data['platform']. Got None. (See /config/configuration.yaml, line 13)

Which does me little good as the docs show basically nothing when it comes to configuring binary sensors. (No code or examples? So I am stuck. I am sure it’s something easy, but I am not experienced enough to know what.

In other news, I tried to follow what the one mod was saying about not needing a boolean input and after two days of Google, I don’t understand that at all.

if this is an included file, you need to remove binary_sensor:.

Ah, very good. I am slowly realizing this is not setup like old school config.d ideas where things are separated just for readability. I need to learn YAML too seemingly as 2 spaces = good. No or one space = bad in this particular case before - platform. What finally worked for any future Googlers.

  - platform: template
    sensors:
      master_bath_motion:
        value_template: "{{ is_state('input_boolean.master_bath_motion_state', 'on') }}"
        friendly_name: Master Bath Motion Sensor
        device_class: motion

Note this was placed in /config/binary_sensor.yaml which is a file I manually created.

I suspect my original code would have worked fine had it been in configuration.yaml.

yaml actually doesn’t care about spaces as long as it matches the previous indent level.

This

- foo: bar
  junk: stuff
  items:
  - item: 1
  - item: 2

is identical to

  - foo: bar
    junk: stuff
    items:
        - item: 1
        - item: 2

what it doesn’t like is when things aren’t lined up…


# THIS IS BAD DO NOT COPY
- foo: bar
    junk: stuff
      items:
       - item: 1
        - item: 2

1 Like

So had I removed an equivalent number of spaces (be it one or two - so long as consistent) from all other lines, it would have worked? Interesting.

The take away is that every item in a single field needs the same indent level

This is valid

some_field:
- stuff: result
  more_stuff: more_result
- stuff: result
  more_stuff: more_result
- stuff: result
  more_stuff: more_result
some_other_field:
  - stuff: result
    more_stuff: more_result
  - stuff: result
    more_stuff: more_result
  - stuff: result
    more_stuff: more_result

this is not

some_field:
- stuff: result
  more_stuff: more_result
  - stuff: result
    more_stuff: more_result
- stuff: result
  more_stuff: more_result
some_other_field:
    - stuff: result
      more_stuff: more_result
  - stuff: result
    more_stuff: more_result
  - stuff: result
    more_stuff: more_result
1 Like