Advice on how to integrate esphome with thingsboard via MQTT

Hi All,
I am totally newbie in this ESPHome world. I recently tried thingsboard and would like to test the possibility of using esphome with thingsboard via MQTT.
I have the following test code:

mqtt:
  broker: "104.196.24.70"
  client_id: "ik5gju7poo2s5ko52u5j"
  username: "USER"
  password: "PASSWORD"
  discovery: false
  port: 1883
  on_connect:
    - mqtt.publish_json:
        topic: v1/devices/me/attributes
        payload: !lambda |-          
          root["pin"] = "id7";
          root["enabled"] = id(id7).state;  

switch:
  - platform: gpio
    name: "Front door lamp"
    id: id7
    pin:
      pcf8574: pcf8574_hub
      # Use pin number P7
      number: 7
      # One of INPUT or OUTPUT
      mode: 
        output: true
      inverted: false
    state_topic: 'v1/devices/me/attributes'
    command_topic: 'v1/devices/me/attributes/getGpioStatus'
    on_turn_on:
      then:
      - mqtt.publish_json:
          topic: "v1/devices/me/attributes" 
          retain: true
          payload: !lambda |-
            root["pin"] = "id7";
            root["enabled"] = id(id7).state;
    on_turn_off:
      then:
      - mqtt.publish_json:
          topic: "v1/devices/me/attributes" 
          retain: true
          payload: !lambda |-
            root["pin"] = "id7";
            root["enabled"] = id(id7).state;

I did some connection with thingsboard with update on attributes, however, I have no idea on how to make esphome mqtt be successfully updated on thingsboard.
I would like the ESPhome device to send status of switch (that is currently be controlled by Home assistant) to the dashboard on thingsboard (so that thingsboard can also control the switch with its widget) but no matter how i tried with revising the code, thingsboard does not capture the connection from the esphome device.
Can you please be so kind to guide me on this with thanks!
Best regard,

Please mark code as code, as otherwise discourse (the software which builds the community website) does some funny things with the text.
```

> your code goes here

```

1 Like

Yeah Udo, I revised as you have advised. At first, I could not see the code block!
Many thanks for your instructions!

1 Like

It’s but at all clear what you’ve posted and what it has to do with openHAB. If you want to control your ESPHome from Thingsboard, you’ll have better luck of success asking on a Thingsboard forum. We aren’t experts on that here.

If you want to see and control this from openHAB, will need a bit more information about what you’ve tried with the code so we can figure out where you are going wrong and are able to provide more than RTM type answers.

If you don’t know where to start, The Getting Started Tutorial has an example of setting up MQTT.

At a high level, you’ll create a Generic MQTT Thing, add a switch Channel, set the subscription topic to the state topic and the command topic to the command topic. Link that to a Switch Item and you are good.

Hi Rich,
Thanks for your advise, I will try to learn a bit more for now!
Best

As seen on config, I guess client_id is device token that got from Thingsboard.
Actually, the token of device should be fill in username not in client_id.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.