Please help create binary sensor

Good day.

Can anyone help me create a binary.sensor?

I have a Sonoff mini flash firmware Tasmota. For which I separated the relay from Switch1. When I connect S1 and S2, the relay does not respond but the mini sends me the status of S1 and S2 to HA

MQT: stat/garage_door/RESULT = {"Switch1":{"Action":"ON"}}

and

MQT: stat/garage_door/RESULT = {"Switch1":{"Action":"OFF"}}

I was able to use this to control the boolean helper using automation.

But now I would like to make a binary_sensor helper instead.
I’ve been dominating HA since the morning and I just can’t find an easy solution.

I want to use the Sonoff mini to control the garage door.
Use S1 and S2 as “Closed” signals and relays as drive triggers.

Hello,
put in your configuration.yaml file the following code:

binary_sensor:
  - platform: mqtt
    name: "garage_door_switch"
    state_topic: 'stat/garage_door/RESULT'
    payload_on: '{"Switch1":{"Action":"ON"}}'
    payload_off: '{"Switch1":{"Action":"OFF"}}'

and restart Home assistant.
Then add in your front end GUI, a card that will implement the binary sensor with as entity name: binary_sensor.garage_door_switch
The code in the lovelace configuration file should look like this:

      - type: entity
        entity: binary_sensor.garage_door_switch
        name: Test binary sensor
        icon: mdi:light-switch
        state_color: true

You can change the names as you please and select other options for displaying the sensor (icon, color, text, …)
I have simulated it using the MQTT configuration menu which allow to send test messages


test_sensor

If the Sonoff device is flashed with Tasmota, have you considered using the Tasmota integration? It will automatically create all entities needed to represent the device.

Hello.

unfortunately this binary_sensor does not respond to the s1xs2 state. We are certainly able to change its sending status of configured messages. But not by the physical conductive connection of S1 and S2. I have also studied this mqtt binary_sensor in the documentation. Unsuccessfully.
I have an automation that can respond properly and switch boolean based on the S1xS2 I status.
Its basis is as follows:

'{{ trigger.payload_json["Switch1"]["Action"] == ''ON'' }}'
and
'{{ trigger.payload_json["Switch1"]["Action"] == ''OFF'' }}'

This can be switched by the boolean helper…
Thank you for your time.

Hello.

I use both integrations. In this case, I didn’t try the Switch1 integration in Tasmota.
Thank you for pointing it out.
This is where the status of switch ON and OFF…
Thank you