Mqtt and multiple states

Hi all,

I’m very new to mqtt :slight_smile:

I have been able to get my ceiling fan working using the Sonoff RF Bridge with Portisch firmware.

image

In my configuration.yaml i have the following:

mqtt:
  switch:
    - unique_id: camden_room_light
      name: "Cammy Room Light"
      command_topic: "cmnd/rf-bridge/Backlog"
      #availability_topic: "tele/rf-bridge/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"
      state_topic: "tele/rf-bridge/RESULT"
      payload_on: "rfraw AA B0 17 04 08 0118 00A0 0208 1F36 38081A08080808080808081A08 55; rfraw 0"
      payload_off: "rfraw AA B0 17 04 08 0122 00A0 01FE 1F36 3808081A080808080808081A08 55; rfraw 0"
      state_on: "rfraw AA B0 17 04 08 0118 00A0 0208 1F36 38081A08080808080808081A08 55"
      state_off: "rfraw AA B0 17 04 08 0122 00A0 01FE 1F36 3808081A080808080808081A08 55"
      optimistic: true
      retain: false
      qos: 2
      
    - unique_id: camden_room_fan_low
      name: "Cammy Room Fan Low"
      command_topic: "cmnd/rf-bridge/Backlog"
      #availability_topic: "tele/rf-bridge/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"
      state_topic: "tele/rf-bridge/RESULT"
      payload_on: "rfraw AA B0 17 04 08 010E 00AA 01F4 1F54 381A0808080808080808280A28 55; rfraw 0"
      payload_off: "rfraw AA B0 17 04 08 012C 00AA 0208 1F40 3808080808081A080808081A08 55; rfraw 0"
      state_on: "rfraw AA B0 17 04 08 010E 00AA 01F4 1F54 381A0808080808080808280A28 55"
      state_off: "rfraw AA B0 17 04 08 012C 00AA 0208 1F40 3808080808081A080808081A08 55"

      optimistic: true
      retain: false
      qos: 2
      
    - unique_id: camden_room_fan_medium
      name: "Cammy Room Fan Medium"
      command_topic: "cmnd/rf-bridge/Backlog"
      #availability_topic: "tele/rf-bridge/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"
      state_topic: "tele/rf-bridge/RESULT"
      payload_on: "rfraw AA B0 17 04 08 0122 00AA 0208 1F40 380808081A0808080808081A08 55; rfraw 0"
      payload_off: "rfraw AA B0 17 04 08 012C 00AA 0208 1F40 3808080808081A080808081A08 55; rfraw 0"
      state_on: "rfraw AA B0 17 04 08 0122 00AA 0208 1F40 380808081A0808080808081A08 55"
      state_off: "rfraw AA B0 17 04 08 012C 00AA 0208 1F40 3808080808081A080808081A08 55"
      optimistic: true
      retain: false
      qos: 2
      
    - unique_id: camden_room_fan_high
      name: "Cammy Room Fan High"
      command_topic: "cmnd/rf-bridge/Backlog"
      #availability_topic: "tele/rf-bridge/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"
      state_topic: "tele/rf-bridge/RESULT"
      payload_on: "rfraw AA B0 17 04 08 0122 00A0 0208 1F36 38080808081A08080808081A08 55; rfraw 0"
      payload_off: "rfraw AA B0 17 04 08 012C 00AA 0208 1F40 3808080808081A080808081A08 55; rfraw 0"
      state_on: "rfraw AA B0 17 04 08 0122 00A0 0208 1F36 38080808081A08080808081A08 55"
      state_off: "rfraw AA B0 17 04 08 012C 00AA 0208 1F40 3808080808081A080808081A08 55"
      optimistic: true
      retain: false
      qos: 2

The problems I am facing are:

  1. Switching the fan from low to medium or high etc… the icons don’t recognize the change. Is there a way to have multiple state values?

  2. For the dashboard controls - how would i make that a toggle rather than 2 buttons?

  3. When using the remote, the rfraw values will be different, how would i use that to change the state?

Thanks,
David

You might look into a template fan

And as for the button issue (or whether you use the fan template), you need to define a state_topic or set optimistic: true. The issue is that this is an RF bridge, so there is no state for you to get. You can thus get out of sync using the optimistic flag if you change the device outside of HA.

In other words, the separate buttons you see is because it’s stateless. For an actual switch, you need the state or assume it.

Thanks @parautenbach & @francisp ,

The fan template looks like the best option for me but i have a question as to how the speed control works. So in my example i have 3 specific MQTT commands for each speed. But in the template, it has the entity fan.percentage_fan & fan.set_percentage service.

So how in my case does the high, medium and low options get set? Is it referencing my scripts and calling them “high, medium or low”? Sorry just not familiar enough with HA and MQTT to understand how to write this

Thanks :slight_smile:

I haven’t done this, but it seem you use 33% and 67%.

Check this: