Control State only?

Ok, so I have a broadlink RM pro that I have configured to control a few outlets and my bedroom fan. Works great and I will provide my configuration below. I also have a Sonoff RF Bridge flashed with OpenMQTTGateway that allows me to listen for RF remotes such as the remote for my outlets and my bedroom fan. Obviously when you control any of those devices through HA, you HA is aware of its state. The problem is that if i control the device through a remote, HA wont be aware of its current state as it obviously interfaces directly with the device. Thus the reason for the openmqttgateway. So what I am thinking I can do is have the remotes work like normal, but openmqttgateway will pass on its received RF code through mqtt and i now need to figure a way for HA to simply update/toggle that devices state instead of actually performing the action on the device since that was already done by the remote. Make sense?

Also, in case it makes a difference, my outlets do have an on button and and off button so the rf codes will be different, but the bedroom fan is simply a toggle.

In configuration.yaml:

switch: !include switches.yaml


In switches.yaml:

platform: broadlink
host: 192.168.1.211
mac: '34:ea:34:89:19:23'

switches:
    outlet_1:
        friendly_name: 'Lamp 1'
        command_on: 'sgYyAAcSEwYHEgcSBxITBgcSEwYHEhMGBxITBgcSEwYHEhMGBxIHEhMGEwYHEgcSEwYTBge6AAAAAAAA'
        command_off: 'sg4yAAcSEwYHEgcSBxITBgcSEwYHEhMGBxITBgcSEwYHEhMGBxIHEhMGEwYTBhMGBxIHEge6AAAAAAAA'

    outlet_2:
        friendly_name: 'Lamp 2'
        command_on: 'shIyAAcSEwYHEgcSBxITBgcSEwYHExMGBxITBgcSEwYHEhMGEwYTBgcSBxIHEgcSEwYTBge6AAAAAAAA'
        command_off: 'sgwyAAcSEwYHEgcSBxITBgcSEwYHEhMGBxITBgcSEwYHEhMGEwYTBgcSBxITBhMGBxIHEge6AAAAAAAA'

    outlet_3:
        friendly_name: 'Lamp 3'
        command_on: 'sggyAAcSFAYHEgcSBxITBgcSEwYHEhMGBxITBgcSEwYTBhMGBxIHEgcSBxIHEgcSEwYTBge6AAAAAAAA'
        command_off: 'sgsyAAcTEwcHEwcSBxITBgcSEwYHEhMGBxITBgcSEwYTBhMGBxIHEgcSBxITBhMGBxIHEge6AAAAAAAA'

    outlet_4:
        friendly_name: 'Lamp 4'
        command_on: 'shQyAAcSEwYHEgcSBxITBgcSFAYHEhMGBxITBhMGEwYHEhMGBxIHEgcSBxIHEggSEwYTBge6AAAAAAAA'
        command_off: 'sg8yAAcTEwcHEgcSBxMTBgcTEwYHEhMGBxITBhMGEwYHEhMGBxIHEgcSBxMTBhMGBxIHEge7AAAAAAAA'

    outlet_5:
        friendly_name: 'Lamp 5'
        command_on: 'sgcyAAcSEwYHEgcSBxMTBgcTEwYHEhMGEwYTBgcSEwYHEhMGBxIHEgcSBxIHEgcSEwYTBge7AAAAAAAA'
        command_off: 'shMyAAcSEwYHEgcSBxITBgcSEwYHEhMGEwYTBgcSEwYHEhMGBxIHEgcSBxITBhMGBxIHEge7AAAAAAAA'

    bedroom_fan_light:
        friendly_name: 'Bedroom Fan Light'
        command_on: 'sgB4AgwODQ0NDQ0ODA4NDgwNDQ4MDg0NDQ0NqxoODBsMGwwcGQ4MGxoNGg4MGxoOGQ4ZDg0bGQ4aDQ0bDBsZDg0bGQ4MGxoODBsNGhoOGQ4aDQ0aDRsNGg0bGQ4NGhoOGg0aDQ0bGg0NGhoOGg0NGg0bDBsaDQ0bDBsNGwwbDRoNGg0bDRoaDhkOGg4MGxkOGg0aDhkOGg0aDhkOGg0NAANKDQ0NDQ0ODA4MDgwODQ4MDgwODA4NDQ2rGg0NGwwbDRoaDg0aGg0aDgwbGg0aDhoNDRsZDhoNDRoNGxoNDRoaDgwbGg0NGw0aGg0aDhoNDRsMGw0aDRsZDg0aGg4aDRoNDRsaDQ0aGg4aDQ0aDRsMGxoODBsMGw0bDBsMGw0bDBsNGhoOGQ4aDQ0bGQ4aDRoOGQ4aDRoOGg0aDQ0AA6cNDQ0NDQ4MDg0NDQ0NDgwODA4NDQ0ODKsaDQ0bDBsNGxkODBsaDhkODRoaDhkOGg0NGxoNGg0NGwwbGg0NGxkODRoaDgwbDRoaDhoNGg0NGwwbDRoNGxkODRoaDhoNGg0NGxoNDRoaDhoNDRoNGw0aDRoNGw0aGg0NG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saDQ0aGg4NGhoODBsNGhoOGQ4aDQ0bDBsNGg0bGQ4NGhoOGQ4aDQ0bGg0NGhoOGQ4NGg0bDBsNGwwbDBsaDgwbDBsaDhkODRoaDhkOGg0aDhoNGg0NGxkOGg0NGwwbGg0NAAXc'

