Help With MQTT Switch (Resolved ty marthocoo)

Hi, i want to make a switch to turn on and off automatic mode on my MQTT thermostat

I tried a lots of configuration but nothing is working …

  • platform: mqtt
    name: “Mode Automatique”
    state_topic: “broadlink/4eae9f34ea34/temp_manual”
    command_topic: “broadlink/4eae9f34ea34/cmd/switch_to_auto”
    availability_topic: “broadlink/4eae9f34ea34/loop_mode”
    qos: 1
    payload_on: “1”
    payload_off: “0”
    payload_available: “1”
    payload_not_available: “0”
    retain: true

To send a command to my thermostat to switch the state:

  • /broadlink/4eae9f34ea34/cmd/switch_to_manual
  • /broadlink/4eae9f34ea34/cmd/switch_to_auto

Someone can help me !!

I don’t know whether there is anything else wrong but check the leading slash

Everything must match EXACTLY. Spelling, case, and slashes

Clarify something for me: what payload do you need to send to the topic /broadlink/4eae9f34ea34/cmd to put the thermostat into auto/manual? Is it “switch_to_manual” for manual mode and “switch_to_auto” for auto mode?

If so, then the setup is going to be a little complex because the command and state payloads are different, but it’s doable.

If it really is two different topics then I don’t think you can do it directly with an MQTT switch. You probably need a template switch to send each topic through a script.

Yes actually it’s 2 different command to change mode, I understand why it was not working if I need a scrip.You can help me put this in place, I do not have much experience with home-assistant, I start.

To switch to Auto mode i have to post this Topic:
/broadlink/4eae9f34ea34/cmd/switch_to_auto

To switch to Manual mode i have to post this Topic:
/broadlink/4eae9f34ea34/cmd/switch_to_manual

Also i have another issue someone can look at it plz :slight_smile:

*Sorry for my english i use google translate to help me :stuck_out_tongue:

Ok again to clarify: the topic is “/broadlink/4eae9f34ea34/cmd” and the payload is “switch_to_auto” for auto and “switch_to_manual” for manual?

Yes that’s right, if i want to know if the state have switch correctly to Auto i have to look at this topic:
broadlink/4eae9f34ea34/loop_mode If it return 1 im in auto mode if 0 im in manual mode

Maybe this topic ll switch to 1 if im in Manal mode im at work i can’t test:
broadlink/4eae9f34ea34/temp_manual

Send this topic to switch to Auto:
broadlink/4eae9f34ea34/cmd/switch_to_auto

Send this topic to switch to Manual
broadlink/4eae9f34ea34/cmd/switch_to_manual

OK then here’s what to do.

First, create a binary sensor by pasting this under binary_sensor: in configuration.yaml:

- platform: mqtt
  name: "Furnace Auto Mode"
  state_topic: "/broadlink/4eae9f34ea34/loop_mode"
  payload_on: "1"
  payload_off: "0"

Second, paste this under switch: in configuration.yaml:

- platform: template
  switches:
    furnace_auto:
      value_template: "{{ is_state('binary_sensor.furnace_auto_mode', 'on') }}"
      friendly_name: "Furnace Auto Mode"
      turn_on:
        service: mqtt.publish
        data:
          topic: "/broadlink/4eae9f34ea34/cmd"
          payload: "switch_to_auto"
      turn_off:
        service: mqtt.publish
        data:
          topic: "/broadlink/4eae9f34ea34/cmd"
          payload: "switch_to_manual"
      icon_template: >-
        {% if is_state('binary_sensor.furnace_auto_mode', 'on') %}
          mdi:brightness-auto
        {% else %}
          mdi:brightness-5
        {% endif %}

Now restart Home Assistant. If you haven’t set a default_view, you should now have a switch in your frontend called “Furnace Auto Mode” that is ON when the furnace is in Auto mode and OFF when in Manual mode. If there are any errors that come up in the Home Assistant log after you restart (or HA fails to load), paste the errors here and we can troubleshoot.

Ty for your help, When im turning the switch to on i have notification: Turned on Furnace Auto Mode but its turn off after 1 sec, if i send the command to the topic manually the switch state change. I got this error in my screen when im switching state maybe the publish was not working i ll look into it.

Exception in thread Thread-1:
Traceback (most recent call last):
File “/usr/lib/python2.7/threading.py”, line 801, in __bootstrap_inner
self.run()
File “/usr/lib/python2.7/threading.py”, line 754, in run
self.__target(*self.__args, **self.__kwargs)
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 2650, in _thread_main
self.loop_forever(retry_first_connection=True)
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 1481, in loop_forever
rc = self.loop(timeout, max_packets)
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 1003, in loop
rc = self.loop_read(max_packets)
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 1284, in loop_read
rc = self._packet_read()
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 1849, in _packet_read
rc = self._packet_handle()
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 2305, in _packet_handle
return self._handle_publish()
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 2500, in _handle_publish
self._handle_on_message(message)
File “/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py”, line 2647, in _handle_on_message
self.on_message(self, self._userdata, message)
File “broadlink-thermostat.py”, line 150, in on_message
command = cmd[4]
IndexError: list index out of range

Edit: I added a / after cmd
topic: “/broadlink/4eae9f34ea34/cmd/”
payload: “switch_to_auto”

Now i see the command in the console but the state doesnt change, my script is set to refresh at 3s maybe its to slow

Edit: I changed the refresh rate of my script but still have the same problem, the switch return to the current state after switching. I see on my screen that a topic was send but its not changing the state of the furnace

I tested different config and its working with this !

  • platform: template
    switches:
    furnace_auto:
    value_template: “{{ is_state(‘binary_sensor.furnace_auto_mode’, ‘on’) }}”
    friendly_name: “Furnace Auto Mode”
    turn_on:
    service: mqtt.publish
    data:
    topic: “/broadlink/4eae9f34ea34/cmd/switch_to_auto”
    payload: “”
    turn_off:
    service: mqtt.publish
    data:
    topic: “/broadlink/4eae9f34ea34/cmd/switch_to_manual”
    payload: “”
    icon_template: >-
    {% if is_state(‘binary_sensor.furnace_auto_mode’, ‘on’) %}
    mdi:brightness-auto
    {% else %}
    mdi:brightness-5
    {% endif %}

I also had problems with my other sensors, I did not use binary_sensor, the state was 1 and 0 thank you Ty vm for you help its really apreciated !

1 Like

Oh ok! I’m sorry I misunderstood your topic/payload, didn’t know that you needed an empty payload! Glad it’s working!