Control ESPhome cover with mqtt

Hi

I have a ESP32 setup and it is working great with home assistant.

My problem is I want to control the cover using mqtt.
I have it setup and connected to my mqtt server.

ESPhome config:

output:
  - platform: gpio
    id: 'win_1'
    pin: GPIO12
  - platform: gpio
    id: 'win_2'
    pin: GPIO14
    
switch:
  - platform: output
    name: 'win_1'
    output: 'win_1'
    id: win1
  - platform: output
    name: 'win_2'
    output: 'win_2'
    id: win2

cover:
  - platform: template
    name: 'Kælder vindue'
    id: win_open
    optimistic: true
    open_action:
      - switch.turn_off: win2
      - switch.turn_on: win1
    close_action:
      - switch.turn_off: win1
      - switch.turn_on: win2
    stop_action:
      - switch.turn_off: win1
      - switch.turn_off: win2

Picture from MQTT Explorer:
image

Can any of you out there help me with a topic and payload ?

Martin

MQTT Explorer gives that info. on the top right

image

I know but if I set …/state to open nothing happens ?

I am looking for the topic that I can change to “open” (or something like that) to open the cover :slight_smile:

Looking at you template you need to set the switches and not the status. Since thats just a status and cannot be set

I have tried that as well
image

But me cover is still closed ?

Why do you want to use mqtt directly rather than using home assistant?

If you have discovery set up a cover entity will be generated in HA and activated by the usual ha methods.

I have it setup in HA but I have a small automation another place that requires mqtt :confused:

I suggest listening to the mqtt messages that ha generates when it opens and closes the cover.

I have found it :slight_smile:

Topic: “vindue-toilet/switch/win_1/command” Payload: ON/OFF
Topic: “vindue-toilet/switch/win_2/command” Payload: ON/OFF

It works now :slight_smile:
Thx for guidance

3 Likes