My approach with a similar issue (LightWaveRF remote and sockets) was do unpair the remote with the sockets and drive everything through HA.
HA receives the remote command and acts accordingly.
Added bonus for me is to play a sound through my speakers, confirming command received/actioned by HA. I use this sound:

You’re a third of the way there !

You can already switch with your broadlink switches switch.outlet_1 etc…
You now want some feedback, so this is where your mqtt comes in.
I’d set the sonoff up so it sends either a ON or OFF depending on the state of the switch you’re monitoring, then create a mqtt binary sensor to receive that info.
I have no idea how your MQTT software of choice works

binary_sensor:
  - platform: mqtt
    name: outlet_1
    state_topic: "/from_your_sonoff/outlet_1/state"

Then glue it all together with a template switch

switch:
  - platform: template
    switches:
      outlet_1_with_state:
        value_template: "{{ is_state('binary_sensor.outlet_1', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.outlet_1
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.outlet_1

I hope this is of some help :slight_smile:

Nah, unpairing from the two different devices would be a pain and I want the remotes to still work even if my HA system is offline.

Hmm, my mqtt output looks like so (im completely new to mqtt and using the hassio addon) when I press the off button (I highlighted in the picture) on my RF remote for outlet 1. I do not see any actual stopic names associated per device. Am I wrong that the topic is the same for every button and it just has a different value for each button? Seems i would somehow simply have to pair the RF code that is sent with a particular action for an outlet. No idea how that should be done.

Oh, i think that there might be some confusion here. The outlets themselves do not report or store any type of state. So they cant be queried or anything like that. Thats why HA needs to store the state

Yep, got that. You’re using the sonoff to translate and send the state to HA via MQTT.

Having one topic for all switches adds another layer of complexity. Probably doable, I just need to think about it a little more :yum:.

Actually, having just one topic for multiple components works perfectly fine !
The only downside is you lose the state of the all but the last toggled device when you restart hassio
States will update once each device is next toggled.

So your first binary_sensor would be :

binary_sensor:
  - platform: mqtt
    name: Outlet 1
    state_topic: "home/SRFBtoMQTT"
    payload_on: "???????"
    payload_off: "4544268"
    qos: 0

One more downside to this setup is that you’re assuming that the RF switch is actually switching when you press the remote button. If for whatever reason that doesn’t happen, as long as the sonoff sees the RF from the remote, it will update HA.

Basically what you will see in HA is what button you pushed on the remote, not necessarily the state of the outlet.

I did something similar with appdeamon: