How to respond to MQTT events

Hi there,

I’ve been doing smart home stuff and automation for several years but am brand new to Home Assistant. I’m experienced with Node-RED and MQTT which I have used extensively in the past but I’ve moved to a new house so thought I would try something different and integrate Home Assistant to tie things together in a different way.

What I’m trying to figure out is how I can get Home Assistant to work with an existing MQTT setup.
I have a broker and devices including buttons, switches, relays etc already set up and I am able to use these in Node-RED.

A simplified version of something I would want to do is:

  1. Press button which sends an MQTT message, eg. ‘bedroom/light1/on’
  2. Have HA receive this and respond by turning on ‘light 1’ in the bedroom.
    The second part is the bit I can’t figure out.

I would also like to be able to send commands like this FROM Node-Red to HA, allowing me to do some more complex automation but I guess that would be a separate question.

If anyone has any advice for me on how to set something like this up, that’d be super helpful.



Use an automation with an MQTT Trigger, subscribed to bedroom/light1. The automation’s action calls either the light.turn_on or light.turn_off service (depending on the payload it received) to control a light.

Speaking of the light, what is the integration you are using for the lights?

Thanks @123 and apologies for the now apparent dumbness of my question.

One of those ‘of course’ moments… I don’t know why but I assumed it would be a more difficult implementation than that. I’m glad the functionality is there in the UI. That’s been my experience of HA so far… some stuff is amazingly straightforward… other stuff that you think should be simple seems overly complex.

I have a few different light protocols… Some stock Philips Hue, assorted zigbee bulbs (which I’m controlling via Zigbee2MQTT) and regular lamps attached to wifi sockets or relays controlled over MQTT.

Do you need help creating the automation or do you have all the information you need to move forward?

An example from my own setup. All my switches are set up to just publish an MQTT topic.

- id: '238764103745834543544'
  alias: Bathroom Vanity Light Switch
  - platform: mqtt
    topic: /bthrm/s0/
  - data:
      entity_id: light.bathroom_vanity_light
    service: light.toggle