How to call MQTT device in automation action?

I am very new to Home Assistant and making really first steps. I’ ve set successfully few MQTT devices (connected to pgysical MQTT switches - Shelly 2) and also have MQTT virtual devices from Smartthings MQTT Bridge. I would like to link them (to operate everything from Smartthings could). I am trying to set automation like below, but simple stupid question: how do I call action for entity_id for device that has not entity_id (for MQTT devices it prohibited and putting it in configuration.yaml gives error)? How can I address my light in setup like this? Should I refer to its name or something?

configuration.yaml

light
  - platform: mqtt
    name: "bathroom_secondary_light"
    state_topic: "smartthings/Bathroom Secondary Light/switch"
    command_topic: "smartthings/Bathroom Secondary Light/switch"
    payload_on: "on"
    payload_off: "off"
    retain: true

automation.yaml

- alias: Example
  trigger:
  - platform: mqtt
    topic: shellies/shellyswitch-134CA7/relay/1
    to: 'on'
    from: 'off'
  action:
  - service: light.turn_on
    entity_id: light.bathroom_secondary_light

I found only this, but there is no solution:

I would really appreciate your help with this basic issue.

Please read the blue banner at the top of the page and edit your post accordingly.

ok, edited. My mistake

So you are saying that the light you created in configuration.yaml doesn’t result in any entity showing up in the dev-states page under the light domain?

I’m sorry. I don’t understand what this means.

What is the error?

The light that I create appears on UI perfectly well. I just don’t know how to call it with no entity_id. When I tried to put

entity_id: bathroom_secondary_light

in configuration.yaml file, it cannot load properly

You forgot to add the light domain to the entity name:

entity_id: light.bathroom_secondary_light

You can always look in the developer tools states menu (<> button lower left) to find the actual entity name of things.

1 Like

@tom_l, do you mean I forgot to put in device or automation action? In device I cannot put (I got configuration invalid error like on screen above) and i automation it was used exactly like you mentioned (in the first post in the topic - without any output.

Regardless of lack to possbility to call entity_id (because it can’t be set for MQTT Light or MQTT Switch), what I am really trying to do here is sync two different MQTT topics to change when the other changes. So I figured to trigger and call in action only MQTT topics like below, but is two problems:

1.Even the one side automation like below doesn’t work
2.I guess putting reverse automation (topic 2 as trigger and trigeer 1 as action) will cause infinite loop of sending MQTT message between this two topics.

- alias: Example
  initial_state: True
  trigger:
    - platform: mqtt
      topic: 'shellies/shellyswitch-134CA7/relay/1'
  action:
    - service: mqtt.publish
      data_template:
        topic: 'smartthings/Bathroom Secondary Light/switch'
        payload_template: '{{ trigger.payload }}'

Is there a way to sync two MQTT topics ? I could find anything on the community site.

I created other Community topic, since real problem is syncing MQTT topics:

in the example picture that you posted you are trying to force an entity_id: key but you aren’t allowed to do that. But you don’t need to do that either. The entity_id is automatically created from the name of the light.

So, from the example you posted:

light
  - platform: mqtt
    name: "bathroom_secondary_light"
    state_topic: "smartthings/Bathroom Secondary Light/switch"
    command_topic: "smartthings/Bathroom Secondary Light/switch"
    payload_on: "on"
    payload_off: "off"
    retain: true

the entity_id will be “light.bathroom_secondary_light”.

2 Likes

Thank you @finity. This is what I was looking for. What about spaces and Caps. Will the name:
“Bathroom Secondary Light” will be changed to “bathroom_secondary_light” ?

yes. it will show up just as i posted.

1 Like