Input_boolean as binary_sensor?

Hello,

I have defined an input_boolean which is turned on/off by an automation.

  alias: Occupancy - Office Turn On
  trigger:
      platform: state
      entity_id: sensor.office_pir
      from: 'standby'
      to: 'motion detected'
  action:
      service: input_boolean.turn_on
      entity_id: input_boolean.office_occupancy
      
  alias: Occupancy - Office Turn Off After 30min
  trigger:
      platform: state
      entity_id: sensor.office_pir
      to: 'standby'
      for:
        minutes: 30
  action:
      service: input_boolean.turn_off
      entity_id: input_boolean.office_occupancy

I don’t like the look of the switch in the dashboard and wanted to know if I can change to a binary_sensor since the states are just on/off. I like that there is visual feedback when a binary sensor is on or off.

I’ve tried the template binary sensor examples and I can’t seem to get it to work, wondering if it’s possible.

platform: template
sensors:
  office_occupancy_on:
    value_template: '{{ states.input_boolean.office_occupancy.state }}'
    friendly_name: 'Office Occupancy'
    device_class: motion

platform: template
sensors:
  office_occupancy_on:
    value_template: '{{ is_state('input_boolean.office_occupancy', 'on') }}'
    friendly_name: 'Office Occupancy'
    device_class: motion

Thanks!

I wonder if this would work:

value_template: "{% if is_state('input_boolean.office_occupancy', 'on') %}on{% else %}off{% endif %}"

Make sure that your state is “on” and not “On” though and adjust the above as necessary for proper case.

1 Like

Thanks for your reply. It didn’t work.

2017-06-26 15:46:27 ERROR (MainThread) [homeassistant.config] Invalid config for [binary_sensor.template]: [vvalue_template] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->sensors->office_occupancy_on->vvalue_template. (See ?, line ?). Please check the docs at https://home-assistant.io/components/binary_sensor.template/

Please read the error and don’t complain just that it didn’t work.

Check your value_template under your sensor, as it appears to be misspelled as vvalue_template instead.

3 Likes

I wasn’t complaining I was simply telling @rpitera that his answer wasn’t working. But @pplucky you are correct, I had an extra character in the value_template, thanks for catching that.

After correcting I no longer get errors but the binary sensor is in an ‘off’ state while the input_boolean is in an ‘on’ state.

Edit:
I did a little more playing around and found the following code to work

platform: template
sensors:
  office_occupancy_on:
    friendly_name: Office Occupancy
    value_template: "{{ states.input_boolean.office_occupancy.state == 'on' }}"
    entity_id: input_boolean.office_occupancy
    device_class: occupancy
2 Likes

Slightly off topic but in the same vain.

I use the following template for my Presence Input_boolean to convert from an On/Off switch to Home/Away which works fine but I’m hoping to add to it. Is there a way for the template to pull in Zone Information ie: My wife is away but inside another zone, example the kids school?

- platform: template
  sensors:
    robb_home_away:
      value_template: "{% if is_state('input_boolean.robb_home', 'on') %}Home{% else %}Away{% endif %}"

It’s definitely a little off topic so you might want to start your own thread.

So you just want to show which zone you or your wife is in?

I just use the states of the device_tracker which is updated if the device tracker enters a defined zone.

So did my value template work as well? I just want to make sure in case I try this myself in some future use case.

Thanks.

@rpitera Nope, I couldn’t get your value template to work and ended up using this:

platform: template
sensors:
  office_occupancy_on:
    friendly_name: Office Occupancy
    value_template: "{{ states.input_boolean.office_occupancy.state == 'on' }}"
    entity_id: input_boolean.office_occupancy
    device_class: occupancy
3 Likes

OK, thanks! Good to know.

1 Like