Binary sensor does not trigger device

I am trying to set up an automation for a freezer door so that if the door is open for more than a specified time, it will trigger an alarm, but if closed before that time, does not trigger the alarm. (The alarm device is already set up and working, it also goes off if a water sensor in the basement senses water.) I have it set up in config.yaml as follows:

binary_sensor:
      platform: mqtt
      state_topic: "/tele/rf_wifi_bridgeB2EB97/motion3"
      name: "freezer door"
      value_template:  '{{value_json.RfReceived.Data}}'
      payload_on: 'E6690A'
      payload_off: 'E6690E'
     device_class: Door

and in automations.yaml as

- id: '1598911158887'
  alias: freezer door open too long
  description: freezer door open too long
  trigger:
  - entity_id: binary_sensor.freezer_door
    for: 00:00:30
    from: 'OFF'
    platform: state
    to: 'ON'
  condition: []
  action:
  - device_id: 917e9ebbae3a44148d8716f7faecae93
    domain: switch
    entity_id: switch.water_detector_alarm_switch
    type: turn_on
  mode: single

I can get the alarm to go off on door opening for <>secs using mqtt but then the alarm goes off whether the door has been closed or not, so thatā€™s not useful. I canā€™t figure out a way, using mqtt, to keep it from alarming if the door has been closed before the timer expires. If I go to console on the Sonoff rf-wifi bridge, I can see the correct messages being sent on door open and close, so the problem seems to be in my code in hass. Iā€™ve found instances on youtube that do exactly what I want using the binary sensor method, so Iā€™ve replicated them exactly (as far as I can tell) yet they still donā€™t work.

Binary sensor states are lower case.

    from: 'off'
    platform: state
    to: 'on'
1 Like

Always look in Developer Tools -> States to see the actual states of entities, rather than the translated or human friendly state.

1 Like

Set them to lower case now (pretty sure Iā€™ve tried that as Iā€™ve seen it both ways, but for the sake of argument, lower case it is.)

Iā€™ve looked in ā€œDev Toolsā€ and the binary sensor for that has never changed state, and I can see that it is real time, seems this might be the root of my problem. Now, how to fix it?

From console on rf-wifi bridge, looks like correct messages are being sent.

13:23:13 RUL: RFRECEIVED#DATA=E6690A performs "publish2 /tele/rf_wifi_bridgeB2EB97/motion3 ON"
13:23:13 MQT: /tele/rf_wifi_bridgeB2EB97/motion3 = ON (retained)
13:23:25 MQT: tele/rf_wifi_bridgeB2EB97/RESULT = {"Time":"2020-09-03T13:23:25","RfReceived":{"Sync":14130,"Low":480,"High":1390,"Data":"E6690E","RfKey":"None"}}
13:23:25 RUL: RFRECEIVED#DATA=E6690E performs "publish2 /tele/rf_wifi_bridgeB2EB97/motion3 OFF"
13:23:25 MQT: /tele/rf_wifi_bridgeB2EB97/motion3 = OFF (retained)

Isnā€™t your spacing off ?

the code I pasted was generated by the gui editor, so I would think itā€™s correct, but Iā€™ve seen weirder things. Iā€™ll give it a try, thanks.

Ah !
Spawn of Beelzebub !
Nuff said
:rofl:

My mistake, that was hand-edited yaml, so it looks correct compared to what I saw, so I guess Iā€™m not sure if itā€™s correct or not?

Edit: ignore this, read finityā€™s post #19

Not sure myself (donā€™t use mqtt)
But, I would have gone with a full yaml compatible and human readable approach (say, and not tested etc.) : -

binary_sensor:
  platform: mqtt
    freezer_door:
      state_topic: "/tele/rf_wifi_bridgeB2EB97/motion3"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: 'E6690A'
      payload_off: 'E6690E'
      device_class: Door

And remember, only one binary sensor header, and one platform mqtt header too

Roger that, I only have one binary sensor Iā€™m dealing with right now but I do have others, so if I get this working thatā€™ll be useful info for when I add the other devices.

Okay, I did it in a rush and Iā€™m nowhere near a workstation, Iā€™ve edited it again.
Each sensor should list under its own key. freezer_door: in this case

Edit: we donā€™t get many seeding machine officianados on this forum

Iā€™ve corrected it as you suggest above, in doing a config check, I get

Error loading /config/configuration.yaml: mapping values are not allowed here
in ā€œ/config/configuration.yamlā€, line 41, column 17
which appears to be the colon at the end of the line of

