Binary sensor does not trigger device

If not already sorted, the following work for me. Should be editable to help suit your needs.

(1st post. Excuse the formatting. Not up-to-speed with quoting stuff.)

binary_sensor.yaml:

 - platform: mqtt
  name: "Shed Door"
  state_topic: "rfbridge/tele/RESULT"
  value_template: '{{value_json.RfReceived.Data}}'    
  payload_on: "4D730A" # open
  payload_off: "4D730E" # closed
  device_class: door
  qos: 1

Preformatted text

automations.yaml:

- id: '1598780714813'
  alias: Shed Door CLOSED
  description: ''
  trigger:
  - entity_id: binary_sensor.shed_door
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      message: The shed door is closed
    service: notify.mobile_app_oneplus_a5000
  - data:
      entity_id: media_player.living_room_speaker
      message: shed door CLOSED
    service: tts.google_say
  mode: single
- id: '1598780714814'
  alias: Shed Door OPEN
  description: ''
  trigger:
  - entity_id: binary_sensor.shed_door
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      message: The shed door is OPEN
    service: notify.mobile_app_oneplus_a5000
  - data:
      entity_id: media_player.living_room_speaker
      message: shed door OPEN
    service: tts.google_say
  mode: single

The formatting still isnā€™t correct.

Yeah. But the code is rightā€¦ :slight_smile:

Thatā€™s betterā€¦ :slightly_smiling_face:

Yeah he PMā€™D me too.
I know how frustrating doing something for the first time can be especially when you donā€™t feel you are making any progress.
I hope he has some light at the end of that tunnel.

Back to mqtt, why is it so different (yaml syntax wise) from everything else ?
We had tink, Tom and me and we were bumbling fools (no surprise for me, but Tom and Tink ???) itā€™s a bit ā€˜differentā€™
Thinking about it, Iā€™m not sure what the ā€˜normalā€™ sensors: header key is for as it does look redundant but repeating - platform: mqtt, seems downright stupid
I think a degree of harmonisation across platforms is required.
What do you think about a WTH ?
:smiley:

Well, thatā€™s annoying, getting shut off for replying too many times. I actually had to wait an hour this morning before I could post. Anyway, hereā€™s where we stand - after many different config attempts, the binary sensor still does not work. The messages get sent by the rf-wifi bridge but nothing ever happens in hass. Iā€™ve monitored the state of the device while opening and closing the door, it never changes (and I know it changes state almost in real-time as Iā€™ve tried it with other devices.) For the hell of it, and to reset, I went back to using MQTT. MQTT works fine to sound the alarm when the door has been open for a set period of time, I just canā€™t figure out how to preempt the alarm if the door is closed before the set time elapses. I have a couple other binary sensors (water detector and pir detector) that I may mess with but that would break existing automations that actually work, so Iā€™m hesitant. Thanks to all, by the way, your efforts and ideas are appreciated!

Did you try the latest code for the binary sensor using the correct topic and payloads?

Iā€™m not sure what you mean here. in your automation you are turning on a switch. how are you doing that differently by ā€œusing MQTTā€?

Yes, I did try the latest, but that reply was where I hit 20 and couldnā€™t respond.

When I set the automation up with mqtt as the trigger, the alarm goes off when I open the door.

- id: '1598911158887'
  alias: freezer door open too long
  description: freezer door open too long
  trigger:
  - payload: 'ON'
    platform: mqtt
    topic: /tele/rf_wifi_bridgeB2EB97/motion3
  condition: []
  action:
  - device_id: 917e9ebbae3a44148d8716f7faecae93
    domain: switch
    entity_id: switch.water_detector_alarm_switch
    type: turn_on
  mode: single

OK, then Iā€™m not sure why yours didnā€™t work.

As I said in my PM that I set up a binary sensor in my config using:

binary_sensor:
  - platform: mqtt
    name: "freezer door"
    state_topic: /tele/rf_wifi_bridgeB2EB97/motion3
    payload_on: 'ON'
    payload_off: 'OFF'
    device_class: door

and when I publish ON & OFF to that topic the binary sensor changed to on & off just as expected. So you must be doing something wrong.

Especially since you are using the exact same topic and payload in your trigger. So it should work in the binary sensor as well.

Actually itā€™s not that MQTT is different. Itā€™s the template stuff (binary, non-binary, etc) that is different from everything else.

Whenever you code multiples of any other thing in HA (fans, covers, lights, switches, etc) that is not a template you always have a main header and each item is listed individually with its own ā€œ- platform:ā€ line.

Iā€™m not sure why the template platform syntax is different.

1 Like

Progress! Now the state changes when I open and close the door, so the binary_sensor part seems to be working. (I did exactly the same as Iā€™ve done before in testing it, so no idea why, but happy for it at any rate.) The automation still doesnā€™t work though.

- id: '1598911158887'
  alias: freezer door open too long
  description: freezer door open too long
  trigger:
  - entity_id: binary_sensor.freezer_door
    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

Seems pretty simple and straightforward, and yet it doesnā€™t work. If this is outside the scope of this post I can repost under a more descriptive or appropriate topicā€¦

Note - when I execute the automation using the ā€œexecuteā€ link in automations, the alarm goes off. Not sure if that means anything but thought it worth mentioning for those of you who understand this stuff far better than I.

Because itā€™s using incorrect values in its State Trigger. They should be lowercase on and off not uppercase ON and OFF.

Yes, itā€™s meaningful. Youā€™ve confirmed the action is functional and the problem is the trigger. When you execute an automation manually, it skips the trigger and condition and just runs the action. So you successfully exercised the action, which indicates the automationā€™s problem is its trigger.

That fixed it, and thanks for the explanation, makes sense now. The automation now works as desired. I was thinking about possibly having an automation to turn it off, but itā€™s kinda like water in the basement - I want the alarm to sound until someone (me) does something about it. I lost about $250.00 worth of food because some idiot (me again) did not make sure the freezer door was closed all the way.

THANKS TO ALL!

No worries, we all make mistakes and you only really have it bed in if thereā€™s a little blood and bruising in getting there.
I bet you have learnt a lot (I know I did, about mqtt) and that will stand you in good stead going forward.
Good luck

Remember to mark one of the posts as your solution, it helps others searching the forum. Usually you mark the post that helped you the most in finding an answer. Iā€™d pick one of finityā€™s

Since I was changing things a lot yesterday and had turned the automation on and off a few times, I just tested it to make sure that turning the automation off would have no effect on the binary sensor, and sure enough, it doesnā€™t. I turned the automation off and opened the door, and the binary sensor changed state, as expected. It certainly would not make sense for the automation to affect the binary sensor, but I just wanted to make sure I hadnā€™t done something stupid yesterday.

This topic is about MQTT sensors and really helpful at that, but I was thinking about something else when I read your problem.
If you want to guard your food from spoiling in the freezer, did you consider monitoring its power consumption using a smart plug? My freezer has a very regular duty cycle. If the on-cycle is longer than 40 minutes I know the door is open or something else is wrong. If the off-cycle is longer than an hour, thereā€™s something wrong with the power. I have automations that check both.
A door switch is faster to detect an open door, but your food wonā€™t spoil instantaneously. A door switch will change the appearance of your freezer and could have reliability problems. Will the sensor trigger if the door is only slightly open?

image