Boolean, Switch, 3 way-switch

So far Ive worked with boolean types and switches for my automations because i either turn a relay on or off for things like patio lights, home lights etc.

Now I have a roller curtain wired up to an arduino that gets mqtt messages (via a wifi shield). The message tells the curtain to roll up or down (0 or 1):

The thing is I had to code the arduino to only roll up or down for 5 seconds on each command (0 or 1). So at present I dont use the switch but instead I go to developer and just send mqtt messages until the curtain reaches a desired position.

I know the best thing would be to add limit switches and Ill get around to it, but in the meantime I wanted to see if I could find a 3-way switch on HA. 1 position for up, 1 position for down and 1 position for stop.

Any suggestions?

That’s precisely what is provided by a cover. I use MQTT Cover to control my garage door.

1 Like

Ok so here is my configuration.yaml file. The first section MQTT Switches are normal switches. And then the second section MQTT Curtain is my curtain code that I took as sample from here:

I changed the name and command topic. I would need to change the payload_on & _off as well, right? But it would have to be _open, _close & _stop, right?

# MQTT Switches RPi2 - RPi3
switch:
  - platform: mqtt
    name: kompressor
    command_topic: "test_channel"
    payload_on: "komp-on"
    payload_off: "komp-off"
  - platform: mqtt
    name: solenoid
    command_topic: "test_channel"
    payload_on: "sole-on"
    payload_off: "sole-off"
  - platform: mqtt
    name: power_curtain
    command_topic: "curtainStatus"
    payload_on: "1"
    payload_off: "0"

#MQTT Curtain
cover:
  - platform: mqtt
    name: "power_curtain"
    command_topic: "curtainStatus"
    state_topic: "home-assistant/cover/state"
    availability_topic: "home-assistant/cover/availability"
    qos: 0
    retain: true
    payload_open: "OPEN"
    payload_close: "CLOSE"
    payload_stop: "STOP"
    state_open: "open"
    state_opening: "opening"
    state_closed: "closed"
    state_closing: "closing"
    payload_available: "online"
    payload_not_available: "offline"
    optimistic: false
    value_template: '{{ value.x }}'
    tilt_command_topic: 'home-assistant/cover/tilt'
    tilt_status_topic: 'home-assistant/cover/tilt-state'
    tilt_status_template: '{{ value_json["PWM"]["PWM1"] }}'
    tilt_min: 0
    tilt_max: 180
    tilt_closed_value: 70
    tilt_opened_value: 180
  • The MQTT payloads published by the arduino to indicate up is 1 and down is 0 but what number is used for stop?
  • What is the the MQTT topic used to show the curtain’s state? Is is curtainStatus?
  • What is the the MQTT topic used to control the curtain?

curtainStatus is the topic to which I post 1’s and 0’s to make it go up or down. So that would be the topic. As for up and down, its controlled via an L298N board where in1HIGH & in2LOW makes it spin in one direction and in1LOW & in2HIGH makes it go down. The stop is both low which i dont have a separate function for, but I could very easily make 2 the mqtt command to call the stop function.

It appears you will have to make changes before you can use MQTT Cover.

It needs two topics, one for publishing commands (commamd_topic) and the other for receiving status (state_topic). If you don’t have a state_topic then you will have to use optimistic mode. In this mode, after a command is sent, it expects no reply from the Arduino and assumes it was received.

Then you must specify the payloads that will be used to command the curtain to go up, down, and stop. If you use a state_topic, you also need to specify the payloads that represent the curtain’s current state.

Set the retain option to false (that’s the default).

Ok Ive done this:

groups.yaml
I commented out view and control because I was getting config error of those as invalid options.

garage_doors:
  name: Garage Doors
#. view: no
#  control: hidden
  icon: mdi:garage
  entities:
    - cover.single //These are named based on my doors, one is double wide the other is single.

customize.yaml

cover.single:
  device_class: garage
  friendly_name: Garage 1 #change this to whatever you want the door called in your HA UI

configuration.yaml
The switch part shows a switch I use that currently works, but Im replacing it for the cover you told me about.
The cover part is the cover code I added with the options I think I need.

# MQTT Switches RPi2 - RPi3
switch:
  - platform: mqtt
    name: kompressor
    command_topic: "test_channel"
    payload_on: "komp-on"
    payload_off: "komp-off"
  - platform: mqtt
    name: solenoid
    command_topic: "test_channel"
    payload_on: "sole-on"
    payload_off: "sole-off"
  - platform: mqtt
    name: power_curtain
    command_topic: "curtainCommand"
    payload_on: "1"
    payload_off: "0"
    
#MQTT Curtain
cover:
  - platform: mqtt
    name: "power_curtain"
    command_topic: "curtainCommand"
    state_topic: "curtainStatus"
    payload_open: "0"
    payload_close: "1"
    payload_stop: "2"
    state_open: "open"
    state_closed: "closed"
    optimistic: false
    retain: false

Currently Im getting this error:

Invalid config for [group]: Entity ID cover.single //These are named based on my doors, one is double wide the other is single. is an invalid entity id for dictionary value @ data['group']['garage_doors']['entities']. Got ['cover.single //These are named based on my doors, one is double wide the other is single.']. 

never mind, got it working…has “//” as comment instead of “#”

view is an option used by the old States UI and not by the Lovelace UI. It was deprecated several versions ago.

If you want to add a friendly_name or device_class to a cover entity, you can specify it directly in the entity’s configuration rather than in customize.yaml.

So does the cover component provide you with the “3-way switch” you requested?

Yes thank you, i got it working.

Glad to hear it works as per your request.

Please my mark my first post in this thread with the Solution tag. This will automatically place a check-mark next to the topic’s title which signals to other users that this topic has a solution. If others are also looking for a 3-way switch, it will help them find this answer.