freezer_door:

seeding machine? howā€™d you know that?

Me : No Idea !

@tom_l , @Tinkerer ???

Docs say:

binary_sensor:
  - platform: template
    sensors:
      sun_up:
        friendly_name: "Sun is up"

What you posted isnā€™t quite right, missing sensors:, I believe the class is door, not Door, and the topic is wrong :wink:

Try

binary_sensor:
  - platform: mqtt
    sensors:
      freezer_door:
        state_topic: tele/rf_wifi_bridgeB2EB97/motion3
        value_template: '{{value_json.RfReceived.Data}}'
        payload_on: 'E6690A'
        payload_off: 'E6690E'
        device_class: door

ok, so here is the corrected bit:

binary_sensor:
  - platform: mqtt
    sensors:    
      freezer_door:    
      state_topic: tele/rf_wifi_bridgeB2EB97/motion3
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: 'E6690A'
      payload_off: 'E6690E'
      device_class: door

on config check prior to reload, I get

 Invalid config for [binary_sensor.mqtt]: [sensors] is an invalid option for [binary_sensor.mqtt]. Check: binary_sensor.mqtt->sensors. (See ?, line ?). 

I did notice that the doc referenced says ā€œplatform: templateā€ so Iā€™m guessing that is a valid option for platofrm: template but not for platform: mqtt?

Edit: ignore this, read finityā€™s post #19

er !

(Iā€™m at a workstation now)
Apologies at forgetting the sensors: sub-header

My binary sensors (occupancy and edited highlights) : -

binary_sensor:
  - platform: template
    sensors:
      bs_occupancy_mutt:
        entity_id: device_tracker.life360_muttley, input_boolean.ib_occupancy_mutt_away
        value_template: "{{ is_state('device_tracker.life360_muttley', 'home') and is_state('input_boolean.ib_occupancy_mutt_away', 'off') }}"
        friendly_name: Mutt At Home
      bs_occupancy_mutt_sound:
        entity_id: sensor.s_occupancy_mutt_dist
        value_template: "{{ states('sensor.s_occupancy_mutt_dist') | float <= states('input_number.in_occupancy_near_sound') | float }}"
        friendly_name: Mutt Sound Zone
      bs_occupancy_mutt_light:
        entity_id: sensor.s_occupancy_mutt_dist
        value_template: "{{ states('sensor.s_occupancy_mutt_dist') | float <= states('input_number.in_occupancy_near_light') | float }}"
        friendly_name: Mutt Light Zone

Do you see how each sensor has itā€™s own header (key) ?
So it can be identified from the previous and the following.
The config checker, ā€˜sometimesā€™ highlights something just before or just after the actual offending bit of code.
Tinkā€™s offered example had indents ā€˜afterā€™ the sensor entity, yours doesnā€™t

OK, I tried that, but I am not using templates, correct? I now have a whole boatload of errors on config check about dictionaries and dictionary values. I can list them if thatā€™ll help. I am not a programmer by any means; Iā€™ve been doing network technician/engineer stuff since ~1995 so there are things I understand and things I donā€™t. Programming is one that I donā€™t, despite having tried countless times over the years. Iā€™ve seen how people do things using templates, but since I donā€™t ā€œgetā€ how they work, Iā€™ve avoided them.

Edit: ignore this, read finityā€™s post #19

Correct your platform would be mqtt instead
This was just an example, to show you the format and the required indenting.
Treat @Tinkerer 's as the definitive

You donā€™t need (or want as it will cause errors :wink:) the ā€œsensors:ā€ bit. Thatā€™s only for template binary sensors. mqtt binary sensors are defined individually.

I donā€™t know if youā€™ve tried this iteration yet but try this:

binary_sensor:
  - platform: mqtt
    name: "freezer_door"
    state_topic: tele/rf_wifi_bridgeB2EB97/motion3
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: 'E6690A'
    payload_off: 'E6690E'
    device_class: door

and here is how they are added more than once:

binary_sensor:
  - platform: mqtt
    name: "freezer_door"
    state_topic: tele/rf_wifi_bridgeB2EB97/motion3
    value_template: '{{value_json.RfReceived.Data}}'
    payload_on: 'E6690A'
    payload_off: 'E6690E'
    device_class: door
  - platform: mqtt
    name: "BI Livingroom Motion"
    state_topic: blue_iris/lr_cam/motion
    payload_on: "on"
    payload_off: "off"
    device_class: motion

Jethro Tull == Seeding Machine

(or rather inventor of ā€¦ )

1 Like