Cover state based on Door/Window sensor (Garage door - Sonoff SV with Xiaomi Door Sensor)

Hi guys,

Not sure how to ask this properly.

I have a simple garage door, which I control with RF button. One button that does everything - opens, closes, pauses garage door. I have Xiaomi Door/Windows sensor which shows me the status of the garage door - whether it is closed or not.

I flashed Sonoff SV with Tasmota and it works as expected, the question is - is it possible to add door sensor state into my cover switch?

This is what I have:
image
I want to have only one arrow up or down available based on the state of Xiaomi sensor. I understand that it doesn’t make a big sense as all actions (up, down or stop) are basically the same, but just to make it look nicer.

My garage cover switch:

- platform: mqtt
  name: "Sonoff SV Garage"
  state_topic: "cmnd/garage/STATE"
  command_topic: "cmnd/garage/POWER"
  payload_open: "ON"
  payload_close: "ON"
  payload_stop: "ON"
  state_open: "ON"
  state_closed: "OFF"
  optimistic: false

Maybe it’s possible to make state_open and state_closed to read the state of the sensor somehow?

Yes, you can do something like this:

Change this:

  state_topic: "cmnd/garage/STATE"

to another topic of your choice:

  state_topic: "xiaomi_sensor/garage/STATE"

Create an automation that is triggered by the Xiaomi sensor and publishes its state value to xiaomi_sensor/garage/STATE.

alias: example
trigger:
- platform: state
  entity_id: binary_sensor.xiaomi_sensor
action:
- service: mqtt.publish
  data:
    topic: xiaomi_sensor/garage/STATE
    payload_template: "{{ trigger.to_state.state | upper }}"
    retain: true