Sensor vs Binary Sensor, Missing Binary Sensor

I can get the binary sensors to work, but when there is no binary sensor ID and ONLY sensor ID’s my code is not working.
This works.

- alias: Hall Way Light    
  trigger: 
    - platform: state
      entity_id: binary_sensor.aeotec_zwa005_trisensor_sensor_2
      to: 'on'
  action:
   - service: switch.turn_on
     entity_id: switch.ge_unknown_type_4952_id_3130_switch
     
     # OFF
- alias: Turn Hall Way #OFF 1 minutes after last movement
  trigger:
   - platform: state
     entity_id: binary_sensor.aeotec_zwa005_trisensor_sensor_2
     to: 'off'
     for:
      minutes: 1
      
  action:
    service: switch.turn_off
    entity_id: switch.ge_14288_duplex_receptacle_switch, switch.ge_14288_duplex_receptacle_switch_2, 
     switch.ge_unknown_type_4952_id_3130_switch

This does not work

- alias: Bathroom Fan
  trigger:
    - platform: state
      entity_id: sensor.ge_26931_smart_motion_switch_burglar_5 #<- This should be your motion sensor
      to: 'on'
  action:
   - service: switch.turn_on  #or light.turn_off
     entity_id: switch.ge_26931_smart_motion_switch_switch_5
        
                 #OFF
- alias: Bathroom Fan
  trigger:
    - platform: state
      entity_id: sensor.ge_26931_smart_motion_switch_burglar_5 #<- This should be your motion sensor
      to: 'off'
      for:
        minutes: 5
  action:
   - service: switch.turn_off  #or light.turn_off
     entity_id: switch.ge_26931_smart_motion_switch_switch_5 # or light.your_light # <- this should be your light entity_id

Check the state of sensor.ge_26931_smart_motion_switch_burglar_5 in the developer tools that you want to trigger from.

Its state may be “ON” or “TRUE” or something else - you need to match that test exactly in your trigger - binary sensors are a little more forgiving as the system knows they can only be on or off.

If you want to tease out a binary sensor from your sensor, you could use a binary template sensor

1 Like

As already mentioned a sensor is not on or off. The burglar sensor will have a variable integer number, depending on what event is being detected. The meaning of the values is explained in the docs, along with an example binary template.

Yes, in HA Overview page, I noticed it triggered “8” which is motion.
That was a good read, I will try it.

Thank you

Ok. Thank you, I believe I found what I was looking for from your link.

Thanks again

Hopefully, I can get that to work.

can I put this in the automations file?

I’m getting an error with this code.

binary_sensor:
  - platform: template
    sensors:
      something_here:
        friendly_name: "2nd BATHROOM FAN motion"
        delay_off:
          minutes: 2
        device_class: motion
        value_template: "{{ is_state('sensor.ge_26931_smart_motion_switch_burglar_5', '8') }}"

Error:
image

Also in config file

sensor:
  # Weather prediction
  - platform: yr
  - platform: random
  - platform: template
  # Motion
  #- plateform:  state

the sensors: and something here: statements seems redundant - remove it and try!

Also - is the value ‘8’ text or an integer? if an integer (number), you dont want quotes around it in your test.

Best is to test that logic in the template editor section of developer tools by removing the outer quotes from the value template formula and see if you get the true/false you are expecting evaluated from the formula

in which file did you place the code above?

in the configuration.yaml, automtions.yaml, sensors.yaml or binary_sensors.yaml?

no, they aren’t redundant.

those lines are required for a template binary sensor.

removing either of those will cause an error.

All states are strings. So the quotes are required or you will get an incorrect result from the template because ‘8’ (a string value of the state of the sensor) will never equal 8 (an integer).

Even at that it would cause the template to fail but it wouldn’t cause an error in the config checker.

no solution?

answer my question?

I mislead you slightly - lift from my config

I have it in configuration.yaml - place it either there or where your binary_sensor: section is

binary_sensor:
  - platform: template 
    sensors:
      ### Shower in progress sensor
      showering:
        friendly_name: Showering
        device_class: moisture
        value_template: >-
          {{ (states('sensor.humidity_158d0001e42369')|float - 4) > (states('sensor.bathroom_humidity_3')|float) }}

I did, still getting error.
image

config:

#Testing below this

binary_sensor:
  - platform: template
    sensor:
      Bathroom_Fan: 
        friendly_name: "2nd BATHROOM FAN motion"
        delay_off:
          minutes: 2
        value_template: "{{ is_state('sensor.ge_26931_smart_motion_switch_burglar_5', '8') }}"

The error is complaining that it expects something in a list int the sensors: block - you have the word sensor - add an s to the end.

Also - if still no joy, try making the title of the sensor lower case only ie bathroom_fan: not Bathroom_fan:

That did work, no more errors. The fan turns off after 15 seconds, I have it set to 2 min?

Thank you!

Wow!

you have three threads going about the same problem and had three people all give you the same answers and then told all three people that they fixed it.

please. please keep all of the questions about the same problem all in one thread. That way you don’t waste peoples time giving you answers you’ve already gotten somewhere else.

2 Likes

yea, that got out of hand a little.

What about the rest of it? The fan still does not turn off after 2 min?

I’m not even sure what you are trying to accomplish using a binary_sensor?

again, read the docs on the binary sensor. I don’t think the “delay_off” means what you think it means and the use of a binary_sensor is likely not what you want to be using.

Unless I’m not seeing something obvious…


I am using binary_sensor: template because this device does not put out the regular entity_id that says binary sensor so I have to create a template. 
Ex.
Regular Automation file

- alias: Turn on couch light when there is movement
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zwa005_trisensor_sensor_2
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.ge_14288_duplex_receptacle_switch, switch.ge_14288_duplex_receptacle_switch_2

vs config file where template is created

binary_sensor:
  - platform: template
    sensors:
      bathroom_fan_motion: 
        friendly_name: "second_ bathroom_ fan_ motion"
        device_class: motion
        delay_off:
          minutes: 2
        value_template: "{{ is_state('sensor.ge_26931_smart_motion_switch_burglar_5', '8')

But where are you using that binary sensor in any automation?