Wemos D1 mini pro MQTT Publish

Hi, I wan’t to publish a mqtt message. I’m running hassio on a raspberry pi 3, and I want to have a wemos d1 powered by usb port all the time, and want to connect a optocopulator to pin d8 and 3.3v. when optocopulator guives signal I want wemos to publish mqtt message. Then I create an automation on homeassistant. My question is about the code to flash on wemos… any one have code to simply do this? just send information to my mqtt server… Thanls

If you want to make your life really easy, you can use esphomeyaml :slight_smile:

Using this configuration:

esphomeyaml:
  name: <NAME>
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: <SSID>
  password: <PASSWORD>

mqtt:
  broker: <MQTT_BROKER>
  username: <MQTT_USERNAME>
  password: <MQTT_PASSWORD>

logger:

ota:

binary_sensor:
  - platform: gpio
    pin: D8
	name: "Optocoupler"

This will:

  • Make flashing the chip quite easy, just install esphomeyaml through python or use the esphomeyaml HassIO Addon (beta) and press the flash button
  • Send the current binary sensor state as you wanted
  • Use MQTT discovery so that you don’t even need to update your Home Assistant configuration for the new sensor.

to be honest this is more an Arduino type of question than a Home Assistant one.
There are plenty of examples available online.
I don’t have an example for such a sensor but I’ve connected various Wemos D1 Mini Pros to LED Strips so you can always take inspiration from my code: