MQTT "Relay" Listener

“Relay” might not be the most descriptive word for what I’m trying to do, but I couldn’t think of a better one. Once I’m done elaborating on what I’m trying to do, perhaps someone could better define what I’m trying to do in Home Assistant jargon. :stuck_out_tongue:

A little background of the setup: My MQTT server is not the native one in HA, but rather Mosquito running on a CentOS server. HA is version 0.82.1 running on an iMac. Python is 3.7.1

I have a group of 4 KULED and 2 Sonoff devices running tasmota all connected to my MQTT server. These devices are grouped together in HA as my ‘under cabinet lights’. My plan was to trigger a rule in tasmota to publish to MQTT to all 6 of these devices to either turn on or turn off based on the current state of the switch being pressed. The trigger would be a ‘long’ press of the switch. The rule, to manage all the devices would be enormous so I thought perhaps a custom component listening to a specific MQTT queue could then trigger all the lights. This is what I meant by a relay; a simple ‘man in the middle’ MQTT queue that I could configure to trigger all the lights, but I’m having a heck of a time trying to either get a custom component working, or finding information on what I’m trying to do.

The custom components I’ve tried, including the ‘hello world’ MQTT component end in an error. Exact copy and paste as well.

Any help would be greatly appreciated.

I think an automation triggering off the message from your long press is all that is necessary. The action would be to turn on all the lights that you want.

Relay seems a perfectly good description to me.

Is it possible for the automation to receive the payload of the MQTT message? For example, if the switch I’m pressing is currently off, I would like to turn on all the lights, if the light is already on, I would like to turn off all the lights regardless of the state the other lights are in. (some could be on, some could be off).

Thanks!

Yes, its in the example I linked to.

Then turn them all off. It doesn’t matter if a light is off and it gets another off command (ditto for on).

Well, if that specific light is off, I’d like to turn them all on, and vice versa. So, I need to have the payload sent to the automation.

I did come across this: https://www.youtube.com/watch?v=jz6sX2f5jjQ which is /sort/ of what I’m looking to do, BUT I have 5 other devices I need to update, and I don’t want to program specific rules into each switch.

Thanks and sorry for the delayed response, work/life/etc

Thanks for your help, ended up getting this automation to work:

- alias: Cabinet Lights All Alias
  trigger:
  - platform: mqtt
    topic: cab_lights/cmnd/POWER
  action:
    service_template: >-
      {% if trigger.payload|string == 'ON' %}
        homeassistant.turn_on
      {% else %}
        homeassistant.turn_off
      {% endif %}
    entity_id: group.cab_lights
1 Like